From ace8ef2d6b9d82a87c6b1c7ea173d69f4a8c8db0 Mon Sep 17 00:00:00 2001 From: ehmicky Date: Tue, 14 May 2019 20:11:29 +0200 Subject: [PATCH] Make stdout and stderr empty strings with `execa.sync()` on errors --- index.js | 9 +++++---- readme.md | 2 ++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index d39a491c33..e2941e1e2b 100644 --- a/index.js +++ b/index.js @@ -109,9 +109,10 @@ function handleInput(spawned, input) { } } -function handleOutput(options, value) { +function handleOutput(options, value, error) { if (typeof value !== 'string' && !Buffer.isBuffer(value)) { - return; + // When `execa.sync()` errors, we normalize it to '' to mimic `execa()` + return error === undefined ? undefined : ''; } if (options.stripFinalNewline) { @@ -427,8 +428,8 @@ module.exports.sync = (command, args, options) => { } const result = childProcess.spawnSync(parsed.command, parsed.args, parsed.options); - result.stdout = handleOutput(parsed.options, result.stdout); - result.stderr = handleOutput(parsed.options, result.stderr); + result.stdout = handleOutput(parsed.options, result.stdout, result.error); + result.stderr = handleOutput(parsed.options, result.stderr, result.error); if (result.error || result.status !== 0 || result.signal !== null) { const error = makeError(result, { diff --git a/readme.md b/readme.md index 15775e44ab..ac1d5eb9a8 100644 --- a/readme.md +++ b/readme.md @@ -107,6 +107,8 @@ try { command: 'wrong command', exitCode: 2, exitCodeName: 'ENOENT', + stdout: '', + stderr: '', failed: true, timedOut: false, isCanceled: false,