Skip to content

Commit a517466

Browse files
committed
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: #3384 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 365c245 commit a517466

File tree

3 files changed

+4
-30
lines changed

3 files changed

+4
-30
lines changed

doc/api/deprecations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ code.
201201
<a id="DEP0019"></a>
202202
### DEP0019: require('.') resolved outside directory
203203

204-
Type: Runtime
204+
Type: End-of-Life
205205

206206
In certain cases, `require('.')` may resolve outside the package directory.
207207
This behavior is deprecated and will be removed in a future major Node.js

lib/module.js

+1-25
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ function tryExtensions(p, exts, isMain) {
159159
return false;
160160
}
161161

162-
var warned = false;
163162
Module._findPath = function(request, paths, isMain) {
164163
if (path.isAbsolute(request)) {
165164
paths = [''];
@@ -221,18 +220,6 @@ Module._findPath = function(request, paths, isMain) {
221220
}
222221

223222
if (filename) {
224-
// Warn once if '.' resolved outside the module dir
225-
if (request === '.' && i > 0) {
226-
if (!warned) {
227-
warned = true;
228-
process.emitWarning(
229-
'warning: require(\'.\') resolved outside the package ' +
230-
'directory. This functionality is deprecated and will be removed ' +
231-
'soon.',
232-
'DeprecationWarning', 'DEP0019');
233-
}
234-
}
235-
236223
Module._pathCache[cacheKey] = filename;
237224
return filename;
238225
}
@@ -335,8 +322,7 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
335322
}
336323

337324
// Check for relative path
338-
if (request.length < 2 ||
339-
request.charCodeAt(0) !== 46/*.*/ ||
325+
if (request.charCodeAt(0) !== 46/*.*/ &&
340326
(request.charCodeAt(1) !== 46/*.*/ &&
341327
request.charCodeAt(1) !== 47/*/*/)) {
342328
var paths = modulePaths;
@@ -347,16 +333,6 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
347333
paths = parent.paths.concat(paths);
348334
}
349335

350-
// Maintain backwards compat with certain broken uses of require('.')
351-
// by putting the module's directory in front of the lookup paths.
352-
if (request === '.') {
353-
if (parent && parent.filename) {
354-
paths.unshift(path.dirname(parent.filename));
355-
} else {
356-
paths.unshift(path.resolve(request));
357-
}
358-
}
359-
360336
debug('looking for %j in %j', request, paths);
361337
return (newReturn ? (paths.length > 0 ? paths : null) : [request, paths]);
362338
}

test/parallel/test-require-dot.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const b = require(fixtures.path('module-require', 'relative', 'dot-slash.js'));
1010
assert.strictEqual(a.value, 42);
1111
assert.strictEqual(a, b, 'require(".") should resolve like require("./")');
1212

13+
// require('.') should not lookup in NODE_PATH
1314
process.env.NODE_PATH = fixtures.path('module-require', 'relative');
1415
m._initPaths();
15-
16-
const c = require('.');
17-
18-
assert.strictEqual(c.value, 42, 'require(".") should honor NODE_PATH');
16+
assert.throws(() => { require('.'); }, Error, "Cannot find module '.'");

0 commit comments

Comments
 (0)