Skip to content
Myr

Add support for `all` option to `execaSync()` (#956)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by GitHub · parent c15edbc · Browse files · 15 files+323 added−166 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

15 files+323 added−166 removed

  • tests:+213 added−89 removed
  • other:+110 added−77 removed

15 files+323 added−166 removed

modified:lib/return/output.js+3 added-11 removed
modified:lib/stdio/output-sync.js+30 added-2 removed
modified:lib/stdio/uint-array.js+8 added-5 removed
modified:lib/async.js+3 added-3 removed
1import {setMaxListeners} from 'node:events';2import {spawn} from 'node:child_process';3import {handleCommand, handleOptions} from './arguments/options.js';4import {makeError, makeSuccessResult} from './return/error.js';5import {handleOutput, handleResult} from './return/output.js';5import {stripNewline, handleResult} from './return/output.js';6import {handleEarlyError} from './return/early-error.js';7import {handleInputAsync, pipeOutputAsync} from './stdio/async.js';8import {subprocessKill} from './exit/kill.js';9import {cleanupOnExit} from './exit/cleanup.js';
70 unmodified lines
80 allResult,81 ] = await getSubprocessResult({subprocess, options, context, fileDescriptors, originalStreams, controller});82 controller.abort();8384 const stdio = stdioResults.map(stdioResult => handleOutput(options, stdioResult));85 const all = handleOutput(options, allResult);84 const stdio = stdioResults.map(stdioResult => stripNewline(stdioResult, options));85 const all = stripNewline(allResult, options);86 const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime});87 return handleResult(result, verboseInfo, options);88};89
16 unmodified lines
modified:lib/sync.js+8 added-6 removed
1import {spawnSync} from 'node:child_process';2import {handleCommand, handleOptions} from './arguments/options.js';3import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';4import {handleOutput, handleResult} from './return/output.js';4import {stripNewline, handleResult} from './return/output.js';5import {handleInputSync} from './stdio/sync.js';6import {addInputOptionsSync} from './stdio/input-sync.js';7import {transformOutputSync} from './stdio/output-sync.js';7import {transformOutputSync, getAllSync} from './stdio/output-sync.js';8import {logEarlyResult} from './verbose/complete.js';9import {getSyncExitResult} from './exit/code.js';1011export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {
44 unmodified lines
56 }5758 const {resultError, exitCode, signal} = getSyncExitResult(syncResult);59 const {output, error = resultError} = transformOutputSync(fileDescriptors, syncResult, options);60 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));61 return getSyncResult({error, exitCode, signal, stdio, options, command, escapedCommand, startTime});60 const stdio = output.map(stdioOutput => stripNewline(stdioOutput, options));61 const all = stripNewline(getAllSync(output, options), options);62 return getSyncResult({error, exitCode, signal, stdio, all, options, command, escapedCommand, startTime});63};6465const runSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {66 try {
6 unmodified lines
73};7475const normalizeSpawnSyncOptions = ({encoding, ...options}) => ({...options, encoding: 'buffer'});7676const getSyncResult = ({error, exitCode, signal, stdio, options, command, escapedCommand, startTime}) => error === undefined77 ? makeSuccessResult({command, escapedCommand, stdio, options, startTime})77const getSyncResult = ({error, exitCode, signal, stdio, all, options, command, escapedCommand, startTime}) => error === undefined78 ? makeSuccessResult({command, escapedCommand, stdio, all, options, startTime})79 : makeError({80 error,81 command,82 escapedCommand,
1 unmodified line
84 isCanceled: false,85 exitCode,86 signal,87 stdio,88 all,89 options,90 startTime,91 isSync: true,92 });
added:test/fixtures/noop-both-fail-strict.js+8 added
modified:test/fixtures/noop-both-fail.js+4 added-4 removed
modified:test/return/error.js+34 added-17 removed
9 unmodified lines
10const isWindows = process.platform === 'win32';1112setFixtureDir();1314test('Return value properties are not missing and are ordered', async t => {15 const result = await execa('empty.js', {...fullStdio, all: true});14const testSuccessShape = async (t, execaMethod) => {15 const result = await execaMethod('empty.js', {...fullStdio, all: true});16 t.deepEqual(Reflect.ownKeys(result), [17 'command',18 'escapedCommand',19 'cwd',
8 unmodified lines
28 'all',29 'stdio',30 'pipedFrom',31 ]);32});32};3334test('Error properties are not missing and are ordered', async t => {35 const error = await t.throwsAsync(execa('fail.js', {...fullStdio, all: true}));34test('Return value properties are not missing and are ordered', testSuccessShape, execa);35test('Return value properties are not missing and are ordered, sync', testSuccessShape, execaSync);3637const testErrorShape = async (t, execaMethod) => {38 const error = await execaMethod('fail.js', {...fullStdio, all: true, reject: false});39 t.is(error.exitCode, 2);40 t.deepEqual(Reflect.ownKeys(error), [41 'stack',42 'message',43 'shortMessage',
15 unmodified lines
59 'all',60 'stdio',61 'pipedFrom',62 ]);59});63};6465test('Error properties are not missing and are ordered', testErrorShape, execa);66test('Error properties are not missing and are ordered, sync', testErrorShape, execaSync);6768test('error.message contains the command', async t => {69 await t.throwsAsync(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});70});7165const testStdioMessage = async (t, encoding, all, objectMode) => {66 const {message} = await t.throwsAsync(execa('echo-fail.js', {...getStdio(1, noopGenerator(objectMode), 4), encoding, all}));72// eslint-disable-next-line max-params73const testStdioMessage = async (t, encoding, all, objectMode, execaMethod) => {74 const {exitCode, message} = await execaMethod('echo-fail.js', {...getStdio(1, noopGenerator(objectMode), 4), encoding, all, reject: false});75 t.is(exitCode, 1);76 const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';77 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));78};7971test('error.message contains stdout/stderr/stdio if available', testStdioMessage, 'utf8', false, false);72test('error.message contains stdout/stderr/stdio even with encoding "buffer"', testStdioMessage, 'buffer', false, false);73test('error.message contains all if available', testStdioMessage, 'utf8', true, false);74test('error.message contains all even with encoding "buffer"', testStdioMessage, 'buffer', true, false);75test('error.message contains stdout/stderr/stdio if available, objectMode', testStdioMessage, 'utf8', false, true);76test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true);77test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true);78test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true);80test('error.message contains stdout/stderr/stdio if available', testStdioMessage, 'utf8', false, false, execa);81test('error.message contains stdout/stderr/stdio even with encoding "buffer"', testStdioMessage, 'buffer', false, false, execa);82test('error.message contains all if available', testStdioMessage, 'utf8', true, false, execa);83test('error.message contains all even with encoding "buffer"', testStdioMessage, 'buffer', true, false, execa);84test('error.message contains stdout/stderr/stdio if available, objectMode', testStdioMessage, 'utf8', false, true, execa);85test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode', testStdioMessage, 'buffer', false, true, execa);86test('error.message contains all if available, objectMode', testStdioMessage, 'utf8', true, true, execa);87test('error.message contains all even with encoding "buffer", objectMode', testStdioMessage, 'buffer', true, true, execa);88test('error.message contains stdout/stderr/stdio if available, sync', testStdioMessage, 'utf8', false, false, execaSync);89test('error.message contains stdout/stderr/stdio even with encoding "buffer", sync', testStdioMessage, 'buffer', false, false, execaSync);90test('error.message contains all if available, sync', testStdioMessage, 'utf8', true, false, execaSync);91test('error.message contains all even with encoding "buffer", sync', testStdioMessage, 'buffer', true, false, execaSync);92test('error.message contains stdout/stderr/stdio if available, objectMode, sync', testStdioMessage, 'utf8', false, true, execaSync);93test('error.message contains stdout/stderr/stdio even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', false, true, execaSync);94test('error.message contains all if available, objectMode, sync', testStdioMessage, 'utf8', true, true, execaSync);95test('error.message contains all even with encoding "buffer", objectMode, sync', testStdioMessage, 'buffer', true, true, execaSync);9697const testLinesMessage = async (t, encoding, stripFinalNewline, execaMethod) => {98 const {failed, message} = await execaMethod('noop-fail.js', ['1', `${foobarString}\n${foobarString}\n`], {99 lines: true,
34 unmodified lines
134test('error.message does not contain stdout/stderr/stdio if not available', testFullIgnoreMessage, {stdio: 'ignore'}, 'message');135test('error.shortMessage does not contain stdout/stderr/stdio', testFullIgnoreMessage, fullStdio, 'shortMessage');136137const testErrorMessageConsistent = async (t, stdout) => {121 const {message} = await t.throwsAsync(execa('noop-both-fail.js', [stdout, 'stderr']));138 const {message} = await t.throwsAsync(execa('noop-both-fail-strict.js', [stdout, 'stderr']));139 t.true(message.endsWith(' stderr\n\nstderr\n\nstdout'));140};141142test('error.message newlines are consistent - no newline', testErrorMessageConsistent, 'stdout');
86 unmodified lines
modified:test/return/output.js+14 added-17 removed
64 unmodified lines
6566test('undefined error.stdout/stderr/stdio', testUndefinedErrorStdio, execa);67test('undefined error.stdout/stderr/stdio - sync', testUndefinedErrorStdio, execaSync);6869const testEmptyAll = async (t, options, expectedValue) => {70 const {all} = await t.throwsAsync(execa('fail.js', options));69const testEmptyAll = async (t, options, expectedValue, execaMethod) => {70 const {all} = await execaMethod('empty.js', options);71 t.is(all, expectedValue);72};7374test('empty error.all', testEmptyAll, {all: true}, '');75test('undefined error.all', testEmptyAll, {}, undefined);76test('ignored error.all', testEmptyAll, {all: true, stdio: 'ignore'}, undefined);74test('empty error.all', testEmptyAll, {all: true}, '', execa);75test('undefined error.all', testEmptyAll, {}, undefined, execa);76test('ignored error.all', testEmptyAll, {all: true, stdio: 'ignore'}, undefined, execa);77test('empty error.all, sync', testEmptyAll, {all: true}, '', execaSync);78test('undefined error.all, sync', testEmptyAll, {}, undefined, execaSync);79test('ignored error.all, sync', testEmptyAll, {all: true, stdio: 'ignore'}, undefined, execaSync);8081test('empty error.stdio[0] even with input', async t => {82 const {stdio} = await t.throwsAsync(execa('fail.js', {input: 'test'}));83 t.is(stdio[0], undefined);
1 unmodified line
8586// `error.code` is OS-specific here87const SPAWN_ERROR_CODES = new Set(['EINVAL', 'ENOTSUP', 'EPERM']);8886test('stdout/stderr/stdio on subprocess spawning errors', async t => {87 const {code, stdout, stderr, stdio} = await t.throwsAsync(execa('empty.js', {uid: -1}));89const testSpawnError = async (t, execaMethod) => {90 const {code, stdout, stderr, stdio, all} = await execaMethod('empty.js', {uid: -1, all: true, reject: false});91 t.true(SPAWN_ERROR_CODES.has(code));92 t.is(stdout, undefined);93 t.is(stderr, undefined);94 t.is(all, undefined);95 t.deepEqual(stdio, [undefined, undefined, undefined]);92});96};9794test('stdout/stderr/all/stdio on subprocess spawning errors - sync', t => {95 const {code, stdout, stderr, stdio} = t.throws(() => {96 execaSync('empty.js', {uid: -1});97 });98 t.true(SPAWN_ERROR_CODES.has(code));99 t.is(stdout, undefined);100 t.is(stderr, undefined);101 t.deepEqual(stdio, [undefined, undefined, undefined]);102});98test('stdout/stderr/all/stdio on subprocess spawning errors', testSpawnError, execa);99test('stdout/stderr/all/stdio on subprocess spawning errors - sync', testSpawnError, execaSync);100101const testErrorOutput = async (t, execaMethod) => {102 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});103 t.true(failed);
36 unmodified lines
modified:test/stdio/generator.js+74 added-38 removed
447 unmodified lines
448 : `${stdoutOutput}${stderrOutput}`;449};450451// eslint-disable-next-line max-params452const testGeneratorAll = async (t, reject, encoding, objectMode, stdoutOption, stderrOption) => {452const testGeneratorAll = async (t, reject, encoding, objectMode, stdoutOption, stderrOption, execaMethod) => {453 const fixtureName = reject ? 'all.js' : 'all-fail.js';454 const {stdout, stderr, all} = await execa(fixtureName, {454 const {stdout, stderr, all} = await execaMethod(fixtureName, {455 all: true,456 reject,457 stdout: getAllStdioOption(stdoutOption, encoding, objectMode),458 stderr: getAllStdioOption(stderrOption, encoding, objectMode),
8 unmodified lines
467 const allOutput = getAllOutput(stdoutOutput, stderrOutput, encoding, objectMode);468 t.deepEqual(all, allOutput);469};470471test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false);472test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false);473test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false);474test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false);475test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false);476test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false);477test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true);478test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true);479test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true);480test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true);481test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true);482test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true);483test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false);484test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false);485test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false);486test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false);487test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false);488test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false);489test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false);490test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false);491test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false);492test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false);493test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false);494test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false);495test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true);496test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true);497test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true);498test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true);499test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true);500test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true);501test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false);502test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false);503test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false);504test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false);505test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false);506test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false);471test('Can use generators with result.all = transform + transform', testGeneratorAll, true, 'utf8', false, false, false, execa);472test('Can use generators with error.all = transform + transform', testGeneratorAll, false, 'utf8', false, false, false, execa);473test('Can use generators with result.all = transform + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, false, execa);474test('Can use generators with error.all = transform + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, false, execa);475test('Can use generators with result.all = transform + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, false, false, execa);476test('Can use generators with error.all = transform + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, false, false, execa);477test('Can use generators with result.all = transform + pipe', testGeneratorAll, true, 'utf8', false, false, true, execa);478test('Can use generators with error.all = transform + pipe', testGeneratorAll, false, 'utf8', false, false, true, execa);479test('Can use generators with result.all = transform + pipe, encoding "buffer"', testGeneratorAll, true, 'buffer', false, false, true, execa);480test('Can use generators with error.all = transform + pipe, encoding "buffer"', testGeneratorAll, false, 'buffer', false, false, true, execa);481test('Can use generators with result.all = transform + pipe, encoding "hex"', testGeneratorAll, true, 'hex', false, false, true, execa);482test('Can use generators with error.all = transform + pipe, encoding "hex"', testGeneratorAll, false, 'hex', false, false, true, execa);483test('Can use generators with result.all = pipe + transform', testGeneratorAll, true, 'utf8', false, true, false, execa);484test('Can use generators with error.all = pipe + transform', testGeneratorAll, false, 'utf8', false, true, false, execa);485test('Can use generators with result.all = pipe + transform, encoding "buffer"', testGeneratorAll, true, 'buffer', false, true, false, execa);486test('Can use generators with error.all = pipe + transform, encoding "buffer"', testGeneratorAll, false, 'buffer', false, true, false, execa);487test('Can use generators with result.all = pipe + transform, encoding "hex"', testGeneratorAll, true, 'hex', false, true, false, execa);488test('Can use generators with error.all = pipe + transform, encoding "hex"', testGeneratorAll, false, 'hex', false, true, false, execa);489test('Can use generators with result.all = transform + transform, objectMode', testGeneratorAll, true, 'utf8', true, false, false, execa);490test('Can use generators with error.all = transform + transform, objectMode', testGeneratorAll, false, 'utf8', true, false, false, execa);491test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, false, execa);492test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, false, execa);493test('Can use generators with result.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, false, execa);494test('Can use generators with error.all = transform + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, false, execa);495test('Can use generators with result.all = transform + pipe, objectMode', testGeneratorAll, true, 'utf8', true, false, true, execa);496test('Can use generators with error.all = transform + pipe, objectMode', testGeneratorAll, false, 'utf8', true, false, true, execa);497test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, false, true, execa);498test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, false, true, execa);499test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, false, true, execa);500test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, false, true, execa);501test('Can use generators with result.all = pipe + transform, objectMode', testGeneratorAll, true, 'utf8', true, true, false, execa);502test('Can use generators with error.all = pipe + transform, objectMode', testGeneratorAll, false, 'utf8', true, true, false, execa);503test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, true, 'buffer', true, true, false, execa);504test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer"', testGeneratorAll, false, 'buffer', true, true, false, execa);505test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, true, 'hex', true, true, false, execa);506test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex"', testGeneratorAll, false, 'hex', true, true, false, execa);507test('Can use generators with result.all = transform + transform, sync', testGeneratorAll, true, 'utf8', false, false, false, execaSync);508test('Can use generators with error.all = transform + transform, sync', testGeneratorAll, false, 'utf8', false, false, false, execaSync);509test('Can use generators with result.all = transform + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, false, execaSync);510test('Can use generators with error.all = transform + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, false, execaSync);511test('Can use generators with result.all = transform + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, false, execaSync);512test('Can use generators with error.all = transform + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, false, execaSync);513test('Can use generators with result.all = transform + pipe, sync', testGeneratorAll, true, 'utf8', false, false, true, execaSync);514test('Can use generators with error.all = transform + pipe, sync', testGeneratorAll, false, 'utf8', false, false, true, execaSync);515test('Can use generators with result.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, false, true, execaSync);516test('Can use generators with error.all = transform + pipe, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, false, true, execaSync);517test('Can use generators with result.all = transform + pipe, encoding "hex", sync', testGeneratorAll, true, 'hex', false, false, true, execaSync);518test('Can use generators with error.all = transform + pipe, encoding "hex", sync', testGeneratorAll, false, 'hex', false, false, true, execaSync);519test('Can use generators with result.all = pipe + transform, sync', testGeneratorAll, true, 'utf8', false, true, false, execaSync);520test('Can use generators with error.all = pipe + transform, sync', testGeneratorAll, false, 'utf8', false, true, false, execaSync);521test('Can use generators with result.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, true, 'buffer', false, true, false, execaSync);522test('Can use generators with error.all = pipe + transform, encoding "buffer", sync', testGeneratorAll, false, 'buffer', false, true, false, execaSync);523test('Can use generators with result.all = pipe + transform, encoding "hex", sync', testGeneratorAll, true, 'hex', false, true, false, execaSync);524test('Can use generators with error.all = pipe + transform, encoding "hex", sync', testGeneratorAll, false, 'hex', false, true, false, execaSync);525test('Can use generators with result.all = transform + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, false, execaSync);526test('Can use generators with error.all = transform + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, false, execaSync);527test('Can use generators with result.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, false, execaSync);528test('Can use generators with error.all = transform + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, false, execaSync);529test('Can use generators with result.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, false, execaSync);530test('Can use generators with error.all = transform + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, false, execaSync);531test('Can use generators with result.all = transform + pipe, objectMode, sync', testGeneratorAll, true, 'utf8', true, false, true, execaSync);532test('Can use generators with error.all = transform + pipe, objectMode, sync', testGeneratorAll, false, 'utf8', true, false, true, execaSync);533test('Can use generators with result.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, false, true, execaSync);534test('Can use generators with error.all = transform + pipe, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, false, true, execaSync);535test('Can use generators with result.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, false, true, execaSync);536test('Can use generators with error.all = transform + pipe, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, false, true, execaSync);537test('Can use generators with result.all = pipe + transform, objectMode, sync', testGeneratorAll, true, 'utf8', true, true, false, execaSync);538test('Can use generators with error.all = pipe + transform, objectMode, sync', testGeneratorAll, false, 'utf8', true, true, false, execaSync);539test('Can use generators with result.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, true, 'buffer', true, true, false, execaSync);540test('Can use generators with error.all = pipe + transform, objectMode, encoding "buffer", sync', testGeneratorAll, false, 'buffer', true, true, false, execaSync);541test('Can use generators with result.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, true, 'hex', true, true, false, execaSync);542test('Can use generators with error.all = pipe + transform, objectMode, encoding "hex", sync', testGeneratorAll, false, 'hex', true, true, false, execaSync);543544const testInputOption = async (t, type, execaMethod) => {545 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});546 t.is(stdout, foobarUppercase);
152 unmodified lines
modified:test/stream/all.js+72 added-9 removed
1import test from 'ava';2import {execa} from '../../index.js';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {defaultHighWaterMark} from '../helpers/stream.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();89const textEncoder = new TextEncoder();10const foobarStringFull = `${foobarString}\n`;11const doubleFoobarStringFull = `${foobarStringFull}${foobarStringFull}`;12const doubleFoobarString = `${foobarStringFull}${foobarString}`;13const doubleFoobarUint8ArrayFull = textEncoder.encode(doubleFoobarStringFull);14const doubleFoobarUint8Array = textEncoder.encode(doubleFoobarString);15const doubleFoobarArrayFull = [foobarStringFull, foobarStringFull];16const doubleFoobarArray = [foobarString, foobarString];1718// eslint-disable-next-line max-params19const testAllBoth = async (t, expectedOutput, encoding, lines, stripFinalNewline, isFailure, execaMethod) => {20 const fixtureName = isFailure ? 'noop-both-fail.js' : 'noop-both.js';21 const {exitCode, all} = await execaMethod(fixtureName, [foobarString], {all: true, encoding, lines, stripFinalNewline, reject: !isFailure});22 t.is(exitCode, isFailure ? 1 : 0);23 t.deepEqual(all, expectedOutput);24};2526test('result.all is defined', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execa);27test('result.all is defined, encoding "buffer"', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execa);28test('result.all is defined, stripFinalNewline', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execa);29test('result.all is defined, encoding "buffer", stripFinalNewline', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execa);30test('result.all is defined, failure', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execa);31test('result.all is defined, encoding "buffer", failure', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execa);32test('result.all is defined, stripFinalNewline, failure', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execa);33test('result.all is defined, encoding "buffer", stripFinalNewline, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execa);34test('result.all is defined, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execaSync);35test('result.all is defined, encoding "buffer", sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execaSync);36test('result.all is defined, lines, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execaSync);37test('result.all is defined, stripFinalNewline, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execaSync);38test('result.all is defined, encoding "buffer", stripFinalNewline, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execaSync);39test('result.all is defined, lines, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execaSync);40test('result.all is defined, failure, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execaSync);41test('result.all is defined, encoding "buffer", failure, sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execaSync);42test('result.all is defined, lines, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execaSync);43test('result.all is defined, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execaSync);44test('result.all is defined, encoding "buffer", stripFinalNewline, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execaSync);45test('result.all is defined, lines, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execaSync);4647test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {48 const {all} = await execa('noop-132.js', {all: true});49 t.is(all, '132');50});5113test('result.all is undefined unless opts.all is true', async t => {14 const {all} = await execa('noop.js');15 t.is(all, undefined);52test('result.all shows both `stdout` and `stderr` not intermixed, sync', t => {53 const {all} = execaSync('noop-132.js', {all: true});54 t.is(all, '123');55});5618test('result.all is undefined if ignored', async t => {19 const {all} = await execa('noop.js', {stdio: 'ignore', all: true});57const testAllIgnored = async (t, options, execaMethod) => {58 const {all} = await execaMethod('noop.js');59 t.is(all, undefined);21});60};6162test('result.all is undefined unless opts.all is true', testAllIgnored, {}, execa);63test('result.all is undefined if opts.all is false', testAllIgnored, {all: false}, execa);64test('result.all is undefined if ignored', testAllIgnored, {stdio: 'ignore', all: true}, execa);65test('result.all is undefined unless opts.all is true, sync', testAllIgnored, {}, execaSync);66test('result.all is undefined if opts.all is false, sync', testAllIgnored, {all: false}, execaSync);67test('result.all is undefined if ignored, sync', testAllIgnored, {stdio: 'ignore', all: true}, execaSync);6869const testAllProperties = async (t, options) => {70 const subprocess = execa('empty.js', {...options, all: true});71 t.is(subprocess.all.readableObjectMode, false);72 t.is(subprocess.all.readableHighWaterMark, defaultHighWaterMark);
13 unmodified lines
86 t.is(subprocess.all.readableHighWaterMark, subprocess[streamName].readableHighWaterMark);8788 const result = await subprocess;89 t.is(result[otherStreamName], undefined);44 t.is(result[streamName], 'foobar');45 t.is(result.all, 'foobar');90 t.is(result[streamName], foobarString);91 t.is(result.all, foobarString);92};9394test('can use all: true with stdout: ignore', testAllIgnore, 'stderr', 'stdout');95test('can use all: true with stderr: ignore', testAllIgnore, 'stdout', 'stderr');9697const testAllIgnoreSync = (t, streamName, otherStreamName) => {98 const result = execaSync('noop-both.js', {[otherStreamName]: 'ignore', all: true});99 t.is(result[otherStreamName], undefined);100 t.is(result[streamName], foobarString);101 t.is(result.all, foobarString);102};103104test('can use all: true with stdout: ignore, sync', testAllIgnoreSync, 'stderr', 'stdout');105test('can use all: true with stderr: ignore, sync', testAllIgnoreSync, 'stdout', 'stderr');106107test('can use all: true with stdout: ignore + stderr: ignore', async t => {108 const subprocess = execa('noop-both.js', {stdout: 'ignore', stderr: 'ignore', all: true});109 t.is(subprocess.stdout, null);110 t.is(subprocess.stderr, null);
3 unmodified lines
114 t.is(stdout, undefined);115 t.is(stderr, undefined);116 t.is(all, undefined);117});118119test('can use all: true with stdout: ignore + stderr: ignore, sync', t => {120 const {stdout, stderr, all} = execaSync('noop-both.js', {stdout: 'ignore', stderr: 'ignore', all: true});121 t.is(stdout, undefined);122 t.is(stderr, undefined);123 t.is(all, undefined);124});
modified:test/verbose/info.js+7 added-4 removed
1import test from 'ava';2import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {execa} from '../../index.js';3import {execa, execaSync} from '../../index.js';4import {foobarString} from '../helpers/input.js';5import {6 QUOTE,7 nestedExecaAsync,
5 unmodified lines
13} from '../helpers/verbose.js';1415setFixtureDir();1617test('Prints command, NODE_DEBUG=execa + "inherit"', async t => {18 const {all} = await execa('verbose-script.js', {env: {NODE_DEBUG: 'execa'}, all: true});17const testVerboseGeneral = async (t, execaMethod) => {18 const {all} = await execaMethod('verbose-script.js', {env: {NODE_DEBUG: 'execa'}, all: true});19 t.deepEqual(getNormalizedLines(all), [20 `${testTimestamp} [0] $ node -e ${QUOTE}console.error(1)${QUOTE}`,21 '1',22 `${testTimestamp} [0] √ (done in 0ms)`,23 `${testTimestamp} [1] $ node -e ${QUOTE}process.exit(2)${QUOTE}`,24 `${testTimestamp} [1] ‼ Command failed with exit code 2: node -e ${QUOTE}process.exit(2)${QUOTE}`,25 `${testTimestamp} [1] ‼ (done in 0ms)`,26 ]);27});27};2829test('Prints command, NODE_DEBUG=execa + "inherit"', testVerboseGeneral, execa);30test('Prints command, NODE_DEBUG=execa + "inherit", sync', testVerboseGeneral, execaSync);3132test('NODE_DEBUG=execa changes verbose default value to "full"', async t => {33 const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});34 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);35 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);
10 unmodified lines
modified:index.d.ts+9 added-9 removed
227 unmodified lines
228 : IsInputStdioDescriptor<FdNumber, OptionsType> extends true229 ? true230 : IgnoresStreamResult<FdNumber, OptionsType>;231232type LacksBuffer<BufferOption extends Options['buffer']> = BufferOption extends false ? true : false;232type LacksBuffer<BufferOption extends CommonOptions['buffer']> = BufferOption extends false ? true : false;233234// Whether `result.stdio[FdNumber]` is an input stream235type IsInputStdioDescriptor<236 FdNumber extends string,
70 unmodified lines
307 : string[]308 : string;309310// Type of `result.all`311type AllOutput<OptionsType extends Options = Options> = AllOutputProperty<OptionsType['all'], OptionsType>;311type AllOutput<OptionsType extends CommonOptions = CommonOptions> = AllOutputProperty<OptionsType['all'], OptionsType>;312313type AllOutputProperty<314 AllOption extends Options['all'] = Options['all'],315 OptionsType extends Options = Options,314 AllOption extends CommonOptions['all'] = CommonOptions['all'],315 OptionsType extends CommonOptions = CommonOptions,316> = AllOption extends true317 ? StdioOutput<AllUsesStdout<OptionsType> extends true ? '1' : '2', OptionsType>318 : undefined;319320type AllUsesStdout<OptionsType extends Options = Options> = IgnoresStreamOutput<'1', OptionsType> extends true320type AllUsesStdout<OptionsType extends CommonOptions = CommonOptions> = IgnoresStreamOutput<'1', OptionsType> extends true321 ? false322 : IgnoresStreamOutput<'2', OptionsType> extends true323 ? true324 : IsObjectStream<'2', OptionsType> extends true
356 unmodified lines
681 Add an `.all` property on the promise and the resolved value. The property contains the output of the subprocess with `stdout` and `stderr` interleaved.682683 @default false684 */685 readonly all?: Unless<IsSync, boolean>;685 readonly all?: boolean;686687 /**688 Enables exchanging messages with the subprocess using [`subprocess.send(value)`](https://nodejs.org/api/child_process.html#subprocesssendmessage-sendhandle-options-callback) and [`subprocess.on('message', (value) => {})`](https://nodejs.org/api/child_process.html#event-message).689
154 unmodified lines
844 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)845846 This is an array if the `lines` option is `true`, or if either the `stdout` or `stderr` option is a transform in object mode.847 */848 all: Unless<IsSync, AllOutput<StricterOptions<OptionsType, Options>>>;848 all: AllOutput<OptionsType>;849850 /**851 Results of the other subprocesses that were piped into this subprocess. This is useful to inspect a series of subprocesses piped with each other.852
565 unmodified lines
1418Same as `execa()` but synchronous.14191420Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.14211422Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1422Cannot use the following options: `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. `result.all` is not interleaved. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.14231424@param file - The program/script to execute, as a string or file URL1425@param arguments - Arguments to pass to `file` on execution.1426@returns A `subprocessResult` object
105 unmodified lines
1532Same as `execaCommand()` but synchronous.15331534Returns or throws a `subprocessResult`. The `subprocess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()`, `.iterable()`, `.readable()`, `.writable()`, `.duplex()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.15351536Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1536Cannot use the following options: `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. `result.all` is not interleaved. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async transform, a `Duplex`, or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.15371538@param command - The program/script to execute and its arguments.1539@returns A `subprocessResult` object1540@throws A `subprocessResult` error
128 unmodified lines
modified:index.test-d.ts+48 added-40 removed
171 unmodified lines
172expectType<AnyChunk>({} as ExecaResult['all']);173expectAssignable<[undefined, AnyChunk, AnyChunk, ...AnyChunk[]]>({} as ExecaResult['stdio']);174expectType<AnyChunk>({} as ExecaSyncResult['stdout']);175expectType<AnyChunk>({} as ExecaSyncResult['stderr']);176expectType<AnyChunk>({} as ExecaSyncResult['all']);177expectAssignable<[undefined, AnyChunk, AnyChunk, ...AnyChunk[]]>({} as ExecaSyncResult['stdio']);178179try {180 const execaPromise = execa('unicorns', {all: true});
910 unmodified lines
1091expectType<string | undefined>(noRejectsResult.code);1092expectType<unknown>(noRejectsResult.cause);10931094try {1094 const unicornsResult = execaSync('unicorns');1095 const unicornsResult = execaSync('unicorns', {all: true});10961097 expectAssignable<ExecaSyncResult>(unicornsResult);1098 expectType<string>(unicornsResult.command);1099 expectType<string>(unicornsResult.escapedCommand);
13 unmodified lines
1113 expectType<string>(unicornsResult.stdout);1114 expectType<string>(unicornsResult.stdio[1]);1115 expectType<string>(unicornsResult.stderr);1116 expectType<string>(unicornsResult.stdio[2]);1116 expectError(unicornsResult.all.toString());1117 expectType<string>(unicornsResult.all);11181118 const bufferResult = execaSync('unicorns', {encoding: 'buffer'});1119 const bufferResult = execaSync('unicorns', {encoding: 'buffer', all: true});1120 expectType<Uint8Array>(bufferResult.stdout);1121 expectType<Uint8Array>(bufferResult.stdio[1]);1122 expectType<Uint8Array>(bufferResult.stderr);1123 expectType<Uint8Array>(bufferResult.stdio[2]);1123 expectError(bufferResult.all.toString());1124 expectType<Uint8Array>(bufferResult.all);11251125 const linesResult = execaSync('unicorns', {lines: true});1126 const linesResult = execaSync('unicorns', {lines: true, all: true});1127 expectType<string[]>(linesResult.stdout);1128 expectType<string[]>(linesResult.stderr);1129 expectType<string[]>(linesResult.all);11301129 const linesBufferResult = execaSync('unicorns', {lines: true, encoding: 'buffer'});1131 const linesBufferResult = execaSync('unicorns', {lines: true, encoding: 'buffer', all: true});1132 expectType<Uint8Array>(linesBufferResult.stdout);1133 expectType<Uint8Array>(linesBufferResult.stderr);1134 expectType<Uint8Array>(linesBufferResult.all);11351133 const linesHexResult = execaSync('unicorns', {lines: true, encoding: 'hex'});1136 const linesHexResult = execaSync('unicorns', {lines: true, encoding: 'hex', all: true});1137 expectType<string>(linesHexResult.stdout);1138 expectType<string>(linesHexResult.stderr);1139 expectType<string>(linesHexResult.all);11401137 const noBufferResult = execaSync('unicorns', {buffer: false});1141 const noBufferResult = execaSync('unicorns', {buffer: false, all: true});1142 expectType<undefined>(noBufferResult.stdout);1143 expectType<undefined>(noBufferResult.stderr);1144 expectType<undefined>(noBufferResult.all);11451141 const ignoreStdoutResult = execaSync('unicorns', {stdout: 'ignore'});1146 const ignoreStdoutResult = execaSync('unicorns', {stdout: 'ignore', all: true});1147 expectType<undefined>(ignoreStdoutResult.stdout);1148 expectType<undefined>(ignoreStdoutResult.stdio[1]);1149 expectType<string>(ignoreStdoutResult.stderr);1150 expectType<string>(ignoreStdoutResult.stdio[2]);1146 expectError(ignoreStdoutResult.all.toString());1151 expectType<string>(ignoreStdoutResult.all);11521148 const ignoreStderrResult = execaSync('unicorns', {stderr: 'ignore'});1153 const ignoreStderrResult = execaSync('unicorns', {stderr: 'ignore', all: true});1154 expectType<string>(ignoreStderrResult.stdout);1155 expectType<undefined>(ignoreStderrResult.stderr);1151 expectError(ignoreStderrResult.all.toString());1156 expectType<string>(ignoreStderrResult.all);11571153 const inheritStdoutResult = execaSync('unicorns', {stdout: 'inherit'});1158 const inheritStdoutResult = execaSync('unicorns', {stdout: 'inherit', all: true});1159 expectType<undefined>(inheritStdoutResult.stdout);1160 expectType<string>(inheritStdoutResult.stderr);1156 expectError(inheritStdoutResult.all.toString());1161 expectType<string>(inheritStdoutResult.all);11621158 const inheritStderrResult = execaSync('unicorns', {stderr: 'inherit'});1163 const inheritStderrResult = execaSync('unicorns', {stderr: 'inherit', all: true});1164 expectType<string>(inheritStderrResult.stdout);1165 expectType<undefined>(inheritStderrResult.stderr);1161 expectError(inheritStderrResult.all.toString());1166 expectType<string>(inheritStderrResult.all);11671163 const numberStdoutResult = execaSync('unicorns', {stdout: 1});1168 const numberStdoutResult = execaSync('unicorns', {stdout: 1, all: true});1169 expectType<undefined>(numberStdoutResult.stdout);1170 expectType<string>(numberStdoutResult.stderr);1166 expectError(numberStdoutResult.all.toString());1171 expectType<string>(numberStdoutResult.all);11721168 const numberStderrResult = execaSync('unicorns', {stderr: 1});1173 const numberStderrResult = execaSync('unicorns', {stderr: 1, all: true});1174 expectType<string>(numberStderrResult.stdout);1175 expectType<undefined>(numberStderrResult.stderr);1171 expectError(numberStderrResult.all.toString());1176 expectType<string>(numberStderrResult.all);1177} catch (error: unknown) {1178 if (error instanceof ExecaSyncError) {1179 expectAssignable<ExecaSyncError>(error);1180 expectType<'ExecaSyncError'>(error.name);
13 unmodified lines
1194 expectType<unknown>(error.cause);1195 expectType<[]>(error.pipedFrom);1196 }11971193 const execaStringError = error as ExecaSyncError<{}>;1198 const execaStringError = error as ExecaSyncError<{all: true}>;1199 expectType<undefined>(execaStringError.stdio[0]);1200 expectType<string>(execaStringError.stdout);1201 expectType<string>(execaStringError.stdio[1]);1202 expectType<string>(execaStringError.stderr);1203 expectType<string>(execaStringError.stdio[2]);1199 expectError(execaStringError.all.toString());1204 expectType<string>(execaStringError.all);12051201 const execaBufferError = error as ExecaSyncError<{encoding: 'buffer'}>;1206 const execaBufferError = error as ExecaSyncError<{encoding: 'buffer'; all: true}>;1207 expectType<Uint8Array>(execaBufferError.stdout);1208 expectType<Uint8Array>(execaBufferError.stdio[1]);1209 expectType<Uint8Array>(execaBufferError.stderr);1210 expectType<Uint8Array>(execaBufferError.stdio[2]);1206 expectError(execaBufferError.all.toString());1211 expectType<Uint8Array>(execaBufferError.all);12121208 const execaLinesError = error as ExecaSyncError<{lines: true}>;1213 const execaLinesError = error as ExecaSyncError<{lines: true; all: true}>;1214 expectType<string[]>(execaLinesError.stdout);1215 expectType<string[]>(execaLinesError.stderr);1216 expectType<string[]>(execaLinesError.all);12171212 const execaLinesBufferError = error as ExecaSyncError<{lines: true; encoding: 'buffer'}>;1218 const execaLinesBufferError = error as ExecaSyncError<{lines: true; encoding: 'buffer'; all: true}>;1219 expectType<Uint8Array>(execaLinesBufferError.stdout);1220 expectType<Uint8Array>(execaLinesBufferError.stderr);1221 expectType<Uint8Array>(execaLinesBufferError.all);12221216 const noBufferError = error as ExecaSyncError<{buffer: false}>;1223 const noBufferError = error as ExecaSyncError<{buffer: false; all: true}>;1224 expectType<undefined>(noBufferError.stdout);1225 expectType<undefined>(noBufferError.stderr);1226 expectType<undefined>(noBufferError.all);12271220 const ignoreStdoutError = error as ExecaSyncError<{stdout: 'ignore'}>;1228 const ignoreStdoutError = error as ExecaSyncError<{stdout: 'ignore'; all: true}>;1229 expectType<undefined>(ignoreStdoutError.stdout);1230 expectType<undefined>(ignoreStdoutError.stdio[1]);1231 expectType<string>(ignoreStdoutError.stderr);1232 expectType<string>(ignoreStdoutError.stdio[2]);1225 expectError(ignoreStdoutError.all.toString());1233 expectType<string>(ignoreStdoutError.all);12341227 const ignoreStderrError = error as ExecaSyncError<{stderr: 'ignore'}>;1235 const ignoreStderrError = error as ExecaSyncError<{stderr: 'ignore'; all: true}>;1236 expectType<string>(ignoreStderrError.stdout);1237 expectType<undefined>(ignoreStderrError.stderr);1230 expectError(ignoreStderrError.all.toString());1238 expectType<string>(ignoreStderrError.all);12391232 const inheritStdoutError = error as ExecaSyncError<{stdout: 'inherit'}>;1240 const inheritStdoutError = error as ExecaSyncError<{stdout: 'inherit'; all: true}>;1241 expectType<undefined>(inheritStdoutError.stdout);1242 expectType<string>(inheritStdoutError.stderr);1235 expectError(inheritStdoutError.all.toString());1243 expectType<string>(inheritStdoutError.all);12441237 const inheritStderrError = error as ExecaSyncError<{stderr: 'inherit'}>;1245 const inheritStderrError = error as ExecaSyncError<{stderr: 'inherit'; all: true}>;1246 expectType<string>(inheritStderrError.stdout);1247 expectType<undefined>(inheritStderrError.stderr);1240 expectError(inheritStderrError.all.toString());1248 expectType<string>(inheritStderrError.all);12491242 const numberStdoutError = error as ExecaSyncError<{stdout: 1}>;1250 const numberStdoutError = error as ExecaSyncError<{stdout: 1; all: true}>;1251 expectType<undefined>(numberStdoutError.stdout);1252 expectType<string>(numberStdoutError.stderr);1245 expectError(numberStdoutError.all.toString());1253 expectType<string>(numberStdoutError.all);12541247 const numberStderrError = error as ExecaSyncError<{stderr: 1}>;1255 const numberStderrError = error as ExecaSyncError<{stderr: 1; all: true}>;1256 expectType<string>(numberStderrError.stdout);1257 expectType<undefined>(numberStderrError.stderr);1250 expectError(numberStderrError.all.toString());1258 expectType<string>(numberStderrError.all);1259}12601261const rejectsSyncResult = execaSync('unicorns');1262expectError(rejectsSyncResult.stack?.toString());
144 unmodified lines
1407execaSync('unicorns', {buffer: false});1408expectError(execa('unicorns', {buffer: 'false'}));1409expectError(execaSync('unicorns', {buffer: 'false'}));1410execa('unicorns', {all: true});1403expectError(execaSync('unicorns', {all: true}));1411execaSync('unicorns', {all: true});1412expectError(execa('unicorns', {all: 'true'}));1413expectError(execaSync('unicorns', {all: 'true'}));1414execa('unicorns', {ipc: true});1415expectError(execaSync('unicorns', {ipc: true}));
2359 unmodified lines
modified:readme.md+1 added-1 removed
317 unmodified lines
318Same as [`execa()`](#execafile-arguments-options) but synchronous.319320Returns or throws a [`subprocessResult`](#subprocessResult). The [`subprocess`](#subprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options), [`.iterable()`](#iterablereadableoptions), [`.readable()`](#readablereadableoptions), [`.writable()`](#writablewritableoptions), [`.duplex()`](#duplexduplexoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`forceKillAfterDelay`](#forcekillafterdelay). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.322Cannot use the following options: [`cleanup`](#cleanup), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`forceKillAfterDelay`](#forcekillafterdelay). [`result.all`](#all-1) is not interleaved. Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [`stdio`](#stdio-1) options cannot be [`'overlapped'`](https://nodejs.org/api/child_process.html#optionsstdio), an async iterable, an async [transform](docs/transform.md), a [`Duplex`](docs/transform.md#duplextransform-streams), or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.323324#### $(file, arguments?, options?)325326`file`: `string | URL`\
899 unmodified lines