Skip to content

Commit

Permalink
module: remove require('.') with NODE_PATH compatibilty
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Apr 17, 2015
1 parent cd60ff0 commit ca16df6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 27 deletions.
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("./")');

0 comments on commit ca16df6

Please sign in to comment.