Browse Source

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.
v0.7.4-release
isaacs 14 years ago
committed by Ryan Dahl
parent
commit
492fc0d752
  1. 19
      src/node.js

19
src/node.js

@ -126,15 +126,20 @@ var module = (function () {
var pathModule = createInternalModule('path', pathFn); var pathModule = createInternalModule('path', pathFn);
var path = pathModule.exports; var path = pathModule.exports;
var modulePaths = [path.join(process.execPath, "..", "..", "lib", "node")]; // The paths that the user has specifically asked for. Highest priority.
// This is what's hung on require.paths.
if (process.env["HOME"]) { var modulePaths = [];
modulePaths.unshift(path.join(process.env["HOME"], ".node_libraries")); if (process.env.NODE_PATH) {
modulePaths = process.env.NODE_PATH.split(":");
} }
if (process.env["NODE_PATH"]) { // The default global paths that are always checked.
modulePaths = process.env["NODE_PATH"].split(":").concat(modulePaths); // 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 extensions = {};
var registerExtension = removed('require.registerExtension() removed. Use require.extensions instead'); var registerExtension = removed('require.registerExtension() removed. Use require.extensions instead');
@ -185,7 +190,7 @@ var module = (function () {
var start = request.substring(0, 2); var start = request.substring(0, 2);
if (start !== "./" && start !== "..") { if (start !== "./" && start !== "..") {
return [request, modulePaths]; return [request, modulePaths.concat(defaultPaths)];
} }
// Is the parent an index module? // Is the parent an index module?

Loading…
Cancel
Save