Skip to content

Commit e5484bc

Browse files
yosuke-furukawaandrewdeandrade
authored andcommitted
src: fix preload when used with prior flags
Fixes: nodejs/node#1691 PR-URL: nodejs/node#1694 Reviewed-By: Ali Ijaz Sheikh <[email protected]> Reviewed-By: Trevor Norris <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent 25af46e commit e5484bc

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/node.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -82,24 +82,17 @@
8282
delete process.env.NODE_UNIQUE_ID;
8383
}
8484

85-
// Load any preload modules
86-
if (process._preload_modules) {
87-
var Module = NativeModule.require('module');
88-
process._preload_modules.forEach(function(module) {
89-
Module._load(module);
90-
});
91-
}
92-
9385
if (process._eval != null) {
9486
// User passed '-e' or '--eval' arguments to Node.
87+
startup.preloadModules();
9588
evalScript('[eval]');
9689
} else if (process.argv[1]) {
9790
// make process.argv[1] into a full path
9891
var path = NativeModule.require('path');
9992
process.argv[1] = path.resolve(process.argv[1]);
10093

10194
var Module = NativeModule.require('module');
102-
95+
startup.preloadModules();
10396
if (global.v8debug &&
10497
process.execArgv.some(function(arg) {
10598
return arg.match(/^--debug-brk(=[0-9]*)?$/);
@@ -857,6 +850,16 @@
857850
};
858851
};
859852

853+
// Load preload modules
854+
startup.preloadModules = function() {
855+
if (process._preload_modules) {
856+
var Module = NativeModule.require('module');
857+
process._preload_modules.forEach(function(module) {
858+
Module._load(module);
859+
});
860+
}
861+
};
862+
860863
// Below you find a minimal module system, which is used to load the node
861864
// core modules found in lib/*.js. All core modules are compiled into the
862865
// node binary, so they can be loaded faster.

test/parallel/test-preload.js

+12
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ child_process.exec(nodeBinary + ' '
8080
if (err) throw err;
8181
assert.ok(/worker terminated with code 43/.test(stdout));
8282
});
83+
84+
// https://github.com/iojs/io.js/issues/1691
85+
var originalCwd = process.cwd();
86+
process.chdir(path.join(__dirname, '../fixtures/'));
87+
child_process.exec(nodeBinary + ' '
88+
+ '--expose_debug_as=v8debug '
89+
+ '--require ' + fixture('cluster-preload.js') + ' '
90+
+ 'cluster-preload-test.js',
91+
function(err, stdout, stderr) {
92+
if (err) throw err;
93+
assert.ok(/worker terminated with code 43/.test(stdout));
94+
});

0 commit comments

Comments
 (0)