Skip to content

Commit 6301f18

Browse files
isaacsry
authored andcommitted
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.
1 parent c2454a0 commit 6301f18

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/node.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ var pathModule = createInternalModule("path", function (exports) {
689689
joined += part;
690690
}
691691
// replace /foo/../bar/baz with /bar/baz
692-
while (dotdotre.exec(joined)) joined.replace(dotdotre, dotdotreplace);
692+
while (dotdotre.exec(joined)) joined = joined.replace(dotdotre, dotdotreplace);
693693
return joined;
694694

695695
};
@@ -782,15 +782,19 @@ function loadModule (request, parent) {
782782
// This is the promise which is actually returned from require.async()
783783
var loadPromise = new process.Promise();
784784

785-
debug("loadModule REQUEST " + JSON.stringify(request) + " parent: " + JSON.stringify(parent));
785+
// debug("loadModule REQUEST " + (request) + " parent: " + JSON.stringify(parent));
786786

787787
var id, paths;
788788
if (request.charAt(0) == "." && (request.charAt(1) == "/" || request.charAt(1) == ".")) {
789789
// Relative request
790-
id = path.join(path.dirname(parent.id), request);
790+
var parentIdPath = path.dirname(parent.id +
791+
(path.filename(parent.filename).match(/^index\.(js|addon)$/) ? "/" : ""));
792+
id = path.join(parentIdPath, request);
793+
debug("RELATIVE: requested:"+request+" set ID to: "+id+" from "+parent.id+"("+parentIdPath+")");
791794
paths = [path.dirname(parent.filename)];
792795
} else {
793796
id = request;
797+
debug("ABSOLUTE: id="+id);
794798
paths = process.paths;
795799
}
796800

0 commit comments

Comments
 (0)