Tidy _resolveFilename

This commit is contained in:
Paddy Byers 2011-11-22 23:46:01 +00:00 committed by isaacs
parent 35b3d15194
commit 840229a825

View File

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