}
+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);
}
if (filename) {
+ // Warn once if '.' resolved outside the module dir
+ if (request === '.' && i > 0) noopDeprecateRequireDot();
Module._pathCache[cacheKey] = filename;
return filename;
}
}
var start = request.substring(0, 2);
- if (start !== '.' && start !== './' && start !== '..') {
+ if (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];
}
--- /dev/null
+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');
\ No newline at end of file
var common = require('../common');
var assert = require('assert');
-require(common.fixturesDir + '/require-bin/bin/req.js');
-
-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("./")');
+require(common.fixturesDir + '/require-bin/bin/req.js');
\ No newline at end of file