Skip to content
Myr

Add support for `buffer: false` to `execaSync()` (#953)

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

authored by ehmicky · committed by GitHub · parent 88bff1f · Browse files · 17 files+182 added−43 removed
This commit

State

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

Diff stats

17 files+182 added−43 removed

  • tests:+151 added−30 removed
  • other:+31 added−13 removed

17 files+182 added−43 removed

modified:lib/stdio/handle.js+1 added-1 removed
modified:lib/stdio/option.js+13 added-4 removed
modified:lib/stdio/output-sync.js+4 added-3 removed
12 unmodified lines
13 transformOutputResultSync({result, fileDescriptors, fdNumber, state}, options));14 return {output: transformedOutput, ...state};15};1617const transformOutputResultSync = ({result, fileDescriptors, fdNumber, state}, {encoding, lines}) => {17const transformOutputResultSync = ({result, fileDescriptors, fdNumber, state}, {buffer, encoding, lines}) => {18 if (result === null) {19 return result;20 }21
3 unmodified lines
25 const uint8ArrayResult = bufferToUint8Array(result);26 const generators = getGenerators(allStdioItems);27 const chunks = runOutputGeneratorsSync([uint8ArrayResult], generators, state);28 const {serializedResult, finalResult} = serializeChunks({chunks, generators, allOutputLines, encoding, lines});29 const returnedResult = buffer ? finalResult : undefined;3031 try {32 if (state.error === undefined) {33 writeToFiles(serializedResult, allStdioItems);34 }3535 return finalResult;36 return returnedResult;37 } catch (error) {38 state.error = error;38 return finalResult;39 return returnedResult;40 }41};4243const runOutputGeneratorsSync = (chunks, generators, state) => {
25 unmodified lines
modified:test/fixtures/nested-transform.js+8 added-3 removed
added:test/fixtures/nested-write.js+8 added
1#!/usr/bin/env node2import {writeFile} from 'node:fs/promises';3import {text} from 'node:stream/consumers';4import process from 'node:process';56const [filePath, bytes] = process.argv.slice(2);7const stdinString = await text(process.stdin);8await writeFile(filePath, `${stdinString} ${bytes}`);
modified:test/helpers/generator.js+2 added-1 removed
75 unmodified lines
76 }77});7879const textDecoder = new TextDecoder();80const textEncoder = new TextEncoder();8182export const uppercaseBufferGenerator = getGenerator(function * (buffer) {82 yield textDecoder.decode(buffer).toUpperCase();83 yield textEncoder.encode(textDecoder.decode(buffer).toUpperCase());84});8586export const uppercaseGenerator = getGenerator(function * (string) {87 yield string.toUpperCase();
26 unmodified lines
modified:test/helpers/input.js+2 added-1 removed
4 unmodified lines
5export const bufferToUint8Array = buffer => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);67export const foobarString = 'foobar';8export const foobarArray = ['foo', 'bar'];9export const foobarUint8Array = textEncoder.encode('foobar');9export const foobarUint8Array = textEncoder.encode(foobarString);10export const foobarArrayBuffer = foobarUint8Array.buffer;11export const foobarUint16Array = new Uint16Array(foobarArrayBuffer);12export const foobarBuffer = Buffer.from(foobarString);13const foobarUtf16Buffer = Buffer.from(foobarString, 'utf16le');14export const foobarUtf16Uint8Array = bufferToUint8Array(foobarUtf16Buffer);15export const foobarDataView = new DataView(foobarArrayBuffer);16export const foobarHex = foobarBuffer.toString('hex');17export const foobarUppercase = foobarString.toUpperCase();18export const foobarUppercaseUint8Array = textEncoder.encode(foobarUppercase);19export const foobarUppercaseHex = Buffer.from(foobarUppercase).toString('hex');20export const foobarObject = {foo: 'bar'};21export const foobarObjectString = JSON.stringify(foobarObject);
modified:test/stdio/encoding-final.js+1 added-1 removed
17 unmodified lines
18 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});19 compareValues(t, stdio[fdNumber], encoding);2021 if (execaMethod !== execaSync) {22 const subprocess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding, buffer: false});22 const subprocess = execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});23 const getStreamMethod = encoding === 'buffer' ? getStreamAsBuffer : getStream;24 const result = await getStreamMethod(subprocess.stdio[fdNumber]);25 compareValues(t, result, encoding);26 await subprocess;
197 unmodified lines
modified:test/stdio/file-path.js+14 added
320 unmodified lines
321test('stderr can use "lines: true" together with output file URLs, sync', testOutputFileLines, 2, pathToFileURL, execaSync);322test('stdio[*] can use "lines: true" together with output file paths, sync', testOutputFileLines, 3, getAbsolutePath, execaSync);323test('stdio[*] can use "lines: true" together with output file URLs, sync', testOutputFileLines, 3, pathToFileURL, execaSync);324325const testOutputFileNoBuffer = async (t, execaMethod) => {326 const filePath = tempfile();327 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {328 stdout: getAbsolutePath(filePath),329 buffer: false,330 });331 t.is(stdout, undefined);332 t.is(await readFile(filePath, 'utf8'), foobarString);333 await rm(filePath);334};335336test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, execa);337test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, execaSync);338339const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {340 const filePath = tempfile();341 t.throws(() => {342 execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [
52 unmodified lines
modified:test/stdio/lines.js+6 added-3 removed
127 unmodified lines
128test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testTextEncoding, noNewlinesChunks, true, execa);129test('"lines: true" is a noop with "encoding: utf16", sync', testTextEncoding, simpleLines, false, execaSync);130test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testTextEncoding, noNewlinesChunks, true, execaSync);131132test('"lines: true" is a noop with "buffer: false"', async t => {133 const {stdout} = await getSimpleChunkSubprocessAsync({buffer: false});132const testLinesNoBuffer = async (t, execaMethod) => {133 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {buffer: false});134 t.is(stdout, undefined);135});135};136137test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, execa);138test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, execaSync);139140test('"lines: true" can be below "maxBuffer"', async t => {141 const maxBuffer = simpleLines.length;142 const {stdout} = await getSimpleChunkSubprocessAsync({maxBuffer});143 t.deepEqual(stdout, noNewlinesChunks);
72 unmodified lines
modified:test/stdio/native.js+22 added-9 removed
1import {readFile, rm} from 'node:fs/promises';2import {platform} from 'node:process';3import test from 'ava';4import tempfile from 'tempfile';5import {execa} from '../../index.js';6import {getStdio, fullStdio} from '../helpers/stdio.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {foobarString} from '../helpers/input.js';910setFixtureDir();1112const testRedirect = async (t, stdioOption, fdNumber, isInput) => {13 const {fixtureName, ...options} = isInput11 ? {fixtureName: 'stdin-fd.js', input: 'foobar'}14 ? {fixtureName: 'stdin-fd.js', input: foobarString}15 : {fixtureName: 'noop-fd.js'};13 const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, fixtureName, 'foobar'], options);16 const {stdio} = await execa('nested-stdio.js', [JSON.stringify(stdioOption), `${fdNumber}`, fixtureName, foobarString], options);17 const resultFdNumber = isStderrDescriptor(stdioOption) ? 2 : 1;15 t.is(stdio[resultFdNumber], 'foobar');18 t.is(stdio[resultFdNumber], foobarString);19};2021const isStderrDescriptor = stdioOption => stdioOption === 222 || stdioOption === 'stderr'
30 unmodified lines
53test('stdio[*] can be [process.stderr]', testRedirect, ['stderr'], 3, false);54test('stdio[*] can be [process.stderr, "pipe"]', testRedirect, ['stderr', 'pipe'], 3, false);5556const testInheritStdin = async (t, stdin) => {54 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdin)], {input: 'foobar'});55 t.is(stdout, 'foobarfoobar');57 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdin)], {input: foobarString});58 t.is(stdout, `${foobarString}${foobarString}`);59};6061test('stdin can be ["inherit", "pipe"]', testInheritStdin, ['inherit', 'pipe']);62test('stdin can be [0, "pipe"]', testInheritStdin, [0, 'pipe']);6364const testInheritStdout = async (t, stdout) => {65 const result = await execa('nested-multiple-stdout.js', [JSON.stringify(stdout)]);63 t.is(result.stdout, 'foobar');64 t.is(result.stderr, 'nested foobar');66 t.is(result.stdout, foobarString);67 t.is(result.stderr, `nested ${foobarString}`);68};6970test('stdout can be ["inherit", "pipe"]', testInheritStdout, ['inherit', 'pipe']);71test('stdout can be [1, "pipe"]', testInheritStdout, [1, 'pipe']);7273const testInheritStderr = async (t, stderr) => {74 const result = await execa('nested-multiple-stderr.js', [JSON.stringify(stderr)]);72 t.is(result.stdout, 'nested foobar');73 t.is(result.stderr, 'foobar');75 t.is(result.stdout, `nested ${foobarString}`);76 t.is(result.stderr, foobarString);77};7879test('stderr can be ["inherit", "pipe"]', testInheritStderr, ['inherit', 'pipe']);80test('stderr can be [2, "pipe"]', testInheritStderr, [2, 'pipe']);8182const testInheritNoBuffer = async (t, stdioOption) => {83 const filePath = tempfile();84 await execa('nested.js', [JSON.stringify({stdin: stdioOption, buffer: false}), 'nested-write.js', filePath, foobarString], {input: foobarString});85 t.is(await readFile(filePath, 'utf8'), `${foobarString} ${foobarString}`);86 await rm(filePath);87};8889test('stdin can be ["inherit", "pipe"], buffer: false', testInheritNoBuffer, ['inherit', 'pipe']);90test('stdin can be [0, "pipe"], buffer: false', testInheritNoBuffer, [0, 'pipe']);9192const testOverflowStream = async (t, fdNumber, stdioOption) => {93 const {stdout} = await execa('nested.js', [JSON.stringify(getStdio(fdNumber, stdioOption)), 'empty.js'], fullStdio);94 t.is(stdout, '');95};
26 unmodified lines
modified:test/stream/max-buffer.js+11 added-1 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import getStream from 'get-stream';4import {execa} from '../../index.js';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {fullStdio} from '../helpers/stdio.js';78setFixtureDir();
71 unmodified lines
80test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1);81test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2);82test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3);8384const testNoMaxBufferSync = (t, fdNumber) => {85 const {stdio} = execaSync('max-buffer.js', [`${fdNumber}`, `${maxBuffer}`], {...fullStdio, buffer: false});86 t.is(stdio[fdNumber], undefined);87};8889// @todo: add a test for fd3 once the following Node.js bug is fixed.90// https://github.com/nodejs/node/issues/5233891test('do not buffer stdout when `buffer` set to `false`, sync', testNoMaxBufferSync, 1);92test('do not buffer stderr when `buffer` set to `false`, sync', testNoMaxBufferSync, 2);9394const testNoMaxBufferOption = async (t, fdNumber) => {95 const length = maxBuffer + 1;96 const subprocess = execa('max-buffer.js', [`${fdNumber}`, `${length}`], {...fullStdio, maxBuffer, buffer: false});97 const [result, output] = await Promise.all([
22 unmodified lines
modified:test/stream/no-buffer.js+60 added-8 removed
1import {once} from 'node:events';2import test from 'ava';3import getStream from 'get-stream';4import {execa} from '../../index.js';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';7import {foobarString} from '../helpers/input.js';7import {foobarString, foobarUppercase, foobarUppercaseUint8Array} from '../helpers/input.js';8import {resultGenerator, uppercaseGenerator, uppercaseBufferGenerator} from '../helpers/generator.js';910setFixtureDir();1112const testLateStream = async (t, fdNumber, all) => {
72 unmodified lines
85test('Listen to stderr errors even when `buffer` is `false`', testNoBufferStreamError, 2, false);86test('Listen to stdio[*] errors even when `buffer` is `false`', testNoBufferStreamError, 3, false);87test('Listen to all errors even when `buffer` is `false`', testNoBufferStreamError, 1, true);8888test('buffer: false > promise resolves', async t => {89 await t.notThrowsAsync(execa('noop.js', {buffer: false}));90});89const testNoOutput = async (t, stdioOption, execaMethod) => {90 const {stdout} = await execaMethod('noop.js', {stdout: stdioOption, buffer: false});91 t.is(stdout, undefined);92};9392test('buffer: false > promise rejects when subprocess returns non-zero', async t => {93 const {exitCode} = await t.throwsAsync(execa('fail.js', {buffer: false}));94test('buffer: false does not return output', testNoOutput, 'pipe', execa);95test('buffer: false does not return output, stdout undefined', testNoOutput, undefined, execa);96test('buffer: false does not return output, stdout null', testNoOutput, null, execa);97test('buffer: false does not return output, stdout ["pipe"]', testNoOutput, ['pipe'], execa);98test('buffer: false does not return output, stdout [undefined]', testNoOutput, [undefined], execa);99test('buffer: false does not return output, stdout [null]', testNoOutput, [null], execa);100test('buffer: false does not return output, stdout ["pipe", undefined]', testNoOutput, ['pipe', undefined], execa);101test('buffer: false does not return output, sync', testNoOutput, 'pipe', execaSync);102test('buffer: false does not return output, stdout undefined, sync', testNoOutput, undefined, execaSync);103test('buffer: false does not return output, stdout null, sync', testNoOutput, null, execaSync);104test('buffer: false does not return output, stdout ["pipe"], sync', testNoOutput, ['pipe'], execaSync);105test('buffer: false does not return output, stdout [undefined], sync', testNoOutput, [undefined], execaSync);106test('buffer: false does not return output, stdout [null], sync', testNoOutput, [null], execaSync);107test('buffer: false does not return output, stdout ["pipe", undefined], sync', testNoOutput, ['pipe', undefined], execaSync);108109const testNoOutputFail = async (t, execaMethod) => {110 const {exitCode, stdout} = await execaMethod('fail.js', {buffer: false, reject: false});111 t.is(exitCode, 2);112 t.is(stdout, undefined);95});113};114115test('buffer: false does not return output, failure', testNoOutputFail, execa);116test('buffer: false does not return output, failure, sync', testNoOutputFail, execaSync);117118const testTransform = async (t, objectMode, execaMethod) => {119 const lines = [];120 const {stdout} = await execaMethod('noop.js', {121 buffer: false,122 stdout: [uppercaseGenerator(objectMode), resultGenerator(lines)(objectMode)],123 });124 t.is(stdout, undefined);125 t.deepEqual(lines, [foobarUppercase]);126};127128test('buffer: false still runs transforms', testTransform, false, execa);129test('buffer: false still runs transforms, objectMode', testTransform, true, execa);130test('buffer: false still runs transforms, sync', testTransform, false, execaSync);131test('buffer: false still runs transforms, objectMode, sync', testTransform, true, execaSync);132133const testTransformBinary = async (t, objectMode, execaMethod) => {134 const lines = [];135 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {136 buffer: false,137 stdout: [uppercaseBufferGenerator(objectMode, true), resultGenerator(lines)(objectMode)],138 encoding: 'buffer',139 });140 t.is(stdout, undefined);141 t.deepEqual(lines, [foobarUppercaseUint8Array]);142};143144test('buffer: false still runs transforms, encoding "buffer"', testTransformBinary, false, execa);145test('buffer: false still runs transforms, encoding "buffer", objectMode', testTransformBinary, true, execa);146test('buffer: false still runs transforms, encoding "buffer", sync', testTransformBinary, false, execaSync);147test('buffer: false still runs transforms, encoding "buffer", objectMode, sync', testTransformBinary, true, execaSync);148149const testStreamEnd = async (t, fdNumber, buffer) => {150 const subprocess = execa('wrong command', {...fullStdio, buffer});151 await Promise.all([152 t.throwsAsync(subprocess, {message: /wrong command/}),
10 unmodified lines
modified:test/verbose/output.js+17 added-3 removed
4 unmodified lines
5import tempfile from 'tempfile';6import {red} from 'yoctocolors';7import {execa} from '../../index.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {foobarString, foobarObject} from '../helpers/input.js';9import {foobarString, foobarObject, foobarUppercase} from '../helpers/input.js';10import {fullStdio} from '../helpers/stdio.js';11import {12 nestedExeca,13 nestedExecaAsync,
222 unmodified lines
236test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaAsync);237test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'}, nestedExecaAsync);238test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null}, nestedExecaAsync);239test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaAsync);240test('Prints stdout, buffer false', testPrintOutputOptions, {buffer: false}, nestedExecaAsync);240test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, nestedExecaSync);241test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, nestedExecaSync);242test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, nestedExecaSync);244test('Prints stdout, buffer false, sync', testPrintOutputOptions, {buffer: false}, nestedExecaSync);243244const testPrintOutputNoBuffer = async (t, execaMethod) => {245 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', buffer: false});246 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);247};248249test('Prints stdout, buffer: false', testPrintOutputNoBuffer, nestedExecaAsync);250test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, nestedExecaSync);251252const testPrintOutputNoBufferTransform = async (t, isSync) => {253 const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer: false, type: 'generator', isSync});254 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);255};256257test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false);258test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, true);259260const testPrintOutputFixture = async (t, fixtureName, ...args) => {261 const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});262 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);263};
3 unmodified lines
modified:index.d.ts+3 added-3 removed
663 unmodified lines
664 When `buffer` is `false`, the output can still be read using the `subprocess.stdout`, `subprocess.stderr`, `subprocess.stdio` and `subprocess.all` streams. If the output is read, this should be done right away to avoid missing any data.665666 @default true667 */668 readonly buffer?: Unless<IsSync, boolean>;668 readonly buffer?: boolean;669670 /**671 Add an `.all` property on the promise and the resolved value. The property contains the output of the subprocess with `stdout` and `stderr` interleaved.672
735 unmodified lines
1408Same as `execa()` but synchronous.14091410Returns 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.14111412Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'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.1412Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'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.14131414@param file - The program/script to execute, as a string or file URL1415@param arguments - Arguments to pass to `file` on execution.1416@returns A `subprocessResult` object
105 unmodified lines
1522Same as `execaCommand()` but synchronous.15231524Returns 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.15251526Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'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.1526Cannot use the following options: `all`, `cleanup`, `detached`, `ipc`, `serialization`, `cancelSignal` and `forceKillAfterDelay`. Also, the `stdin`, `stdout`, `stderr` and `stdio` options cannot be a `['pipe', 'inherit']` array, [`'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.15271528@param command - The program/script to execute and its arguments.1529@returns A `subprocessResult` object1530@throws A `subprocessResult` error
128 unmodified lines
modified:index.test-d.ts+9 added-1 removed
1132 unmodified lines
1133 const linesHexResult = execaSync('unicorns', {lines: true, encoding: 'hex'});1134 expectType<string>(linesHexResult.stdout);1135 expectType<string>(linesHexResult.stderr);11361137 const noBufferResult = execaSync('unicorns', {buffer: false});1138 expectType<undefined>(noBufferResult.stdout);1139 expectType<undefined>(noBufferResult.stderr);11401141 const ignoreStdoutResult = execaSync('unicorns', {stdout: 'ignore'});1142 expectType<undefined>(ignoreStdoutResult.stdout);1143 expectType<undefined>(ignoreStdoutResult.stdio[1]);1144 expectType<string>(ignoreStdoutResult.stderr);
67 unmodified lines
1212 const execaLinesBufferError = error as ExecaSyncError<{lines: true; encoding: 'buffer'}>;1213 expectType<Uint8Array>(execaLinesBufferError.stdout);1214 expectType<Uint8Array>(execaLinesBufferError.stderr);12151216 const noBufferError = error as ExecaSyncError<{buffer: false}>;1217 expectType<undefined>(noBufferError.stdout);1218 expectType<undefined>(noBufferError.stderr);12191220 const ignoreStdoutError = error as ExecaSyncError<{stdout: 'ignore'}>;1221 expectType<undefined>(ignoreStdoutError.stdout);1222 expectType<undefined>(ignoreStdoutError.stdio[1]);1223 expectType<string>(ignoreStdoutError.stderr);
171 unmodified lines
1395expectError(execaSync('unicorns', {cleanup: false}));1396expectError(execa('unicorns', {cleanup: 'false'}));1397expectError(execaSync('unicorns', {cleanup: 'false'}));1398execa('unicorns', {buffer: false});1391expectError(execaSync('unicorns', {buffer: false}));1399execaSync('unicorns', {buffer: false});1400expectError(execa('unicorns', {buffer: 'false'}));1401expectError(execaSync('unicorns', {buffer: 'false'}));1402execa('unicorns', {all: true});1403expectError(execaSync('unicorns', {all: true}));
2321 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), [`buffer`](#buffer), [`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 a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'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: [`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 a [`['pipe', 'inherit']`](#redirect-stdinstdoutstderr-to-multiple-destinations) array, [`'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