src: fix preload when used with prior flags
authorYosuke Furukawa <yosuke.furukawa@gmail.com>
Wed, 13 May 2015 15:00:57 +0000 (00:00 +0900)
committerJeremiah Senkpiel <fishrock123@rocketmail.com>
Fri, 15 May 2015 21:40:03 +0000 (17:40 -0400)
Fixes: https://github.com/nodejs/io.js/issues/1691
PR-URL: https://github.com/nodejs/io.js/pull/1694
Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com>
Reviewed-By: Trevor Norris <trev.norris@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
src/node.js
test/parallel/test-preload.js

index 55b1d78..cb50341 100644 (file)
         delete process.env.NODE_UNIQUE_ID;
       }
 
-      // Load any preload modules
-      if (process._preload_modules) {
-        var Module = NativeModule.require('module');
-        process._preload_modules.forEach(function(module) {
-          Module._load(module);
-        });
-      }
-
       if (process._eval != null) {
         // User passed '-e' or '--eval' arguments to Node.
+        startup.preloadModules();
         evalScript('[eval]');
       } else if (process.argv[1]) {
         // make process.argv[1] into a full path
@@ -99,7 +92,7 @@
         process.argv[1] = path.resolve(process.argv[1]);
 
         var Module = NativeModule.require('module');
-
+        startup.preloadModules();
         if (global.v8debug &&
             process.execArgv.some(function(arg) {
               return arg.match(/^--debug-brk(=[0-9]*)?$/);
     };
   };
 
+  // Load preload modules
+  startup.preloadModules = function() {
+    if (process._preload_modules) {
+      var Module = NativeModule.require('module');
+      process._preload_modules.forEach(function(module) {
+        Module._load(module);
+      });
+    }
+  };
+
   // Below you find a minimal module system, which is used to load the node
   // core modules found in lib/*.js. All core modules are compiled into the
   // node binary, so they can be loaded faster.
index 643edfb..3801f3d 100644 (file)
@@ -80,3 +80,15 @@ child_process.exec(nodeBinary + ' '
     if (err) throw err;
     assert.ok(/worker terminated with code 43/.test(stdout));
   });
+
+// https://github.com/iojs/io.js/issues/1691
+var originalCwd = process.cwd();
+process.chdir(path.join(__dirname, '../fixtures/'));
+child_process.exec(nodeBinary + ' '
+  + '--expose_debug_as=v8debug '
+  + '--require ' + fixture('cluster-preload.js') + ' '
+  + 'cluster-preload-test.js',
+  function(err, stdout, stderr) {
+    if (err) throw err;
+    assert.ok(/worker terminated with code 43/.test(stdout));
+  });