Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Tidy _resolveFilename

  • Loading branch information...
paddybyers authored and isaacs committed Nov 22, 2011
1 parent 35b3d15 commit 840229a8251955d2b791928875f36d35127dcad0
Showing with 8 additions and 11 deletions.
  1. +8 −11 lib/module.js
@@ -276,29 +276,27 @@ 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;
return replModule.exports;
}

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() {

0 comments on commit 840229a

Please sign in to comment.
You can’t perform that action at this time.