diff --git a/lib/monitor/run.js b/lib/monitor/run.js index 4d9ca1ad..95c78234 100644 --- a/lib/monitor/run.js +++ b/lib/monitor/run.js @@ -33,11 +33,11 @@ function run(options) { var stdio = ['pipe', 'pipe', 'pipe']; if (config.options.stdout) { - stdio = ['pipe', process.stdout, 'pipe']; + stdio = ['pipe', process.stdout, process.stderr]; } if (config.options.stdin === false) { - stdio = [process.stdin, process.stdout, 'pipe']; + stdio = [process.stdin, process.stdout, process.stderr]; } var sh = 'sh'; @@ -99,6 +99,8 @@ function run(options) { if (shouldFork) { var forkArgs = cmd.args.slice(1); var env = utils.merge(options.execOptions.env, process.env); + stdio.pop(); + stdio.push(process.stderr); stdio.push('ipc'); child = fork(options.execOptions.script, forkArgs, { env: env, @@ -110,7 +112,7 @@ function run(options) { } else { utils.log.detail('spawning'); child = spawn.apply(null, spawnArgs); - debug('spawn', sh, shFlag, args) + debug('spawn', sh, shFlag, args); } if (config.required) { @@ -139,20 +141,6 @@ function run(options) { bus.emit('message', message, sendHandle); }); } - } else { // else if not required… - - // this swallows a shell message that happens because we kill the sh -c - // more details here: https://git.io/Je6d0 - child.stderr.on('data', s => { - s = s.toString(); - - if (child.__nodemonRestart) { // this flag is set right before the kill - utils.log.detail('stderr: ' + s); - return; - } - - process.stderr.write(s); - }); } bus.emit('start'); @@ -276,7 +264,6 @@ function run(options) { /* Now kill the entire subtree of processes belonging to nodemon */ var oldPid = child.pid; if (child) { - child.__nodemonRestart = true; kill(child, config.signal, function () { // this seems to fix the 0.11.x issue with the "rs" restart command, // though I'm unsure why. it seems like more data is streamed in to @@ -380,6 +367,8 @@ function kill(child, signal, callback) { // the sub processes need to be killed from smallest to largest debug('sending kill signal to ' + pids.join(', ')); + child.kill(signal); + pids.sort().forEach(pid => exec(`kill -${sig} ${pid}`, noop)); waitForSubProcesses(child.pid, () => { diff --git a/test/fork/run.test.js b/test/fork/run.test.js index c572e562..04c2023c 100644 --- a/test/fork/run.test.js +++ b/test/fork/run.test.js @@ -5,19 +5,45 @@ var assert = require('assert'), run = utils.run; describe('nodemon fork', function () { - it('should start a fork', function (done) { - var p = run(appjs, { + it('should not show user-signal', done => { + var p = run({ exec: 'bin/nodemon.js', + args: [ '-V', '-x', 'echo running && sleep 20' ] }, { error: function (data) { p.send('quit'); + if (data.trim().indexOf('signal') !== -1) { + return done(new Error('Signal incorrectly shown')); + } + done(new Error(data)); + }, + output: function (data) { + if (data.trim().indexOf('signal') !== -1) { + done(new Error('Signal incorrectly shown')); + } } }); + let started = false; p.on('message', function (event) { if (event.type === 'start') { + if (!started) { + p.send('restart'); + started = true; + } else { + p.send('quit'); + assert(true, 'nodemon started'); + done(); + } + + } + }); + }); + + it('should start a fork', function (done) { + var p = run(appjs, { + error: function (data) { p.send('quit'); - assert(true, 'nodemon started'); - done(); + done(new Error(data)); } }); });