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
Provenance
- Commit
a25a50d- Tree
e665f9c- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
c474b30
14 files changed+244 added−71 removed
modified:lib/arguments/options.js+1 added-6 removed
32 unmodified lines3334353637383839404139404142434445464751484950518 unmodified lines60616263686465666720 unmodified lines32 unmodified lines validateEncoding(options); options.shell = normalizeFileUrl(options.shell); options.env = getEnv(options); options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay); options.lines = options.lines.map((lines, fdNumber) => lines && !BINARY_ENCODINGS.has(options.encoding) && options.buffer[fdNumber]);
if (BINARY_ENCODINGS.has(options.encoding) || !options.buffer) { options.lines.fill(false); }
if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') { // #116 args.unshift('/q'); }
return {file, args, options};};
const addDefaultOptions = ({ buffer = true, extendEnv = true, preferLocal = false, cwd, localDir = cwd,8 unmodified lines serialization = 'advanced', ...options}) => ({ ...options, buffer, extendEnv, preferLocal, cwd, localDir,20 unmodified linesmodified:lib/arguments/specific.js+2 added-1 removed
72 unmodified lines73747576777879808182828372 unmodified lines : optionValue);
const DEFAULT_OPTIONS = { lines: false, buffer: true, maxBuffer: 1000 * 1000 * 100, verbose: verboseDefault, stripFinalNewline: true,};
export const FD_SPECIFIC_OPTIONS = ['lines', 'maxBuffer', 'verbose', 'stripFinalNewline'];export const FD_SPECIFIC_OPTIONS = ['lines', 'buffer', 'maxBuffer', 'verbose', 'stripFinalNewline'];modified:lib/stdio/option.js+7 added-3 removed
39 unmodified lines40 41 return stdioOption;42 };43 44-const normalizeStdioSync = (stdioArray, buffer, verbose) => buffer45- ? stdioArray46- : stdioArray.map((stdioOption, fdNumber) => fdNumber !== 0 && verbose[fdNumber] !== 'full' && isOutputPipeOnly(stdioOption) ? 'ignore' : stdioOption);44+const normalizeStdioSync = (stdioArray, buffer, verbose) => stdioArray.map((stdioOption, fdNumber) =>45+ !buffer[fdNumber]46+ && fdNumber !== 047+ && verbose[fdNumber] !== 'full'48+ && isOutputPipeOnly(stdioOption)49+ ? 'ignore'50+ : stdioOption);51 52 const isOutputPipeOnly = stdioOption => stdioOption === 'pipe'53 || (Array.isArray(stdioOption) && stdioOption.every(item => item === 'pipe'));54 3 unmodified linesmodified:lib/stdio/output-sync.js+1 added-1 removed
37 unmodified lines38 const linesArray = splitLinesSync(serializedResult, false, objectMode);39 logLinesSync(linesArray, verboseInfo);40 }41 42- const returnedResult = buffer ? finalResult : undefined;42+ const returnedResult = buffer[fdNumber] ? finalResult : undefined;43 44 try {45 if (state.error === undefined) {46 writeToFiles(serializedResult, stdioItems);76 unmodified linesmodified:lib/stream/all.js+18 added-2 removed
6 unmodified lines7 : undefined;8 9 // Read the contents of `subprocess.all` and|or wait for its completion10 export 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 line19 verboseInfo,20 streamInfo,21 });22 23+const getAllStream = ({stdout, stderr, all}, [, bufferStdout, bufferStderr]) => {24+ const buffer = bufferStdout || bufferStderr;25+ if (!buffer) {26+ return {stream: all, buffer};27+ }28+29+ if (!bufferStdout) {30+ return {stream: stderr, buffer};31+ }32+33+ if (!bufferStderr) {34+ return {stream: stdout, buffer};35+ }36+37+ return {stream: all, buffer};38+};39+40 // 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 linesmodified:lib/stream/resolve.js+1 added-1 removed
54 unmodified lines55 };56 57 // Read the contents of `subprocess.std*` and|or wait for its completion58 const 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}));60 61 // Transforms replace `subprocess.std*`, which means they are not exposed to users.62 // However, we still want to wait for their completion.63 const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>23 unmodified linesmodified:test/stdio/file-path.js+6 added-4 removed
320 unmodified lines321 test('stderr can use "lines: true" together with output file URLs, sync', testOutputFileLines, 2, pathToFileURL, execaSync);322 test('stdio[*] can use "lines: true" together with output file paths, sync', testOutputFileLines, 3, getAbsolutePath, execaSync);323 test('stdio[*] can use "lines: true" together with output file URLs, sync', testOutputFileLines, 3, pathToFileURL, execaSync);324 325-const testOutputFileNoBuffer = async (t, execaMethod) => {325+const 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 };335 336-test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, execa);337-test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, execaSync);336+test('stdout can use "buffer: false" together with output file paths', testOutputFileNoBuffer, false, execa);337+test('stdout can use "buffer: false" together with output file paths, fd-specific', testOutputFileNoBuffer, {stdout: false}, execa);338+test('stdout can use "buffer: false" together with output file paths, sync', testOutputFileNoBuffer, false, execaSync);339+test('stdout can use "buffer: false" together with output file paths, fd-specific, sync', testOutputFileNoBuffer, {stdout: false}, execaSync);340 341 const testOutputFileObject = async (t, fdNumber, mapFile, execaMethod) => {342 const filePath = tempfile();343 t.throws(() => {53 unmodified linesmodified:test/stdio/lines.js+8 added-6 removed
145 unmodified lines146 test('"lines: true" is a noop with "encoding: hex", fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execaSync);147 test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execaSync);148 test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execaSync);149 150-const testLinesNoBuffer = async (t, lines, execaMethod) => {151- const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer: false});150+const testLinesNoBuffer = async (t, lines, buffer, execaMethod) => {151+ const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer});152 t.is(stdout, undefined);153 };154 155-test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, execa);156-test('"lines: true" is a noop with "buffer: false", fd-specific', testLinesNoBuffer, {stdout: true}, execa);157-test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, execaSync);158-test('"lines: true" is a noop with "buffer: false", fd-specific, sync', testLinesNoBuffer, {stdout: true}, execaSync);155+test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, false, execa);156+test('"lines: true" is a noop with "buffer: false", fd-specific buffer', testLinesNoBuffer, true, {stdout: false}, execa);157+test('"lines: true" is a noop with "buffer: false", fd-specific lines', testLinesNoBuffer, {stdout: true}, false, execa);158+test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, false, execaSync);159+test('"lines: true" is a noop with "buffer: false", fd-specific buffer, sync', testLinesNoBuffer, true, {stdout: false}, execaSync);160+test('"lines: true" is a noop with "buffer: false", fd-specific lines, sync', testLinesNoBuffer, {stdout: true}, false, execaSync);161 162 const maxBuffer = simpleLines.length - 1;163 164 const testBelowMaxBuffer = async (t, lines) => {111 unmodified linesmodified:test/stream/max-buffer.js+16 added-11 removed
208 unmodified lines209 test('maxBuffer ignores other encodings and stdout, sync', testMaxBufferHexSync, 1);210 test('maxBuffer ignores other encodings and stderr, sync', testMaxBufferHexSync, 2);211 test('maxBuffer ignores other encodings and stdio[*], sync', testMaxBufferHexSync, 3);212 213-const testNoMaxBuffer = async (t, fdNumber) => {214- const subprocess = getMaxBufferSubprocess(execa, fdNumber, {buffer: false});213+const 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 line220 t.is(stdio[fdNumber], undefined);221 t.is(output, getExpectedOutput(maxBuffer + 1));222 };223 224-test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1);225-test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2);226-test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3);224+test('do not buffer stdout when `buffer` set to `false`', testNoMaxBuffer, 1, false);225+test('do not buffer stdout when `buffer` set to `false`, fd-specific', testNoMaxBuffer, 1, {stdout: false});226+test('do not buffer stderr when `buffer` set to `false`', testNoMaxBuffer, 2, false);227+test('do not buffer stderr when `buffer` set to `false`, fd-specific', testNoMaxBuffer, 2, {stderr: false});228+test('do not buffer stdio[*] when `buffer` set to `false`', testNoMaxBuffer, 3, false);229+test('do not buffer stdio[*] when `buffer` set to `false`, fd-specific', testNoMaxBuffer, 3, {fd3: false});230 228-const testNoMaxBufferSync = (t, fdNumber) => {229- const {isMaxBuffer, stdio} = getMaxBufferSubprocess(execaSync, fdNumber, {buffer: false});231+const testNoMaxBufferSync = (t, fdNumber, buffer) => {232+ const {isMaxBuffer, stdio} = getMaxBufferSubprocess(execaSync, fdNumber, {buffer});233 t.false(isMaxBuffer);234 t.is(stdio[fdNumber], undefined);235 };236 234-// @todo: add a test for fd3 once the following Node.js bug is fixed.235-// https://github.com/nodejs/node/issues/52338236-test('do not buffer stdout when `buffer` set to `false`, sync', testNoMaxBufferSync, 1);237-test('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/52422239+test('do not buffer stdout when `buffer` set to `false`, sync', testNoMaxBufferSync, 1, false);240+test('do not buffer stdout when `buffer` set to `false`, fd-specific, sync', testNoMaxBufferSync, 1, {stdout: false});241+test('do not buffer stderr when `buffer` set to `false`, sync', testNoMaxBufferSync, 2, false);242+test('do not buffer stderr when `buffer` set to `false`, fd-specific, sync', testNoMaxBufferSync, 2, {stderr: false});243 244 const testMaxBufferAbort = async (t, fdNumber) => {245 const subprocess = getMaxBufferSubprocess(execa, fdNumber);246 const [{isMaxBuffer, shortMessage}] = await Promise.all([19 unmodified linesmodified:test/stream/no-buffer.js+46 added-16 removed
84 unmodified lines85 test('Listen to stderr errors even when `buffer` is `false`', testNoBufferStreamError, 2, false);86 test('Listen to stdio[*] errors even when `buffer` is `false`', testNoBufferStreamError, 3, false);87 test('Listen to all errors even when `buffer` is `false`', testNoBufferStreamError, 1, true);88 89-const testNoOutput = async (t, stdioOption, execaMethod) => {90- const {stdout} = await execaMethod('noop.js', {stdout: stdioOption, buffer: false});89+const testOutput = async (t, buffer, execaMethod) => {90+ const {stdout} = await execaMethod('noop-fd.js', ['1', foobarString], {buffer});91+ t.is(stdout, foobarString);92+};93+94+test('buffer: true returns output', testOutput, true, execa);95+test('buffer: true returns output, fd-specific', testOutput, {stderr: false}, execa);96+test('buffer: default returns output', testOutput, undefined, execa);97+test('buffer: default returns output, fd-specific', testOutput, {}, execa);98+99+const testNoOutput = async (t, stdioOption, buffer, execaMethod) => {100+ const {stdout} = await execaMethod('noop.js', {stdout: stdioOption, buffer});101 t.is(stdout, undefined);102 };103 94-test('buffer: false does not return output', testNoOutput, 'pipe', execa);95-test('buffer: false does not return output, stdout undefined', testNoOutput, undefined, execa);96-test('buffer: false does not return output, stdout null', testNoOutput, null, execa);97-test('buffer: false does not return output, stdout ["pipe"]', testNoOutput, ['pipe'], execa);98-test('buffer: false does not return output, stdout [undefined]', testNoOutput, [undefined], execa);99-test('buffer: false does not return output, stdout [null]', testNoOutput, [null], execa);100-test('buffer: false does not return output, stdout ["pipe", undefined]', testNoOutput, ['pipe', undefined], execa);101-test('buffer: false does not return output, sync', testNoOutput, 'pipe', execaSync);102-test('buffer: false does not return output, stdout undefined, sync', testNoOutput, undefined, execaSync);103-test('buffer: false does not return output, stdout null, sync', testNoOutput, null, execaSync);104-test('buffer: false does not return output, stdout ["pipe"], sync', testNoOutput, ['pipe'], execaSync);105-test('buffer: false does not return output, stdout [undefined], sync', testNoOutput, [undefined], execaSync);106-test('buffer: false does not return output, stdout [null], sync', testNoOutput, [null], execaSync);107-test('buffer: false does not return output, stdout ["pipe", undefined], sync', testNoOutput, ['pipe', undefined], execaSync);104+test('buffer: false does not return output', testNoOutput, 'pipe', false, execa);105+test('buffer: false does not return output, fd-specific', testNoOutput, 'pipe', {stdout: false}, execa);106+test('buffer: false does not return output, stdout undefined', testNoOutput, undefined, false, execa);107+test('buffer: false does not return output, stdout null', testNoOutput, null, false, execa);108+test('buffer: false does not return output, stdout ["pipe"]', testNoOutput, ['pipe'], false, execa);109+test('buffer: false does not return output, stdout [undefined]', testNoOutput, [undefined], false, execa);110+test('buffer: false does not return output, stdout [null]', testNoOutput, [null], false, execa);111+test('buffer: false does not return output, stdout ["pipe", undefined]', testNoOutput, ['pipe', undefined], false, execa);112+test('buffer: false does not return output, sync', testNoOutput, 'pipe', false, execaSync);113+test('buffer: false does not return output, fd-specific, sync', testNoOutput, 'pipe', {stdout: false}, execaSync);114+test('buffer: false does not return output, stdout undefined, sync', testNoOutput, undefined, false, execaSync);115+test('buffer: false does not return output, stdout null, sync', testNoOutput, null, false, execaSync);116+test('buffer: false does not return output, stdout ["pipe"], sync', testNoOutput, ['pipe'], false, execaSync);117+test('buffer: false does not return output, stdout [undefined], sync', testNoOutput, [undefined], false, execaSync);118+test('buffer: false does not return output, stdout [null], sync', testNoOutput, [null], false, execaSync);119+test('buffer: false does not return output, stdout ["pipe", undefined], sync', testNoOutput, ['pipe', undefined], false, execaSync);120 121 const testNoOutputFail = async (t, execaMethod) => {122 const {exitCode, stdout} = await execaMethod('fail.js', {buffer: false, reject: false});123 t.is(exitCode, 2);2 unmodified lines126 127 test('buffer: false does not return output, failure', testNoOutputFail, execa);128 test('buffer: false does not return output, failure, sync', testNoOutputFail, execaSync);129 130+// eslint-disable-next-line max-params131+const 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+};138+139+test('buffer: {}, all: true', testNoOutputAll, {}, true, true, execa);140+test('buffer: {stdout: false}, all: true', testNoOutputAll, {stdout: false}, false, true, execa);141+test('buffer: {stderr: false}, all: true', testNoOutputAll, {stderr: false}, true, false, execa);142+test('buffer: {all: false}, all: true', testNoOutputAll, {all: false}, false, false, execa);143+test('buffer: {}, all: true, sync', testNoOutputAll, {}, true, true, execaSync);144+test('buffer: {stdout: false}, all: true, sync', testNoOutputAll, {stdout: false}, false, true, execaSync);145+test('buffer: {stderr: false}, all: true, sync', testNoOutputAll, {stderr: false}, true, false, execaSync);146+test('buffer: {all: false}, all: true, sync', testNoOutputAll, {all: false}, false, false, execaSync);147+148 const testTransform = async (t, objectMode, execaMethod) => {149 const lines = [];150 const {stdout} = await execaMethod('noop.js', {151 buffer: false,41 unmodified linesmodified:test/verbose/output.js+20 added-14 removed
312 unmodified lines313 test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);314 test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);315 test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);316 317-const testPrintOutputNoBuffer = async (t, verbose, execaMethod) => {318- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer: false});317+const 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 };321 322-test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', parentExecaAsync);323-test('Prints stdout, buffer: false, fd-specific', testPrintOutputNoBuffer, fdFullOption, parentExecaAsync);324-test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', parentExecaSync);325-test('Prints stdout, buffer: false, fd-specific, sync', testPrintOutputNoBuffer, fdFullOption, parentExecaSync);322+test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', false, parentExecaAsync);323+test('Prints stdout, buffer: false, fd-specific buffer', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaAsync);324+test('Prints stdout, buffer: false, fd-specific verbose', testPrintOutputNoBuffer, fdFullOption, false, parentExecaAsync);325+test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', false, parentExecaSync);326+test('Prints stdout, buffer: false, fd-specific buffer, sync', testPrintOutputNoBuffer, 'full', {stdout: false}, parentExecaSync);327+test('Prints stdout, buffer: false, fd-specific verbose, sync', testPrintOutputNoBuffer, fdFullOption, false, parentExecaSync);328 327-const testPrintOutputNoBufferFalse = async (t, execaMethod) => {328- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer: false});329+const testPrintOutputNoBufferFalse = async (t, buffer, execaMethod) => {330+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer});331 t.is(getOutputLine(stderr), undefined);332 };333 332-test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, parentExecaAsync);333-test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, parentExecaSync);334+test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, false, parentExecaAsync);335+test('Does not print stdout, buffer: false, different fd, fd-specific buffer', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaAsync);336+test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, false, parentExecaSync);337+test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaSync);338 335-const testPrintOutputNoBufferTransform = async (t, isSync) => {336- const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer: false, type: 'generator', isSync});339+const 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 };343 340-test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false);341-test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, true);344+test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false, false);345+test('Prints stdout, buffer: false, transform, fd-specific buffer', testPrintOutputNoBufferTransform, {stdout: false}, false);346+test('Prints stdout, buffer: false, transform, sync', testPrintOutputNoBufferTransform, false, true);347+test('Prints stdout, buffer: false, transform, fd-specific buffer, sync', testPrintOutputNoBufferTransform, {stdout: false}, true);348 349 const 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 linesmodified:index.d.ts+7 added-5 removed
245 unmodified lines246 // Whether `result.stdout|stderr|all` is `undefined`247 type 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>;255 256-type LacksBuffer<BufferOption extends CommonOptions['buffer']> = BufferOption extends false ? true : false;256+type LacksBuffer<BufferOption extends boolean | undefined> = BufferOption extends false ? true : false;257 258 // Whether `result.stdio[FdNumber]` is an input stream259 type IsInputStdioDescriptor<260 FdNumber extends string,512 unmodified lines773 On failure, the `error.stdout`, `error.stderr`, `error.all` and `error.stdio` properties are used instead.774 775 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.776 777+ By default, this applies to both `stdout` and `stderr`, but different values can also be passed.778+779 @default true780 */779- readonly buffer?: boolean;781+ readonly buffer?: FdGenericOption<boolean>;782 783 /**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 lines841 842 /**843 Subprocess options.844 843-Some 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.845+Some 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.846 847 @example848 849 ```5 unmodified lines855 856 /**857 Subprocess options, with synchronous methods.858 857-Some 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.859+Some 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.860 861 @example862 863 ```1030 unmodified linesmodified:index.test-d.ts+108 added
1612 unmodified lines1613 execaSync('unicorns', {lines: {fd1: true}});1614 execaSync('unicorns', {lines: {fd2: true}});1615 execaSync('unicorns', {lines: {fd3: true}});1616 expectError(execaSync('unicorns', {lines: {stdout: 'true'}}));1617+execa('unicorns', {buffer: {}});1618+expectError(execa('unicorns', {buffer: []}));1619+execa('unicorns', {buffer: {stdout: true}});1620+execa('unicorns', {buffer: {stderr: true}});1621+execa('unicorns', {buffer: {stdout: true, stderr: true} as const});1622+execa('unicorns', {buffer: {all: true}});1623+execa('unicorns', {buffer: {fd1: true}});1624+execa('unicorns', {buffer: {fd2: true}});1625+execa('unicorns', {buffer: {fd3: true}});1626+expectError(execa('unicorns', {buffer: {stdout: 'true'}}));1627+execaSync('unicorns', {buffer: {}});1628+expectError(execaSync('unicorns', {buffer: []}));1629+execaSync('unicorns', {buffer: {stdout: true}});1630+execaSync('unicorns', {buffer: {stderr: true}});1631+execaSync('unicorns', {buffer: {stdout: true, stderr: true} as const});1632+execaSync('unicorns', {buffer: {all: true}});1633+execaSync('unicorns', {buffer: {fd1: true}});1634+execaSync('unicorns', {buffer: {fd2: true}});1635+execaSync('unicorns', {buffer: {fd3: true}});1636+expectError(execaSync('unicorns', {buffer: {stdout: 'true'}}));1637 1638 const linesStdoutResult = await execa('unicorns', {all: true, lines: {stdout: true}});1639 expectType<string[]>(linesStdoutResult.stdout);1640 expectType<string[]>(linesStdoutResult.stdio[1]);81 unmodified lines1722 expectType<string>(linesFd3ResultSync.all);1723 expectType<string[]>(linesFd3ResultSync.stdio[3]);1724 expectType<string>(linesFd3ResultSync.stdio[4]);1725 1726+const noBufferStdoutResult = await execa('unicorns', {all: true, buffer: {stdout: false}});1727+expectType<undefined>(noBufferStdoutResult.stdout);1728+expectType<undefined>(noBufferStdoutResult.stdio[1]);1729+expectType<string>(noBufferStdoutResult.stderr);1730+expectType<string>(noBufferStdoutResult.stdio[2]);1731+expectType<string>(noBufferStdoutResult.all);1732+1733+const noBufferStderrResult = await execa('unicorns', {all: true, buffer: {stderr: false}});1734+expectType<string>(noBufferStderrResult.stdout);1735+expectType<string>(noBufferStderrResult.stdio[1]);1736+expectType<undefined>(noBufferStderrResult.stderr);1737+expectType<undefined>(noBufferStderrResult.stdio[2]);1738+expectType<string>(noBufferStderrResult.all);1739+1740+const noBufferFd1Result = await execa('unicorns', {all: true, buffer: {fd1: false}});1741+expectType<undefined>(noBufferFd1Result.stdout);1742+expectType<undefined>(noBufferFd1Result.stdio[1]);1743+expectType<string>(noBufferFd1Result.stderr);1744+expectType<string>(noBufferFd1Result.stdio[2]);1745+expectType<string>(noBufferFd1Result.all);1746+1747+const noBufferFd2Result = await execa('unicorns', {all: true, buffer: {fd2: false}});1748+expectType<string>(noBufferFd2Result.stdout);1749+expectType<string>(noBufferFd2Result.stdio[1]);1750+expectType<undefined>(noBufferFd2Result.stderr);1751+expectType<undefined>(noBufferFd2Result.stdio[2]);1752+expectType<string>(noBufferFd2Result.all);1753+1754+const noBufferAllResult = await execa('unicorns', {all: true, buffer: {all: false}});1755+expectType<undefined>(noBufferAllResult.stdout);1756+expectType<undefined>(noBufferAllResult.stdio[1]);1757+expectType<undefined>(noBufferAllResult.stderr);1758+expectType<undefined>(noBufferAllResult.stdio[2]);1759+expectType<undefined>(noBufferAllResult.all);1760+1761+const noBufferFd3Result = await execa('unicorns', {all: true, buffer: {fd3: false}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1762+expectType<string>(noBufferFd3Result.stdout);1763+expectType<string>(noBufferFd3Result.stdio[1]);1764+expectType<string>(noBufferFd3Result.stderr);1765+expectType<string>(noBufferFd3Result.stdio[2]);1766+expectType<string>(noBufferFd3Result.all);1767+expectType<undefined>(noBufferFd3Result.stdio[3]);1768+expectType<string>(noBufferFd3Result.stdio[4]);1769+1770+const noBufferStdoutResultSync = execaSync('unicorns', {all: true, buffer: {stdout: false}});1771+expectType<undefined>(noBufferStdoutResultSync.stdout);1772+expectType<undefined>(noBufferStdoutResultSync.stdio[1]);1773+expectType<string>(noBufferStdoutResultSync.stderr);1774+expectType<string>(noBufferStdoutResultSync.stdio[2]);1775+expectType<string>(noBufferStdoutResultSync.all);1776+1777+const noBufferStderrResultSync = execaSync('unicorns', {all: true, buffer: {stderr: false}});1778+expectType<string>(noBufferStderrResultSync.stdout);1779+expectType<string>(noBufferStderrResultSync.stdio[1]);1780+expectType<undefined>(noBufferStderrResultSync.stderr);1781+expectType<undefined>(noBufferStderrResultSync.stdio[2]);1782+expectType<string>(noBufferStderrResultSync.all);1783+1784+const noBufferFd1ResultSync = execaSync('unicorns', {all: true, buffer: {fd1: false}});1785+expectType<undefined>(noBufferFd1ResultSync.stdout);1786+expectType<undefined>(noBufferFd1ResultSync.stdio[1]);1787+expectType<string>(noBufferFd1ResultSync.stderr);1788+expectType<string>(noBufferFd1ResultSync.stdio[2]);1789+expectType<string>(noBufferFd1ResultSync.all);1790+1791+const noBufferFd2ResultSync = execaSync('unicorns', {all: true, buffer: {fd2: false}});1792+expectType<string>(noBufferFd2ResultSync.stdout);1793+expectType<string>(noBufferFd2ResultSync.stdio[1]);1794+expectType<undefined>(noBufferFd2ResultSync.stderr);1795+expectType<undefined>(noBufferFd2ResultSync.stdio[2]);1796+expectType<string>(noBufferFd2ResultSync.all);1797+1798+const noBufferAllResultSync = execaSync('unicorns', {all: true, buffer: {all: false}});1799+expectType<undefined>(noBufferAllResultSync.stdout);1800+expectType<undefined>(noBufferAllResultSync.stdio[1]);1801+expectType<undefined>(noBufferAllResultSync.stderr);1802+expectType<undefined>(noBufferAllResultSync.stdio[2]);1803+expectType<undefined>(noBufferAllResultSync.all);1804+1805+const noBufferFd3ResultSync = execaSync('unicorns', {all: true, buffer: {fd3: false}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1806+expectType<string>(noBufferFd3ResultSync.stdout);1807+expectType<string>(noBufferFd3ResultSync.stdio[1]);1808+expectType<string>(noBufferFd3ResultSync.stderr);1809+expectType<string>(noBufferFd3ResultSync.stdio[2]);1810+expectType<string>(noBufferFd3ResultSync.all);1811+expectType<undefined>(noBufferFd3ResultSync.stdio[3]);1812+expectType<string>(noBufferFd3ResultSync.stdio[4]);1813+1814 expectError(execa('unicorns', {stdio: []}));1815 expectError(execaSync('unicorns', {stdio: []}));1816 expectError(execa('unicorns', {stdio: ['pipe']}));1817 expectError(execaSync('unicorns', {stdio: ['pipe']}));2303 unmodified linesmodified:readme.md+3 added-1 removed
829 unmodified lines830 Type: `object`831 832 This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).833 834-Some 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.834+Some 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.835 836 ```js837 await execa('./run.js', {verbose: 'full'}) // Same value for stdout and stderr838 await execa('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values112 unmodified lines951 On failure, the [`error.stdout`](#resultstdout), [`error.stderr`](#resultstderr), [`error.all`](#resultall) and [`error.stdio`](#resultstdio) properties are used instead.952 953 When `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.954 955+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).956+957 #### options.input958 959 Type: `string | Uint8Array | stream.Readable`960 385 unmodified lines