Skip to content

Commit 1368d0e

Browse files
jamestalmagesindresorhus
authored andcommitted
Fix npm link usage on Node.js 6 (#815)
1 parent 8c9f7b2 commit 1368d0e

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lib/fork.js

+29-3
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,35 @@ module.exports = function (file, opts) {
3131
} : false
3232
}, opts);
3333

34-
var ps = childProcess.fork(path.join(__dirname, 'test-worker.js'), [JSON.stringify(opts)], {
35-
cwd: path.dirname(file),
36-
silent: true,
34+
// Workaround for breakage caused by https://github.com/nodejs/node/pull/5950
35+
// Those changes will be reverted in https://github.com/nodejs/node/pull/6537
36+
37+
// Revert #815 when these changes land in Node.js
38+
var execArgv = process.execArgv;
39+
var cwd = path.dirname(file);
40+
41+
// This whole if statement is copied straight out of Nodes `child_process`
42+
if (process._eval != null) { // eslint-disable-line
43+
var index = execArgv.lastIndexOf(process._eval);
44+
if (index > 0) {
45+
// Remove the -e switch to avoid fork bombing ourselves.
46+
execArgv = execArgv.slice();
47+
execArgv.splice(index - 1, 2);
48+
}
49+
}
50+
51+
var testWorkerPath = path.join(__dirname, 'test-worker.js');
52+
53+
var args = execArgv.concat([
54+
'-e',
55+
'require(' + JSON.stringify(testWorkerPath) + ')',
56+
testWorkerPath,
57+
JSON.stringify(opts)
58+
]);
59+
60+
var ps = childProcess.spawn(process.execPath, args, {
61+
cwd: cwd,
62+
stdio: ['pipe', 'pipe', 'pipe', 'ipc'],
3763
env: env
3864
});
3965

0 commit comments

Comments
 (0)