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

Make stdout and stderr properties undefined instead of null #246

Merged
merged 8 commits into from May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions index.js
Expand Up @@ -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 : '';
ehmicky marked this conversation as resolved.
Show resolved Hide resolved
}

if (options.stripFinalNewline) {
Expand Down Expand Up @@ -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, {
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Expand Up @@ -107,6 +107,8 @@ try {
command: 'wrong command',
exitCode: 2,
exitCodeName: 'ENOENT',
stdout: '',
stderr: '',
failed: true,
timedOut: false,
isCanceled: false,
Expand Down