Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module: remove require('.') with NODE_PATH compatibilty #1452

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,6 @@ function tryExtensions(p, exts) {
}


const noopDeprecateRequireDot = util.deprecate(function() {},
"warning: require('.') resolved outside the package directory. " +
"This functionality is deprecated and will be removed soon.");


Module._findPath = function(request, paths) {
var exts = Object.keys(Module._extensions);

Expand Down Expand Up @@ -174,8 +169,6 @@ Module._findPath = function(request, paths) {
}

if (filename) {
// Warn once if '.' resolved outside the module dir
if (request === '.' && i > 0) noopDeprecateRequireDot();
Module._pathCache[cacheKey] = filename;
return filename;
}
Expand Down Expand Up @@ -212,23 +205,13 @@ Module._resolveLookupPaths = function(request, parent) {
}

var start = request.substring(0, 2);
if (start !== './' && start !== '..') {
if (start !== '.' && start !== './' && start !== '..') {
var paths = modulePaths;
if (parent) {
if (!parent.paths) parent.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.splice(0, 0, path.dirname(parent.filename));
} else {
paths.splice(0, 0, path.resolve(request));
}
}

return [request, paths];
}

Expand Down
10 changes: 1 addition & 9 deletions test/parallel/test-require-dot.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
var common = require('../common');
var assert = require('assert');
var module = require('module');

var a = require(common.fixturesDir + '/module-require/relative/dot.js');
var b = require(common.fixturesDir + '/module-require/relative/dot-slash.js');

assert.equal(a.value, 42);
assert.equal(a, b, 'require(".") should resolve like require("./")');

process.env.NODE_PATH = common.fixturesDir + '/module-require/relative';
module._initPaths();

var c = require('.');

assert.equal(c.value, 42, 'require(".") should honor NODE_PATH');
assert.equal(a, b, 'require(".") should resolve like require("./")');