module: mark DEP0019 as End-of-Life
In certain cases, `require('.')` could resolve outside the package directory. This behavior has been removed. PR-URL: https://github.com/nodejs/node/pull/26973 Refs: https://github.com/nodejs/node/pull/3384 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
666c67e078
commit
75007d64c0
@ -442,6 +442,9 @@ code.
|
|||||||
### DEP0019: require('.') resolved outside directory
|
### DEP0019: require('.') resolved outside directory
|
||||||
<!-- YAML
|
<!-- YAML
|
||||||
changes:
|
changes:
|
||||||
|
- version: REPLACEME
|
||||||
|
pr-url: https://github.com/nodejs/node/pull/26973
|
||||||
|
description: Removed functionality.
|
||||||
- version:
|
- version:
|
||||||
- v4.8.6
|
- v4.8.6
|
||||||
- v6.12.0
|
- v6.12.0
|
||||||
@ -452,11 +455,10 @@ changes:
|
|||||||
description: Runtime deprecation.
|
description: Runtime deprecation.
|
||||||
-->
|
-->
|
||||||
|
|
||||||
Type: Runtime
|
Type: End-of-Life
|
||||||
|
|
||||||
In certain cases, `require('.')` may resolve outside the package directory.
|
In certain cases, `require('.')` could resolve outside the package directory.
|
||||||
This behavior is deprecated and will be removed in a future major Node.js
|
This behavior has been removed.
|
||||||
release.
|
|
||||||
|
|
||||||
<a id="DEP0020"></a>
|
<a id="DEP0020"></a>
|
||||||
### DEP0020: Server.connections
|
### DEP0020: Server.connections
|
||||||
|
@ -70,7 +70,6 @@ const {
|
|||||||
CHAR_FORWARD_SLASH,
|
CHAR_FORWARD_SLASH,
|
||||||
CHAR_BACKWARD_SLASH,
|
CHAR_BACKWARD_SLASH,
|
||||||
CHAR_COLON,
|
CHAR_COLON,
|
||||||
CHAR_DOT,
|
|
||||||
CHAR_UNDERSCORE,
|
CHAR_UNDERSCORE,
|
||||||
CHAR_0,
|
CHAR_0,
|
||||||
CHAR_9,
|
CHAR_9,
|
||||||
@ -306,7 +305,6 @@ function findLongestRegisteredExtension(filename) {
|
|||||||
return '.js';
|
return '.js';
|
||||||
}
|
}
|
||||||
|
|
||||||
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 = [''];
|
||||||
@ -375,18 +373,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;
|
||||||
}
|
}
|
||||||
@ -490,35 +476,23 @@ Module._resolveLookupPaths = function(request, parent, newReturn) {
|
|||||||
return (newReturn ? null : [request, []]);
|
return (newReturn ? null : [request, []]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check for non-relative path
|
// Check for node modules paths.
|
||||||
if (request.length < 2 ||
|
if (request.charAt(0) !== '.' ||
|
||||||
request.charCodeAt(0) !== CHAR_DOT ||
|
(request.length > 1 &&
|
||||||
(request.charCodeAt(1) !== CHAR_DOT &&
|
request.charAt(1) !== '.' &&
|
||||||
request.charCodeAt(1) !== CHAR_FORWARD_SLASH &&
|
request.charAt(1) !== '/' &&
|
||||||
(!isWindows || request.charCodeAt(1) !== CHAR_BACKWARD_SLASH))) {
|
(!isWindows || request.charAt(1) !== '\\'))) {
|
||||||
var paths = modulePaths;
|
|
||||||
if (parent) {
|
|
||||||
if (!parent.paths)
|
|
||||||
paths = parent.paths = [];
|
|
||||||
else
|
|
||||||
paths = parent.paths.concat(paths);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Maintain backwards compat with certain broken uses of require('.')
|
let paths = modulePaths;
|
||||||
// by putting the module's directory in front of the lookup paths.
|
if (parent != null && parent.paths && parent.paths.length) {
|
||||||
if (request === '.') {
|
paths = parent.paths.concat(paths);
|
||||||
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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// with --eval, parent.id is not set and parent.filename is null
|
// With --eval, parent.id is not set and parent.filename is null.
|
||||||
if (!parent || !parent.id || !parent.filename) {
|
if (!parent || !parent.id || !parent.filename) {
|
||||||
// Make require('./path/to/foo') work - normally the path is taken
|
// Make require('./path/to/foo') work - normally the path is taken
|
||||||
// from realpath(__filename) but with eval there is no filename
|
// from realpath(__filename) but with eval there is no filename
|
||||||
|
@ -14,9 +14,10 @@ assert.strictEqual(a, b);
|
|||||||
process.env.NODE_PATH = fixtures.path('module-require', 'relative');
|
process.env.NODE_PATH = fixtures.path('module-require', 'relative');
|
||||||
m._initPaths();
|
m._initPaths();
|
||||||
|
|
||||||
const c = require('.');
|
assert.throws(
|
||||||
assert.strictEqual(
|
() => require('.'),
|
||||||
c.value,
|
{
|
||||||
42,
|
message: /Cannot find module '\.'/,
|
||||||
`require(".") should honor NODE_PATH; expected 42, found ${c.value}`
|
code: 'MODULE_NOT_FOUND'
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user