Skip to content

Commit

Permalink
Do not mutate process promise
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jun 26, 2019
1 parent cba87e1 commit 954fbc4
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,14 +162,19 @@ const execa = (file, args, options) => {
});

const handlePromise = async () => {
const [result, stdout, stderr, all] = await getSpawnedResult(spawned, parsed.options, processDone);
result.stdout = handleOutput(parsed.options, stdout);
result.stderr = handleOutput(parsed.options, stderr);
result.all = handleOutput(parsed.options, all);

if (result.error || result.code !== 0 || result.signal !== null) {
const error = makeError({
...result,
const [{error, code, signal}, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
const stdout = handleOutput(parsed.options, stdoutResult);
const stderr = handleOutput(parsed.options, stderrResult);
const all = handleOutput(parsed.options, allResult);

if (error || code !== 0 || signal !== null) {
const returnedError = makeError({
error,
code,
signal,
stdout,
stderr,
all,
command,
parsed,
timedOut: context.timedOut,
Expand All @@ -178,19 +183,19 @@ const execa = (file, args, options) => {
});

if (!parsed.options.reject) {
return error;
return returnedError;
}

throw error;
throw returnedError;
}

return {
command,
exitCode: 0,
exitCodeName: 'SUCCESS',
stdout: result.stdout,
stderr: result.stderr,
all: result.all,
stdout,
stderr,
all,
failed: false,
timedOut: false,
isCanceled: false,
Expand Down

0 comments on commit 954fbc4

Please sign in to comment.