Skip to content

Commit d3fb7e1

Browse files
committed
module: mark DEP0019 as End-of-Life
In certain cases, `require('.')` could resolve outside the package directory. This behavior has been removed.
1 parent 805e614 commit d3fb7e1

File tree

3 files changed

+22
-44
lines changed

3 files changed

+22
-44
lines changed

doc/api/deprecations.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,9 @@ code.
442442
### DEP0019: require('.') resolved outside directory
443443
<!-- YAML
444444
changes:
445+
- version: REPLACEME
446+
pr-url: https://github.com/nodejs/node/pull/REPLACEME
447+
description: Removed functionality.
445448
- version:
446449
- v4.8.6
447450
- v6.12.0
@@ -452,11 +455,10 @@ changes:
452455
description: Runtime deprecation.
453456
-->
454457

455-
Type: Runtime
458+
Type: End-of-Life
456459

457-
In certain cases, `require('.')` may resolve outside the package directory.
458-
This behavior is deprecated and will be removed in a future major Node.js
459-
release.
460+
In certain cases, `require('.')` could resolve outside the package directory.
461+
This behavior has been removed.
460462

461463
<a id="DEP0020"></a>
462464
### DEP0020: Server.connections

lib/internal/modules/cjs/loader.js

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ const {
7777
CHAR_FORWARD_SLASH,
7878
CHAR_BACKWARD_SLASH,
7979
CHAR_COLON,
80-
CHAR_DOT,
8180
CHAR_UNDERSCORE,
8281
CHAR_0,
8382
CHAR_9,
@@ -382,18 +381,6 @@ Module._findPath = function(request, paths, isMain) {
382381
}
383382

384383
if (filename) {
385-
// Warn once if '.' resolved outside the module dir
386-
if (request === '.' && i > 0) {
387-
if (!warned) {
388-
warned = true;
389-
process.emitWarning(
390-
'warning: require(\'.\') resolved outside the package ' +
391-
'directory. This functionality is deprecated and will be removed ' +
392-
'soon.',
393-
'DeprecationWarning', 'DEP0019');
394-
}
395-
}
396-
397384
Module._pathCache[cacheKey] = filename;
398385
return filename;
399386
}
@@ -497,35 +484,23 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
497484
return (newReturn ? null : [request, []]);
498485
}
499486

500-
// Check for non-relative path
501-
if (request.length < 2 ||
502-
request.charCodeAt(0) !== CHAR_DOT ||
503-
(request.charCodeAt(1) !== CHAR_DOT &&
504-
request.charCodeAt(1) !== CHAR_FORWARD_SLASH &&
505-
(!isWindows || request.charCodeAt(1) !== CHAR_BACKWARD_SLASH))) {
506-
var paths = modulePaths;
507-
if (parent) {
508-
if (!parent.paths)
509-
paths = parent.paths = [];
510-
else
511-
paths = parent.paths.concat(paths);
512-
}
487+
// Check for node modules paths.
488+
if (request.charAt(0) !== '.' ||
489+
(request.length > 1 &&
490+
request.charAt(1) !== '.' &&
491+
request.charAt(1) !== '/' &&
492+
(!isWindows || request.charAt(1) !== '\\'))) {
513493

514-
// Maintain backwards compat with certain broken uses of require('.')
515-
// by putting the module's directory in front of the lookup paths.
516-
if (request === '.') {
517-
if (parent && parent.filename) {
518-
paths.unshift(path.dirname(parent.filename));
519-
} else {
520-
paths.unshift(path.resolve(request));
521-
}
494+
let paths = modulePaths;
495+
if (parent != null && parent.paths && parent.paths.length) {
496+
paths = parent.paths.concat(paths);
522497
}
523498

524499
debug('looking for %j in %j', request, paths);
525500
return (newReturn ? (paths.length > 0 ? paths : null) : [request, paths]);
526501
}
527502

528-
// with --eval, parent.id is not set and parent.filename is null
503+
// With --eval, parent.id is not set and parent.filename is null.
529504
if (!parent || !parent.id || !parent.filename) {
530505
// Make require('./path/to/foo') work - normally the path is taken
531506
// from realpath(__filename) but with eval there is no filename

test/parallel/test-require-dot.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ assert.strictEqual(a, b);
1414
process.env.NODE_PATH = fixtures.path('module-require', 'relative');
1515
m._initPaths();
1616

17-
const c = require('.');
18-
assert.strictEqual(
19-
c.value,
20-
42,
21-
`require(".") should honor NODE_PATH; expected 42, found ${c.value}`
17+
assert.throws(
18+
() => require('.'),
19+
{
20+
message: /Cannot find module '\.'/,
21+
code: 'MODULE_NOT_FOUND'
22+
}
2223
);

0 commit comments

Comments
 (0)