Skip to content
Permalink
Browse files
Detached child process should not kill child - fixes #115 (#117)
  • Loading branch information
SamVerschueren authored and sindresorhus committed Dec 31, 2017
1 parent 79a496a commit 5f890abd67ddb2326dd0cf091d01c2d4061798a9
Showing 3 changed files with 28 additions and 0 deletions.
@@ -0,0 +1,13 @@
#!/usr/bin/env node
const fs = require('fs');
const execa = require('..');

const fd = fs.openSync(process.argv[2], 'w');

const cp = execa('noop', ['foo'], {
detached: true,
stdio: ['ignore', fd]
});
cp.unref();

process.exit();
@@ -54,6 +54,11 @@ function handleArgs(cmd, args, opts) {
opts.env = npmRunPath.env(Object.assign({}, opts, {cwd: opts.localDir}));
}

if (opts.detached) {
// #115
opts.cleanup = false;
}

return {
cmd: parsed.command,
args: parsed.args,
10 test.js
@@ -489,3 +489,13 @@ test('do not buffer when streaming', async t => {

t.is(result, '....................\n');
});

test('detach child process', async t => {
const file = tempfile('.txt');

await m('detach', [file]);

await delay(2000);

t.is(fs.readFileSync(file, 'utf8'), 'foo\n');
});

0 comments on commit 5f890ab

Please sign in to comment.