Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Bugfix: child modules get wrong id with "index.js"

Fix for bug brought up by nua in irc, where child modules get the wrong id
when loaded from a parent module with an id of index.js or index.addon.
  • Loading branch information...
commit 6301f18e62e8f90026dda3aec3457e4723ea319b 1 parent c2454a0
isaacs authored ry committed
Showing with 7 additions and 3 deletions.
  1. +7 −3 src/node.js
10 src/node.js
View
@@ -689,7 +689,7 @@ var pathModule = createInternalModule("path", function (exports) {
joined += part;
}
// replace /foo/../bar/baz with /bar/baz
- while (dotdotre.exec(joined)) joined.replace(dotdotre, dotdotreplace);
+ while (dotdotre.exec(joined)) joined = joined.replace(dotdotre, dotdotreplace);
return joined;
};
@@ -782,15 +782,19 @@ function loadModule (request, parent) {
// This is the promise which is actually returned from require.async()
var loadPromise = new process.Promise();
- debug("loadModule REQUEST " + JSON.stringify(request) + " parent: " + JSON.stringify(parent));
+ // debug("loadModule REQUEST " + (request) + " parent: " + JSON.stringify(parent));
var id, paths;
if (request.charAt(0) == "." && (request.charAt(1) == "/" || request.charAt(1) == ".")) {
// Relative request
- id = path.join(path.dirname(parent.id), request);
+ var parentIdPath = path.dirname(parent.id +
+ (path.filename(parent.filename).match(/^index\.(js|addon)$/) ? "/" : ""));
+ id = path.join(parentIdPath, request);
+ debug("RELATIVE: requested:"+request+" set ID to: "+id+" from "+parent.id+"("+parentIdPath+")");
paths = [path.dirname(parent.filename)];
} else {
id = request;
+ debug("ABSOLUTE: id="+id);
paths = process.paths;
}
Please sign in to comment.
Something went wrong with that request. Please try again.