foreground-child
Advanced tools
Comparing version 1.4.0 to 1.5.0
20
index.js
@@ -63,4 +63,10 @@ var signalExit = require('signal-exit') | ||
var spawnOpts = { stdio: ['inherit', 'inherit', 'inherit'] } | ||
if (process.send) { | ||
spawnOpts.stdio.push('ipc') | ||
} | ||
var spawnfn = needsCrossSpawn(program) ? crossSpawn : spawn | ||
var child = spawnfn(program, args, { stdio: 'inherit' }) | ||
var child = spawnfn(program, args, spawnOpts) | ||
@@ -93,3 +99,15 @@ var childExited = false | ||
if (process.send) { | ||
process.removeAllListeners('message') | ||
child.on('message', function (message, sendHandle) { | ||
process.send(message, sendHandle) | ||
}) | ||
process.on('message', function (message, sendHandle) { | ||
child.send(message, sendHandle) | ||
}) | ||
} | ||
return child | ||
} |
{ | ||
"name": "foreground-child", | ||
"version": "1.4.0", | ||
"version": "1.5.0", | ||
"description": "Run a child as if it's the foreground process. Give it stdio. Exit when it exits.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,1 +34,14 @@ # foreground-child | ||
``` | ||
## Caveats | ||
The "normal" standard IO file descriptors (0, 1, and 2 for stdin, | ||
stdout, and stderr respectively) are shared with the child process. | ||
Additionally, if there is an IPC channel set up in the parent, then | ||
messages are proxied to the child on file descriptor 3. | ||
However, in Node, it's possible to also map arbitrary file descriptors | ||
into a child process. In these cases, foreground-child will not map | ||
the file descriptors into the child. If file descriptors 0, 1, or 2 | ||
are used for the IPC channel, then strange behavior may happen (like | ||
printing IPC messages to stderr, for example). |
@@ -19,2 +19,10 @@ var fg = require('../index.js') | ||
break | ||
case 'ipc': | ||
process.on('message', function(m) { | ||
console.log('message received') | ||
process.send(m) | ||
process.exit(0) | ||
}) | ||
break | ||
} | ||
@@ -154,2 +162,22 @@ | ||
t.test('IPC forwarding', function (t) { | ||
t.plan(5) | ||
var prog = process.execPath | ||
var args = [__filename, 'parent', 'ipc'] | ||
child = spawn(prog, args, { stdio: ['ipc', 'pipe', 'pipe'] }) | ||
var out = '' | ||
var messages = [] | ||
child.on('message', function (m) { messages.push(m) }) | ||
child.stdout.on('data', function (c) { out += c }) | ||
child.send({ data: 'foobar' }) | ||
child.on('close', function (code, signal) { | ||
t.equal(signal, null) | ||
t.equal(code, 0) | ||
t.equal(out, 'stdout\nmessage received\n') | ||
t.equal(messages.length, 1) | ||
t.equal(messages[0].data, 'foobar') | ||
}) | ||
}) | ||
function isZero10OnTravis () { | ||
@@ -156,0 +184,0 @@ return process.env.TRAVIS && /^v0\.10\.[0-9]+$/.test(process.version) ? |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
11230
262
47
2