Browse Source

Tidy _resolveFilename

v0.7.4-release
Paddy Byers 13 years ago
committed by isaacs
parent
commit
840229a825
  1. 19
      lib/module.js

19
lib/module.js

@ -276,18 +276,16 @@ Module._load = function(request, parent, isMain) {
debug('Module._load REQUEST ' + (request) + ' parent: ' + parent.id);
}
var resolved = Module._resolveFilename(request, parent);
var id = resolved[0];
var filename = resolved[1];
var filename = Module._resolveFilename(request, parent);
var cachedModule = Module._cache[filename];
if (cachedModule) {
return cachedModule.exports;
}
if (NativeModule.exists(id)) {
if (NativeModule.exists(filename)) {
// REPL is a special case, because it needs the real require.
if (id == 'repl') {
if (filename == 'repl') {
var replModule = new Module('repl');
replModule._compile(NativeModule.getSource('repl'), 'repl.js');
NativeModule._cache.repl = replModule;
@ -295,10 +293,10 @@ Module._load = function(request, parent, isMain) {
}
debug('load native module ' + request);
return NativeModule.require(id);
return NativeModule.require(filename);
}
var module = new Module(id, parent);
var module = new Module(filename, parent);
if (isMain) {
process.mainModule = module;
@ -318,7 +316,7 @@ Module._load = function(request, parent, isMain) {
Module._resolveFilename = function(request, parent) {
if (NativeModule.exists(request)) {
return [request, request];
return request;
}
var resolvedModule = Module._resolveLookupPaths(request, parent);
@ -333,8 +331,7 @@ Module._resolveFilename = function(request, parent) {
if (!filename) {
throw new Error("Cannot find module '" + request + "'");
}
id = filename;
return [id, filename];
return filename;
};
@ -374,7 +371,7 @@ Module.prototype._compile = function(content, filename) {
}
require.resolve = function(request) {
return Module._resolveFilename(request, self)[1];
return Module._resolveFilename(request, self);
};
Object.defineProperty(require, 'paths', { get: function() {

Loading…
Cancel
Save