Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tidy _resolveFilename

  • Loading branch information...
commit 840229a8251955d2b791928875f36d35127dcad0 1 parent 35b3d15
@paddybyers paddybyers authored isaacs committed
Showing with 8 additions and 11 deletions.
  1. +8 −11 lib/module.js
View
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);
@herby
herby added a note

(commenting it here in commit comment since I cannot comment the line of the file itself, so found the last commit on this line via blame view)

@isaacs and others, don't you want to finish the decoupling in this file? The NativeModule in node.js file is designed so that native modules (module.js being one of them) can (and I say, should) use plain require call to get other native modules. This was by design, to achieve transparent use of require.

This line is only line in the whole file, where NativeModule.require should be explictly call via NativeModule object. All other ones (all of them requires 'fs' and other directly named native modules) should be just plain require calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
- 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() {
@herby

(commenting it here in commit comment since I cannot comment the line of the file itself, so found the last commit on this line via blame view)

@isaacs and others, don't you want to finish the decoupling in this file? The NativeModule in node.js file is designed so that native modules (module.js being one of them) can (and I say, should) use plain require call to get other native modules. This was by design, to achieve transparent use of require.

This line is only line in the whole file, where NativeModule.require should be explictly call via NativeModule object. All other ones (all of them requires 'fs' and other directly named native modules) should be just plain require calls.

Please sign in to comment.
Something went wrong with that request. Please try again.