module: mark DEP0019 as EOL and remove compat code

This removes the compatibilty code that was in place to allow an unintended
interaction between `require('.')` and `NODE_PATH`. The compatibility code and
the accompanying deprecation warning has been in place since 2015-04-17.

PR-URL: https://github.com/nodejs/node/pull/3384
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Roman Reiss 2017-01-18 00:55:34 +01:00 committed by silverwind
parent 365c24591c
commit a517466aa7
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
3 changed files with 4 additions and 30 deletions

View File

@ -201,7 +201,7 @@ code.
<a id="DEP0019"></a> <a id="DEP0019"></a>
### DEP0019: require('.') resolved outside directory ### DEP0019: require('.') resolved outside directory
Type: Runtime Type: End-of-Life
In certain cases, `require('.')` may resolve outside the package directory. In certain cases, `require('.')` may resolve outside the package directory.
This behavior is deprecated and will be removed in a future major Node.js This behavior is deprecated and will be removed in a future major Node.js

View File

@ -159,7 +159,6 @@ function tryExtensions(p, exts, isMain) {
return false; return false;
} }
var warned = false;
Module._findPath = function(request, paths, isMain) { Module._findPath = function(request, paths, isMain) {
if (path.isAbsolute(request)) { if (path.isAbsolute(request)) {
paths = ['']; paths = [''];
@ -221,18 +220,6 @@ Module._findPath = function(request, paths, isMain) {
} }
if (filename) { if (filename) {
// Warn once if '.' resolved outside the module dir
if (request === '.' && i > 0) {
if (!warned) {
warned = true;
process.emitWarning(
'warning: require(\'.\') resolved outside the package ' +
'directory. This functionality is deprecated and will be removed ' +
'soon.',
'DeprecationWarning', 'DEP0019');
}
}
Module._pathCache[cacheKey] = filename; Module._pathCache[cacheKey] = filename;
return filename; return filename;
} }
@ -335,8 +322,7 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
} }
// Check for relative path // Check for relative path
if (request.length < 2 || if (request.charCodeAt(0) !== 46/*.*/ &&
request.charCodeAt(0) !== 46/*.*/ ||
(request.charCodeAt(1) !== 46/*.*/ && (request.charCodeAt(1) !== 46/*.*/ &&
request.charCodeAt(1) !== 47/*/*/)) { request.charCodeAt(1) !== 47/*/*/)) {
var paths = modulePaths; var paths = modulePaths;
@ -347,16 +333,6 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
paths = parent.paths.concat(paths); paths = parent.paths.concat(paths);
} }
// Maintain backwards compat with certain broken uses of require('.')
// by putting the module's directory in front of the lookup paths.
if (request === '.') {
if (parent && parent.filename) {
paths.unshift(path.dirname(parent.filename));
} else {
paths.unshift(path.resolve(request));
}
}
debug('looking for %j in %j', request, paths); debug('looking for %j in %j', request, paths);
return (newReturn ? (paths.length > 0 ? paths : null) : [request, paths]); return (newReturn ? (paths.length > 0 ? paths : null) : [request, paths]);
} }

View File

@ -10,9 +10,7 @@ const b = require(fixtures.path('module-require', 'relative', 'dot-slash.js'));
assert.strictEqual(a.value, 42); assert.strictEqual(a.value, 42);
assert.strictEqual(a, b, 'require(".") should resolve like require("./")'); assert.strictEqual(a, b, 'require(".") should resolve like require("./")');
// require('.') should not lookup in NODE_PATH
process.env.NODE_PATH = fixtures.path('module-require', 'relative'); process.env.NODE_PATH = fixtures.path('module-require', 'relative');
m._initPaths(); m._initPaths();
assert.throws(() => { require('.'); }, Error, "Cannot find module '.'");
const c = require('.');
assert.strictEqual(c.value, 42, 'require(".") should honor NODE_PATH');