Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not read streams more than once #330

Merged
merged 1 commit into from Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion index.js
Expand Up @@ -4,6 +4,7 @@ const childProcess = require('child_process');
const crossSpawn = require('cross-spawn');
const stripFinalNewline = require('strip-final-newline');
const npmRunPath = require('npm-run-path');
const onetime = require('onetime');
const makeError = require('./lib/error');
const normalizeStdio = require('./lib/stdio');
const {spawnedKill, spawnedCancel, setupTimeout, setExitHandler} = require('./lib/kill');
Expand Down Expand Up @@ -144,13 +145,15 @@ const execa = (file, args, options) => {
};
};

const handlePromiseOnce = onetime(handlePromise);

crossSpawn._enoent.hookChildProcess(spawned, parsed.parsed);

handleInput(spawned, parsed.options.input);

spawned.all = makeAllStream(spawned);

return mergePromise(spawned, handlePromise);
return mergePromise(spawned, handlePromiseOnce);
};

module.exports = execa;
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -43,6 +43,7 @@
"is-stream": "^2.0.0",
"merge-stream": "^2.0.0",
"npm-run-path": "^3.0.0",
"onetime": "^5.1.0",
"p-finally": "^2.0.0",
"signal-exit": "^3.0.2",
"strip-final-newline": "^2.0.0"
Expand Down
6 changes: 6 additions & 0 deletions test/test.js
Expand Up @@ -138,6 +138,12 @@ test('child_process.spawnSync() errors are propagated with a correct shape', t =
t.true(failed);
});

test('do not try to consume streams twice', async t => {
const cp = execa('noop', ['foo']);
t.is((await cp).stdout, 'foo');
t.is((await cp).stdout, 'foo');
});

test('use relative path with \'..\' chars', async t => {
const pathViaParentDir = path.join('..', path.basename(path.dirname(__dirname)), 'test', 'fixtures', 'noop');
const {stdout} = await execa(pathViaParentDir, ['foo']);
Expand Down