Split out modulePaths and defaultPaths
This way, the "default" paths of ~/.node_libraries and {prefix}/lib/node are only checked *after* anything that the user has placed into the NODE_PATHS environ, or pushed onto require.paths. This makes require.paths a much more effective write-target, albeit slightly less useful as a read-target. However, given the existence of require.resolve(), this is less of an issue -- if you want to know what a module ID will map to, just ask that question and get an authoritative answer from the loading machinery.
This commit is contained in:
parent
b0aadbea6b
commit
492fc0d752
19
src/node.js
19
src/node.js
@ -126,15 +126,20 @@ var module = (function () {
|
||||
var pathModule = createInternalModule('path', pathFn);
|
||||
var path = pathModule.exports;
|
||||
|
||||
var modulePaths = [path.join(process.execPath, "..", "..", "lib", "node")];
|
||||
|
||||
if (process.env["HOME"]) {
|
||||
modulePaths.unshift(path.join(process.env["HOME"], ".node_libraries"));
|
||||
// The paths that the user has specifically asked for. Highest priority.
|
||||
// This is what's hung on require.paths.
|
||||
var modulePaths = [];
|
||||
if (process.env.NODE_PATH) {
|
||||
modulePaths = process.env.NODE_PATH.split(":");
|
||||
}
|
||||
|
||||
if (process.env["NODE_PATH"]) {
|
||||
modulePaths = process.env["NODE_PATH"].split(":").concat(modulePaths);
|
||||
// The default global paths that are always checked.
|
||||
// Lowest priority.
|
||||
var defaultPaths = [];
|
||||
if (process.env.HOME) {
|
||||
defaultPaths.push(path.join(process.env.HOME, ".node_libraries"));
|
||||
}
|
||||
defaultPaths.push(path.join(process.execPath, "..", "..", "lib", "node"));
|
||||
|
||||
var extensions = {};
|
||||
var registerExtension = removed('require.registerExtension() removed. Use require.extensions instead');
|
||||
@ -185,7 +190,7 @@ var module = (function () {
|
||||
|
||||
var start = request.substring(0, 2);
|
||||
if (start !== "./" && start !== "..") {
|
||||
return [request, modulePaths];
|
||||
return [request, modulePaths.concat(defaultPaths)];
|
||||
}
|
||||
|
||||
// Is the parent an index module?
|
||||
|
Loading…
x
Reference in New Issue
Block a user