Skip to content
Myr

Allow setting different `buffer` values for `stdout`/`stderr` (#973)

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

authored by ehmicky · committed by GitHub · parent c474b30 · Browse files · 14 files+244 added−71 removed
This commit

State

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

Diff stats

14 files+244 added−71 removed

  • tests:+96 added−51 removed
  • other:+148 added−20 removed

14 files+244 added−71 removed

modified:lib/arguments/options.js+1 added-6 removed
modified:lib/arguments/specific.js+2 added-1 removed
modified:lib/stdio/option.js+7 added-3 removed
39 unmodified lines
4041 return stdioOption;42};4344const normalizeStdioSync = (stdioArray, buffer, verbose) => buffer45 ? stdioArray46 : stdioArray.map((stdioOption, fdNumber) => fdNumber !== 0 && verbose[fdNumber] !== 'full' && isOutputPipeOnly(stdioOption) ? 'ignore' : stdioOption);44const normalizeStdioSync = (stdioArray, buffer, verbose) => stdioArray.map((stdioOption, fdNumber) =>45 !buffer[fdNumber]46 && fdNumber !== 047 && verbose[fdNumber] !== 'full'48 && isOutputPipeOnly(stdioOption)49 ? 'ignore'50 : stdioOption);5152const isOutputPipeOnly = stdioOption => stdioOption === 'pipe'53 || (Array.isArray(stdioOption) && stdioOption.every(item => item === 'pipe'));54
3 unmodified lines
modified:lib/stdio/output-sync.js+1 added-1 removed
37 unmodified lines
38 const linesArray = splitLinesSync(serializedResult, false, objectMode);39 logLinesSync(linesArray, verboseInfo);40 }4142 const returnedResult = buffer ? finalResult : undefined;42 const returnedResult = buffer[fdNumber] ? finalResult : undefined;4344 try {45 if (state.error === undefined) {46 writeToFiles(serializedResult, stdioItems);
76 unmodified lines
modified:lib/stream/all.js+18 added-2 removed
6 unmodified lines
7 : undefined;89// Read the contents of `subprocess.all` and|or wait for its completion10export const waitForAllStream = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo}) => waitForSubprocessStream({11 stream: subprocess.all,11 ...getAllStream(subprocess, buffer),12 fdNumber: 1,13 encoding,14 buffer,14 maxBuffer: maxBuffer[1] + maxBuffer[2],15 lines: lines[1] || lines[2],16 isAll: true,17 allMixed: getAllMixed(subprocess),
1 unmodified line
19 verboseInfo,20 streamInfo,21});2223const getAllStream = ({stdout, stderr, all}, [, bufferStdout, bufferStderr]) => {24 const buffer = bufferStdout || bufferStderr;25 if (!buffer) {26 return {stream: all, buffer};27 }2829 if (!bufferStdout) {30 return {stream: stderr, buffer};31 }3233 if (!bufferStderr) {34 return {stream: stdout, buffer};35 }3637 return {stream: all, buffer};38};3940// When `subprocess.stdout` is in objectMode but not `subprocess.stderr` (or the opposite), we need to use both:41// - `getStreamAsArray()` for the chunks in objectMode, to return as an array without changing each chunk42// - `getStreamAsArrayBuffer()` or `getStream()` for the chunks not in objectMode, to convert them from Buffers to string or Uint8Array43// We do this by emulating the Buffer -> string|Uint8Array conversion performed by `get-stream` with our own, which is identical.
4 unmodified lines
modified:lib/stream/resolve.js+1 added-1 removed
54 unmodified lines
55};5657// Read the contents of `subprocess.std*` and|or wait for its completion58const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo}) =>59 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, fdNumber, encoding, buffer, maxBuffer: maxBuffer[fdNumber], lines: lines[fdNumber], isAll: false, allMixed: false, stripFinalNewline, verboseInfo, streamInfo}));59 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, fdNumber, encoding, buffer: buffer[fdNumber], maxBuffer: maxBuffer[fdNumber], lines: lines[fdNumber], isAll: false, allMixed: false, stripFinalNewline, verboseInfo, streamInfo}));6061// Transforms replace `subprocess.std*`, which means they are not exposed to users.62// However, we still want to wait for their completion.63const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>
23 unmodified lines
modified:test/stdio/file-path.js+6 added-4 removed
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) => {325const testOutputFileNoBuffer = async (t, buffer, execaMethod) => {326 const filePath = tempfile();327 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {328 stdout: getAbsolutePath(filePath),329 buffer: false,329 buffer,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);336test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, false, execa);337test('stdout can use "buffer: false" together with output file paths, fd-specific', testOutputFileNoBuffer, {stdout: false}, execa);338test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, false, execaSync);339test('stdout can use "buffer: false" together with output file paths, fd-specific, sync', testOutputFileNoBuffer, {stdout: false}, execaSync);340341const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {342 const filePath = tempfile();343 t.throws(() => {
53 unmodified lines
modified:test/stdio/lines.js+8 added-6 removed
145 unmodified lines
146test('"lines: true" is a noop with "encoding: hex", fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execaSync);147test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execaSync);148test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execaSync);149150const testLinesNoBuffer = async (t, lines, execaMethod) => {151 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer: false});150const testLinesNoBuffer = async (t, lines, buffer, execaMethod) => {151 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer});152 t.is(stdout, undefined);153};154155test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, execa);156test('"lines: true" is a noop with "buffer: false", fd-specific', testLinesNoBuffer, {stdout: true}, execa);157test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, execaSync);158test('"lines: true" is a noop with "buffer: false", fd-specific, sync', testLinesNoBuffer, {stdout: true}, execaSync);155test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, false, execa);156test('"lines: true" is a noop with "buffer: false", fd-specific buffer', testLinesNoBuffer, true, {stdout: false}, execa);157test('"lines: true" is a noop with "buffer: false", fd-specific lines', testLinesNoBuffer, {stdout: true}, false, execa);158test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, false, execaSync);159test('"lines: true" is a noop with "buffer: false", fd-specific buffer, sync', testLinesNoBuffer, true, {stdout: false}, execaSync);160test('"lines: true" is a noop with "buffer: false", fd-specific lines, sync', testLinesNoBuffer, {stdout: true}, false, execaSync);161162const maxBuffer = simpleLines.length - 1;163164const testBelowMaxBuffer = async (t, lines) => {
111 unmodified lines
modified:test/stream/max-buffer.js+16 added-11 removed
208 unmodified lines
209test('maxBuffer ignores other encodings and stdout, sync', testMaxBufferHexSync, 1);210test('maxBuffer ignores other encodings and stderr, sync', testMaxBufferHexSync, 2);211test('maxBuffer ignores other encodings and stdio[*], sync', testMaxBufferHexSync, 3);212213const testNoMaxBuffer = async (t, fdNumber) => {214 const subprocess = getMaxBufferSubprocess(execa, fdNumber, {buffer: false});213const testNoMaxBuffer = async (t, fdNumber, buffer) => {214 const subprocess = getMaxBufferSubprocess(execa, fdNumber, {buffer});215 const [{isMaxBuffer, stdio}, output] = await Promise.all([216 subprocess,217 getStream(subprocess.stdio[fdNumber]),218 ]);
1 unmodified line
220 t.is(stdio[fdNumber], undefined);221 t.is(output, getExpectedOutput(maxBuffer + 1));222};223224test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1);225test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2);226test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3);224test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1, false);225test('do not buffer stdout when `buffer` set to `false`, fd-specific', testNoMaxBuffer, 1, {stdout: false});226test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2, false);227test('do not buffer stderr when `buffer` set to `false`, fd-specific', testNoMaxBuffer, 2, {stderr: false});228test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3, false);229test('do not buffer stdio[*] when `buffer` set to `false`, fd-specific', testNoMaxBuffer, 3, {fd3: false});230228const testNoMaxBufferSync = (t, fdNumber) => {229 const {isMaxBuffer, stdio} = getMaxBufferSubprocess(execaSync, fdNumber, {buffer: false});231const testNoMaxBufferSync = (t, fdNumber, buffer) => {232 const {isMaxBuffer, stdio} = getMaxBufferSubprocess(execaSync, fdNumber, {buffer});233 t.false(isMaxBuffer);234 t.is(stdio[fdNumber], undefined);235};236234// @todo: add a test for fd3 once the following Node.js bug is fixed.235// https://github.com/nodejs/node/issues/52338236test('do not buffer stdout when `buffer` set to `false`, sync', testNoMaxBufferSync, 1);237test('do not buffer stderr when `buffer` set to `false`, sync', testNoMaxBufferSync, 2);237// @todo: add tests for fd3 once the following Node.js bug is fixed.238// https://github.com/nodejs/node/issues/52422239test('do not buffer stdout when `buffer` set to `false`, sync', testNoMaxBufferSync, 1, false);240test('do not buffer stdout when `buffer` set to `false`, fd-specific, sync', testNoMaxBufferSync, 1, {stdout: false});241test('do not buffer stderr when `buffer` set to `false`, sync', testNoMaxBufferSync, 2, false);242test('do not buffer stderr when `buffer` set to `false`, fd-specific, sync', testNoMaxBufferSync, 2, {stderr: false});243244const testMaxBufferAbort = async (t, fdNumber) => {245 const subprocess = getMaxBufferSubprocess(execa, fdNumber);246 const [{isMaxBuffer, shortMessage}] = await Promise.all([
19 unmodified lines
modified:test/stream/no-buffer.js+46 added-16 removed
84 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);8889const testNoOutput = async (t, stdioOption, execaMethod) => {90 const {stdout} = await execaMethod('noop.js', {stdout: stdioOption, buffer: false});89const testOutput = async (t, buffer, execaMethod) => {90 const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {buffer});91 t.is(stdout, foobarString);92};9394test('buffer: true returns output', testOutput, true, execa);95test('buffer: true returns output, fd-specific', testOutput, {stderr: false}, execa);96test('buffer: default returns output', testOutput, undefined, execa);97test('buffer: default returns output, fd-specific', testOutput, {}, execa);9899const testNoOutput = async (t, stdioOption, buffer, execaMethod) => {100 const {stdout} = await execaMethod('noop.js', {stdout: stdioOption, buffer});101 t.is(stdout, undefined);102};10394test('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);104test('buffer: false does not return output', testNoOutput, 'pipe', false, execa);105test('buffer: false does not return output, fd-specific', testNoOutput, 'pipe', {stdout: false}, execa);106test('buffer: false does not return output, stdout undefined', testNoOutput, undefined, false, execa);107test('buffer: false does not return output, stdout null', testNoOutput, null, false, execa);108test('buffer: false does not return output, stdout ["pipe"]', testNoOutput, ['pipe'], false, execa);109test('buffer: false does not return output, stdout [undefined]', testNoOutput, [undefined], false, execa);110test('buffer: false does not return output, stdout [null]', testNoOutput, [null], false, execa);111test('buffer: false does not return output, stdout ["pipe", undefined]', testNoOutput, ['pipe', undefined], false, execa);112test('buffer: false does not return output, sync', testNoOutput, 'pipe', false, execaSync);113test('buffer: false does not return output, fd-specific, sync', testNoOutput, 'pipe', {stdout: false}, execaSync);114test('buffer: false does not return output, stdout undefined, sync', testNoOutput, undefined, false, execaSync);115test('buffer: false does not return output, stdout null, sync', testNoOutput, null, false, execaSync);116test('buffer: false does not return output, stdout ["pipe"], sync', testNoOutput, ['pipe'], false, execaSync);117test('buffer: false does not return output, stdout [undefined], sync', testNoOutput, [undefined], false, execaSync);118test('buffer: false does not return output, stdout [null], sync', testNoOutput, [null], false, execaSync);119test('buffer: false does not return output, stdout ["pipe", undefined], sync', testNoOutput, ['pipe', undefined], false, execaSync);120121const testNoOutputFail = async (t, execaMethod) => {122 const {exitCode, stdout} = await execaMethod('fail.js', {buffer: false, reject: false});123 t.is(exitCode, 2);
2 unmodified lines
126127test('buffer: false does not return output, failure', testNoOutputFail, execa);128test('buffer: false does not return output, failure, sync', testNoOutputFail, execaSync);129130// eslint-disable-next-line max-params131const testNoOutputAll = async (t, buffer, bufferStdout, bufferStderr, execaMethod) => {132 const {stdout, stderr, all} = await execaMethod('noop-both.js', {all: true, buffer, stripFinalNewline: false});133 t.is(stdout, bufferStdout ? `${foobarString}\n` : undefined);134 t.is(stderr, bufferStderr ? `${foobarString}\n` : undefined);135 const stdoutStderr = [stdout, stderr].filter(Boolean);136 t.is(all, stdoutStderr.length === 0 ? undefined : stdoutStderr.join(''));137};138139test('buffer: {}, all: true', testNoOutputAll, {}, true, true, execa);140test('buffer: {stdout: false}, all: true', testNoOutputAll, {stdout: false}, false, true, execa);141test('buffer: {stderr: false}, all: true', testNoOutputAll, {stderr: false}, true, false, execa);142test('buffer: {all: false}, all: true', testNoOutputAll, {all: false}, false, false, execa);143test('buffer: {}, all: true, sync', testNoOutputAll, {}, true, true, execaSync);144test('buffer: {stdout: false}, all: true, sync', testNoOutputAll, {stdout: false}, false, true, execaSync);145test('buffer: {stderr: false}, all: true, sync', testNoOutputAll, {stderr: false}, true, false, execaSync);146test('buffer: {all: false}, all: true, sync', testNoOutputAll, {all: false}, false, false, execaSync);147148const testTransform = async (t, objectMode, execaMethod) => {149 const lines = [];150 const {stdout} = await execaMethod('noop.js', {151 buffer: false,
41 unmodified lines
modified:test/verbose/output.js+20 added-14 removed
312 unmodified lines
313test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);314test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);315test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);316317const testPrintOutputNoBuffer = async (t, verbose, execaMethod) => {318 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer: false});317const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {318 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});319 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);320};321322test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', parentExecaAsync);323test('Prints stdout, buffer: false, fd-specific', testPrintOutputNoBuffer, fdFullOption, parentExecaAsync);324test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', parentExecaSync);325test('Prints stdout, buffer: false, fd-specific, sync', testPrintOutputNoBuffer, fdFullOption, parentExecaSync);322test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);323test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);324test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, fdFullOption, false, parentExecaAsync);325test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);326test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);327test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, fdFullOption, false, parentExecaSync);328327const testPrintOutputNoBufferFalse = async (t, execaMethod) => {328 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer: false});329const testPrintOutputNoBufferFalse = async (t, buffer, execaMethod) => {330 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer});331 t.is(getOutputLine(stderr), undefined);332};333332test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, parentExecaAsync);333test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, parentExecaSync);334test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, false, parentExecaAsync);335test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaAsync);336test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, false, parentExecaSync);337test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaSync);338335const testPrintOutputNoBufferTransform = async (t, isSync) => {336 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer: false, type: 'generator', isSync});339const testPrintOutputNoBufferTransform = async (t, buffer, isSync) => {340 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer, type: 'generator', isSync});341 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);342};343340test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false);341test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, true);344test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false, false);345test('Prints stdout, buffer: false, transform, fd-specific buffer', testPrintOutputNoBufferTransform, {stdout: false}, false);346test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, false, true);347test('Prints stdout, buffer: false, transform, fd-specific buffer, sync', testPrintOutputNoBufferTransform, {stdout: false}, true);348349const testPrintOutputFixture = async (t, fixtureName, ...args) => {350 const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});351 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);
12 unmodified lines
modified:index.d.ts+7 added-5 removed
245 unmodified lines
246// Whether `result.stdout|stderr|all` is `undefined`247type IgnoresStreamOutput<248 FdNumber extends string,249 OptionsType extends CommonOptions = CommonOptions,250> = LacksBuffer<OptionsType['buffer']> extends true250> = LacksBuffer<FdSpecificOption<OptionsType['buffer'], FdNumber>> extends true251 ? true252 : IsInputStdioDescriptor<FdNumber, OptionsType> extends true253 ? true254 : IgnoresStreamResult<FdNumber, OptionsType>;255256type LacksBuffer<BufferOption extends CommonOptions['buffer']> = BufferOption extends false ? true : false;256type LacksBuffer<BufferOption extends boolean | undefined> = BufferOption extends false ? true : false;257258// Whether `result.stdio[FdNumber]` is an input stream259type IsInputStdioDescriptor<260 FdNumber extends string,
512 unmodified lines
773 On failure, the `error.stdout`, `error.stderr`, `error.all` and `error.stdio` properties are used instead.774775 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.776777 By default, this applies to both `stdout` and `stderr`, but different values can also be passed.778779 @default true780 */779 readonly buffer?: boolean;781 readonly buffer?: FdGenericOption<boolean>;782783 /**784 Add a `subprocess.all` stream and a `result.all` property. They contain the combined/[interleaved](#ensuring-all-output-is-interleaved) output of the subprocess' `stdout` and `stderr`.785
55 unmodified lines
841842/**843Subprocess options.844843Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.845Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `buffer`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.846847@example848849```
5 unmodified lines
855856/**857Subprocess options, with synchronous methods.858857Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.859Some options are related to the subprocess output: `verbose`, `lines`, `stripFinalNewline`, `buffer`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.860861@example862863```
1030 unmodified lines
modified:index.test-d.ts+108 added
1612 unmodified lines
1613execaSync('unicorns', {lines: {fd1: true}});1614execaSync('unicorns', {lines: {fd2: true}});1615execaSync('unicorns', {lines: {fd3: true}});1616expectError(execaSync('unicorns', {lines: {stdout: 'true'}}));1617execa('unicorns', {buffer: {}});1618expectError(execa('unicorns', {buffer: []}));1619execa('unicorns', {buffer: {stdout: true}});1620execa('unicorns', {buffer: {stderr: true}});1621execa('unicorns', {buffer: {stdout: true, stderr: true} as const});1622execa('unicorns', {buffer: {all: true}});1623execa('unicorns', {buffer: {fd1: true}});1624execa('unicorns', {buffer: {fd2: true}});1625execa('unicorns', {buffer: {fd3: true}});1626expectError(execa('unicorns', {buffer: {stdout: 'true'}}));1627execaSync('unicorns', {buffer: {}});1628expectError(execaSync('unicorns', {buffer: []}));1629execaSync('unicorns', {buffer: {stdout: true}});1630execaSync('unicorns', {buffer: {stderr: true}});1631execaSync('unicorns', {buffer: {stdout: true, stderr: true} as const});1632execaSync('unicorns', {buffer: {all: true}});1633execaSync('unicorns', {buffer: {fd1: true}});1634execaSync('unicorns', {buffer: {fd2: true}});1635execaSync('unicorns', {buffer: {fd3: true}});1636expectError(execaSync('unicorns', {buffer: {stdout: 'true'}}));16371638const linesStdoutResult = await execa('unicorns', {all: true, lines: {stdout: true}});1639expectType<string[]>(linesStdoutResult.stdout);1640expectType<string[]>(linesStdoutResult.stdio[1]);
81 unmodified lines
1722expectType<string>(linesFd3ResultSync.all);1723expectType<string[]>(linesFd3ResultSync.stdio[3]);1724expectType<string>(linesFd3ResultSync.stdio[4]);17251726const noBufferStdoutResult = await execa('unicorns', {all: true, buffer: {stdout: false}});1727expectType<undefined>(noBufferStdoutResult.stdout);1728expectType<undefined>(noBufferStdoutResult.stdio[1]);1729expectType<string>(noBufferStdoutResult.stderr);1730expectType<string>(noBufferStdoutResult.stdio[2]);1731expectType<string>(noBufferStdoutResult.all);17321733const noBufferStderrResult = await execa('unicorns', {all: true, buffer: {stderr: false}});1734expectType<string>(noBufferStderrResult.stdout);1735expectType<string>(noBufferStderrResult.stdio[1]);1736expectType<undefined>(noBufferStderrResult.stderr);1737expectType<undefined>(noBufferStderrResult.stdio[2]);1738expectType<string>(noBufferStderrResult.all);17391740const noBufferFd1Result = await execa('unicorns', {all: true, buffer: {fd1: false}});1741expectType<undefined>(noBufferFd1Result.stdout);1742expectType<undefined>(noBufferFd1Result.stdio[1]);1743expectType<string>(noBufferFd1Result.stderr);1744expectType<string>(noBufferFd1Result.stdio[2]);1745expectType<string>(noBufferFd1Result.all);17461747const noBufferFd2Result = await execa('unicorns', {all: true, buffer: {fd2: false}});1748expectType<string>(noBufferFd2Result.stdout);1749expectType<string>(noBufferFd2Result.stdio[1]);1750expectType<undefined>(noBufferFd2Result.stderr);1751expectType<undefined>(noBufferFd2Result.stdio[2]);1752expectType<string>(noBufferFd2Result.all);17531754const noBufferAllResult = await execa('unicorns', {all: true, buffer: {all: false}});1755expectType<undefined>(noBufferAllResult.stdout);1756expectType<undefined>(noBufferAllResult.stdio[1]);1757expectType<undefined>(noBufferAllResult.stderr);1758expectType<undefined>(noBufferAllResult.stdio[2]);1759expectType<undefined>(noBufferAllResult.all);17601761const noBufferFd3Result = await execa('unicorns', {all: true, buffer: {fd3: false}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1762expectType<string>(noBufferFd3Result.stdout);1763expectType<string>(noBufferFd3Result.stdio[1]);1764expectType<string>(noBufferFd3Result.stderr);1765expectType<string>(noBufferFd3Result.stdio[2]);1766expectType<string>(noBufferFd3Result.all);1767expectType<undefined>(noBufferFd3Result.stdio[3]);1768expectType<string>(noBufferFd3Result.stdio[4]);17691770const noBufferStdoutResultSync = execaSync('unicorns', {all: true, buffer: {stdout: false}});1771expectType<undefined>(noBufferStdoutResultSync.stdout);1772expectType<undefined>(noBufferStdoutResultSync.stdio[1]);1773expectType<string>(noBufferStdoutResultSync.stderr);1774expectType<string>(noBufferStdoutResultSync.stdio[2]);1775expectType<string>(noBufferStdoutResultSync.all);17761777const noBufferStderrResultSync = execaSync('unicorns', {all: true, buffer: {stderr: false}});1778expectType<string>(noBufferStderrResultSync.stdout);1779expectType<string>(noBufferStderrResultSync.stdio[1]);1780expectType<undefined>(noBufferStderrResultSync.stderr);1781expectType<undefined>(noBufferStderrResultSync.stdio[2]);1782expectType<string>(noBufferStderrResultSync.all);17831784const noBufferFd1ResultSync = execaSync('unicorns', {all: true, buffer: {fd1: false}});1785expectType<undefined>(noBufferFd1ResultSync.stdout);1786expectType<undefined>(noBufferFd1ResultSync.stdio[1]);1787expectType<string>(noBufferFd1ResultSync.stderr);1788expectType<string>(noBufferFd1ResultSync.stdio[2]);1789expectType<string>(noBufferFd1ResultSync.all);17901791const noBufferFd2ResultSync = execaSync('unicorns', {all: true, buffer: {fd2: false}});1792expectType<string>(noBufferFd2ResultSync.stdout);1793expectType<string>(noBufferFd2ResultSync.stdio[1]);1794expectType<undefined>(noBufferFd2ResultSync.stderr);1795expectType<undefined>(noBufferFd2ResultSync.stdio[2]);1796expectType<string>(noBufferFd2ResultSync.all);17971798const noBufferAllResultSync = execaSync('unicorns', {all: true, buffer: {all: false}});1799expectType<undefined>(noBufferAllResultSync.stdout);1800expectType<undefined>(noBufferAllResultSync.stdio[1]);1801expectType<undefined>(noBufferAllResultSync.stderr);1802expectType<undefined>(noBufferAllResultSync.stdio[2]);1803expectType<undefined>(noBufferAllResultSync.all);18041805const noBufferFd3ResultSync = execaSync('unicorns', {all: true, buffer: {fd3: false}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1806expectType<string>(noBufferFd3ResultSync.stdout);1807expectType<string>(noBufferFd3ResultSync.stdio[1]);1808expectType<string>(noBufferFd3ResultSync.stderr);1809expectType<string>(noBufferFd3ResultSync.stdio[2]);1810expectType<string>(noBufferFd3ResultSync.all);1811expectType<undefined>(noBufferFd3ResultSync.stdio[3]);1812expectType<string>(noBufferFd3ResultSync.stdio[4]);18131814expectError(execa('unicorns', {stdio: []}));1815expectError(execaSync('unicorns', {stdio: []}));1816expectError(execa('unicorns', {stdio: ['pipe']}));1817expectError(execaSync('unicorns', {stdio: ['pipe']}));
2303 unmodified lines
modified:readme.md+3 added-1 removed
829 unmodified lines
830Type: `object`831832This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).833834Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`lines`](#optionslines), [`stripFinalNewline`](#optionsstripfinalnewline), [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.834Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`lines`](#optionslines), [`stripFinalNewline`](#optionsstripfinalnewline), [`buffer`](#optionsbuffer), [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.835836```js837await execa('./run.js', {verbose: 'full'}) // Same value for stdout and stderr838await execa('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values
112 unmodified lines
951On failure, the [`error.stdout`](#resultstdout), [`error.stderr`](#resultstderr), [`error.all`](#resultall) and [`error.stdio`](#resultstdio) properties are used instead.952953When `buffer` is `false`, the output can still be read using the [`subprocess.stdout`](#subprocessstdout), [`subprocess.stderr`](#subprocessstderr), [`subprocess.stdio`](#subprocessstdio) and [`subprocess.all`](#subprocessall) streams. If the output is read, this should be done right away to avoid missing any data.954955By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).956957#### options.input958959Type: `string | Uint8Array | stream.Readable`960
385 unmodified lines