-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src: fix module search path for preload modules
When the preload module is not a abs/relative path, we should use the standard search mechanism of looking into the node_modules folders outwards. The current working directory is deemed to be the 'requiring module', i.e. parent. The search path starts from cwd outwards. Fixes: #1803
- Loading branch information
Showing
3 changed files
with
26 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
var assert = require('assert'); | ||
|
||
// https://github.com/nodejs/io.js/issues/1803 | ||
// this module is used as a preload module. It should have a parent with the | ||
// module search paths initialized from the current working directory | ||
assert.ok(module.parent); | ||
var expectedPaths = require('module')._nodeModulePaths(process.cwd()); | ||
assert.ok(module.parent.paths.length === expectedPaths.length && | ||
module.parent.paths.every(function(e,i) { | ||
return e === expectedPaths[i]; | ||
})); | ||
|
||
var cluster = require('cluster'); | ||
cluster.isMaster || process.exit(42 + cluster.worker.id); // +42 to distinguish | ||
// from exit(1) for other random reasons |