Skip to content

Commit

Permalink
module: inherit unique lookup paths from parent
Browse files Browse the repository at this point in the history
The previous commit added the module lookup paths based on a symlink
location as well as the realpath location.  However, _subsequent_
modules loaded in that environment would _not_ have those additional
paths added to their lookup path, since they are not loaded based on a
linked location.

This patch adds any paths from the parent module lookup paths to the
child, if the child does not already have that path in their lookup
list.
  • Loading branch information
isaacs committed Dec 8, 2016
1 parent d0f9a99 commit f727658
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,13 @@ Module.prototype.load = function(realpath, filename) {
const realdir = path.dirname(realpath);
const linkdir = realpath !== filename ? path.dirname(filename) : null;
this.paths = Module._nodeModulePaths(realdir, linkdir);
if (this.parent && this.parent.paths) {
for (let i = 0; i < this.parent.paths.length; i++) {
if (this.paths.indexOf(this.parent.paths[i]) === -1) {
this.paths.push(this.parent.paths[i]);
}
}
}

var extension = path.extname(filename) || '.js';
if (!Module._extensions[extension]) extension = '.js';
Expand Down

0 comments on commit f727658

Please sign in to comment.