Skip to content

Commit

Permalink
module: mark DEP0019 as EOL and remove compat code
Browse files Browse the repository at this point in the history
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: #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>
  • Loading branch information
silverwind committed Aug 31, 2017
1 parent 365c245 commit a517466
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 30 deletions.
2 changes: 1 addition & 1 deletion doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ code.
<a id="DEP0019"></a>
### DEP0019: require('.') resolved outside directory

Type: Runtime
Type: End-of-Life

In certain cases, `require('.')` may resolve outside the package directory.
This behavior is deprecated and will be removed in a future major Node.js
Expand Down
26 changes: 1 addition & 25 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ function tryExtensions(p, exts, isMain) {
return false;
}

var warned = false;
Module._findPath = function(request, paths, isMain) {
if (path.isAbsolute(request)) {
paths = [''];
Expand Down Expand Up @@ -221,18 +220,6 @@ Module._findPath = function(request, paths, isMain) {
}

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;
return filename;
}
Expand Down Expand Up @@ -335,8 +322,7 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
}

// Check for relative path
if (request.length < 2 ||
request.charCodeAt(0) !== 46/*.*/ ||
if (request.charCodeAt(0) !== 46/*.*/ &&
(request.charCodeAt(1) !== 46/*.*/ &&
request.charCodeAt(1) !== 47/*/*/)) {
var paths = modulePaths;
Expand All @@ -347,16 +333,6 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
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);
return (newReturn ? (paths.length > 0 ? paths : null) : [request, paths]);
}
Expand Down
6 changes: 2 additions & 4 deletions test/parallel/test-require-dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ const b = require(fixtures.path('module-require', 'relative', 'dot-slash.js'));
assert.strictEqual(a.value, 42);
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');
m._initPaths();

const c = require('.');

assert.strictEqual(c.value, 42, 'require(".") should honor NODE_PATH');
assert.throws(() => { require('.'); }, Error, "Cannot find module '.'");

2 comments on commit a517466

@Trott
Copy link
Member

@Trott Trott commented on a517466 Sep 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, and surely not worth fixing with a force push at this point, but the commit message here has lines that are longer than 72 characters in length. (If you want, check out the core-validate-commit npm module for a linter for these sorts of things.)

@silverwind
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually, vim auto-wraps commit bodies for me, but for some reason it wasn't working when I typed that message. Will have to investigate why. Good tip on the validator thought.

Please sign in to comment.