Allow setting different `lines` values for `stdout`/`stderr` (#972)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 64d52db · Browse files · 11 files·+358 added−132 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+358 added−132 removed
- tests:+144 added−98 removed
- other:+214 added−34 removed
Provenance
- Commit
c474b30- Tree
b75ab2f- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
64d52db
11 files changed+358 added−132 removed
modified:lib/arguments/options.js+4 added-3 removed
32 unmodified lines333435363737383940414243444513 unmodified lines5960616260636465669 unmodified lines7677787978808182839 unmodified lines32 unmodified lines validateEncoding(options); options.shell = normalizeFileUrl(options.shell); options.env = getEnv(options); options.forceKillAfterDelay = normalizeForceKillAfterDelay(options.forceKillAfterDelay); options.lines &&= !BINARY_ENCODINGS.has(options.encoding) && options.buffer;
if (BINARY_ENCODINGS.has(options.encoding) || !options.buffer) { options.lines.fill(false); }
if (process.platform === 'win32' && basename(file, '.exe') === 'cmd') { // #116 args.unshift('/q'); }13 unmodified lines all = false, windowsHide = true, killSignal = 'SIGTERM', forceKillAfterDelay = true, lines = false, ipc = false, serialization = 'advanced', ...options}) => ({9 unmodified lines all, windowsHide, killSignal, forceKillAfterDelay, lines, ipc, serialization,});
9 unmodified linesmodified:lib/arguments/specific.js+2 added-1 removed
71 unmodified lines72737475767778798081818271 unmodified lines ? DEFAULT_OPTIONS[optionName] : optionValue);
const DEFAULT_OPTIONS = { lines: false, maxBuffer: 1000 * 1000 * 100, verbose: verboseDefault, stripFinalNewline: true,};
export const FD_SPECIFIC_OPTIONS = ['maxBuffer', 'verbose', 'stripFinalNewline'];export const FD_SPECIFIC_OPTIONS = ['lines', 'maxBuffer', 'verbose', 'stripFinalNewline'];modified:lib/stdio/output-sync.js+8 added-5 removed
1 import {writeFileSync} from 'node:fs';2 import {shouldLogOutput, logLinesSync} from '../verbose/output.js';3 import {getMaxBufferSync} from '../stream/max-buffer.js';4+import {stripNewline} from '../return/output.js';5 import {joinToString, joinToUint8Array, bufferToUint8Array, isUint8Array, concatUint8Arrays} from './uint-array.js';6 import {getGenerators, runGeneratorsSync} from './generator.js';7 import {splitLinesSync} from './split.js';8 import {FILE_TYPES} from './type.js';66 unmodified lines75 return {serializedResult: joinToUint8Array(chunks)};76 }77 78 const serializedResult = joinToString(chunks, encoding);78- if (lines) {79+ if (lines[fdNumber]) {80 return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline[fdNumber], objectMode)};81 }82 83 return {serializedResult};6 unmodified lines90 }91 }92 };93 93-export const getAllSync = ([, stdout, stderr], {all}) => {94- if (!all) {94+export const getAllSync = ([, stdout, stderr], options) => {95+ if (!options.all) {96 return;97 }98 99 if (stdout === undefined) {4 unmodified lines104 return stdout;105 }106 107 if (Array.isArray(stdout)) {107- return Array.isArray(stderr) ? [...stdout, ...stderr] : [...stdout, stderr];108+ return Array.isArray(stderr)109+ ? [...stdout, ...stderr]110+ : [...stdout, stripNewline(stderr, options, true, 2)];111 }112 113 if (Array.isArray(stderr)) {111- return [stdout, ...stderr];114+ return [stripNewline(stdout, options, true, 1), ...stderr];115 }116 117 if (isUint8Array(stdout) && isUint8Array(stderr)) {118 return concatUint8Arrays([stdout, stderr]);4 unmodified linesmodified:lib/stream/all.js+1 added-1 removed
11 unmodified lines12 fdNumber: 1,13 encoding,14 buffer,15 maxBuffer: maxBuffer[1] + maxBuffer[2],16- lines,16+ lines: lines[1] || lines[2],17 isAll: true,18 allMixed: getAllMixed(subprocess),19 stripFinalNewline,20 verboseInfo,11 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, isAll: false, allMixed: false, 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}));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/lines.js+94 added-66 removed
23 unmodified lines24 const getSimpleChunkSubprocessAsync = options => getSimpleChunkSubprocess(execa, options);25 const getSimpleChunkSubprocess = (execaMethod, options) => execaMethod('noop-fd.js', ['1', simpleFull], {lines: true, ...options});26 27 // eslint-disable-next-line max-params28-const testStreamLines = async (t, fdNumber, input, expectedOutput, stripFinalNewline, execaMethod) => {29- const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {30- ...fullStdio,31- lines: true,32- stripFinalNewline,33- });28+const testStreamLines = async (t, fdNumber, input, expectedOutput, lines, stripFinalNewline, execaMethod) => {29+ const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {...fullStdio, lines, stripFinalNewline});30 t.deepEqual(stdio[fdNumber], expectedOutput);31 };32 37-test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleFull, simpleLines, false, execa);38-test('"lines: true" splits lines, stderr, string', testStreamLines, 2, simpleFull, simpleLines, false, execa);39-test('"lines: true" splits lines, stdio[*], string', testStreamLines, 3, simpleFull, simpleLines, false, execa);40-test('"lines: true" splits lines, stdout, string, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execa);41-test('"lines: true" splits lines, stdout, string, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, {stdout: true}, execa);42-test('"lines: true" splits lines, stderr, string, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execa);43-test('"lines: true" splits lines, stderr, string, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, {stderr: true}, execa);44-test('"lines: true" splits lines, stdio[*], string, stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execa);45-test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, {fd3: true}, execa);46-test('"lines: true" splits lines, stdout, string, sync', testStreamLines, 1, simpleFull, simpleLines, false, execaSync);47-test('"lines: true" splits lines, stderr, string, sync', testStreamLines, 2, simpleFull, simpleLines, false, execaSync);48-test('"lines: true" splits lines, stdio[*], string, sync', testStreamLines, 3, simpleFull, simpleLines, false, execaSync);49-test('"lines: true" splits lines, stdout, string, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execaSync);50-test('"lines: true" splits lines, stdout, string, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, {stdout: true}, execaSync);51-test('"lines: true" splits lines, stderr, string, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execaSync);52-test('"lines: true" splits lines, stderr, string, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, {stderr: true}, execaSync);53-test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execaSync);54-test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, {fd3: true}, execaSync);33+test('"lines: true" splits lines, stdout', testStreamLines, 1, simpleFull, simpleLines, true, false, execa);34+test('"lines: true" splits lines, stdout, fd-specific', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execa);35+test('"lines: true" splits lines, stderr', testStreamLines, 2, simpleFull, simpleLines, true, false, execa);36+test('"lines: true" splits lines, stderr, fd-specific', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execa);37+test('"lines: true" splits lines, stdio[*]', testStreamLines, 3, simpleFull, simpleLines, true, false, execa);38+test('"lines: true" splits lines, stdio[*], fd-specific', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execa);39+test('"lines: true" splits lines, stdout, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execa);40+test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execa);41+test('"lines: true" splits lines, stderr, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execa);42+test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execa);43+test('"lines: true" splits lines, stdio[*], stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execa);44+test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execa);45+test('"lines: true" splits lines, stdout, sync', testStreamLines, 1, simpleFull, simpleLines, true, false, execaSync);46+test('"lines: true" splits lines, stdout, fd-specific, sync', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execaSync);47+test('"lines: true" splits lines, stderr, sync', testStreamLines, 2, simpleFull, simpleLines, true, false, execaSync);48+test('"lines: true" splits lines, stderr, fd-specific, sync', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execaSync);49+test('"lines: true" splits lines, stdio[*], sync', testStreamLines, 3, simpleFull, simpleLines, true, false, execaSync);50+test('"lines: true" splits lines, stdio[*], fd-specific, sync', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execaSync);51+test('"lines: true" splits lines, stdout, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execaSync);52+test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execaSync);53+test('"lines: true" splits lines, stderr, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execaSync);54+test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execaSync);55+test('"lines: true" splits lines, stdio[*], stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execaSync);56+test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execaSync);57 58 const testStreamLinesNoop = async (t, lines, execaMethod) => {59 const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});60 t.is(stdout, simpleFull);61 };62 61-test('"lines: false" is a noop with execa()', testStreamLinesNoop, false, execa);62-test('"lines: false" is a noop with execaSync()', testStreamLinesNoop, false, execaSync);63+test('"lines: false" is a noop', testStreamLinesNoop, false, execa);64+test('"lines: false" is a noop, fd-specific', testStreamLinesNoop, {stderr: true}, execa);65+test('"lines: false" is a noop, fd-specific none', testStreamLinesNoop, {}, execa);66+test('"lines: false" is a noop, sync', testStreamLinesNoop, false, execaSync);67+test('"lines: false" is a noop, fd-specific, sync', testStreamLinesNoop, {stderr: true}, execaSync);68+test('"lines: false" is a noop, fd-specific none, sync', testStreamLinesNoop, {}, execaSync);69 70 const bigArray = Array.from({length: 1e5}).fill('.\n');71 const bigString = bigArray.join('');72 const bigStringNoNewlines = '.'.repeat(1e6);29 unmodified lines102 test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execaSync);103 test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execaSync);104 test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync);105 100-const testLinesObjectMode = async (t, execaMethod) => {106+const testLinesObjectMode = async (t, lines, execaMethod) => {107 const {stdout} = await execaMethod('noop.js', {108 stdout: getOutputsGenerator([foobarObject])(true),103- lines: true,109+ lines,110 });111 t.deepEqual(stdout, [foobarObject]);112 };113 108-test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, execa);109-test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, execaSync);114+test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, true, execa);115+test('"lines: true" is a noop with objects generators, fd-specific, objectMode', testLinesObjectMode, {stdout: true}, execa);116+test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, true, execaSync);117+test('"lines: true" is a noop with objects generators, fd-specific, objectMode, sync', testLinesObjectMode, {stdout: true}, execaSync);118 119 // eslint-disable-next-line max-params112-const testEncoding = async (t, input, expectedOutput, encoding, stripFinalNewline, execaMethod) => {113- const {stdout} = await execaMethod('stdin.js', {lines: true, stripFinalNewline, encoding, input});120+const testEncoding = async (t, input, expectedOutput, encoding, lines, stripFinalNewline, execaMethod) => {121+ const {stdout} = await execaMethod('stdin.js', {lines, stripFinalNewline, encoding, input});122 t.deepEqual(stdout, expectedOutput);123 };124 117-test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execa);118-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execa);119-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', {stdout: true}, execa);120-test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);121-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);122-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: false}, execa);123-test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', false, execa);124-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, execa);125-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, execa);126-test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execaSync);127-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execaSync);128-test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', {stdout: true}, execaSync);129-test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);130-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);131-test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: false}, execaSync);132-test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', false, execaSync);133-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, execaSync);134-test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, execaSync);125+test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execa);126+test('"lines: true" is a noop with "encoding: utf16", fd-specific', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execa);127+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execa);128+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execa);129+test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);130+test('"lines: true" is a noop with "encoding: buffer", fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execa);131+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);132+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execa);133+test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execa);134+test('"lines: true" is a noop with "encoding: hex", fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execa);135+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execa);136+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execa);137+test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execaSync);138+test('"lines: true" is a noop with "encoding: utf16", fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execaSync);139+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execaSync);140+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execaSync);141+test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);142+test('"lines: true" is a noop with "encoding: buffer", fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execaSync);143+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);144+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execaSync);145+test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execaSync);146+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 136-const testLinesNoBuffer = async (t, execaMethod) => {137- const {stdout} = await getSimpleChunkSubprocess(execaMethod, {buffer: false});150+const testLinesNoBuffer = async (t, lines, execaMethod) => {151+ const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer: false});152 t.is(stdout, undefined);153 };154 141-test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, execa);142-test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, execaSync);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);159 160 const maxBuffer = simpleLines.length - 1;161 146-test('"lines: true" can be below "maxBuffer"', async t => {147- const {isMaxBuffer, stdout} = await getSimpleChunkSubprocessAsync({maxBuffer: maxBuffer + 1});162+const testBelowMaxBuffer = async (t, lines) => {163+ const {isMaxBuffer, stdout} = await getSimpleChunkSubprocessAsync({lines, maxBuffer: maxBuffer + 1});164 t.false(isMaxBuffer);165 t.deepEqual(stdout, noNewlinesChunks);150-});166+};167 152-test('"lines: true" can be above "maxBuffer"', async t => {153- const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(getSimpleChunkSubprocessAsync({maxBuffer}));168+test('"lines: true" can be below "maxBuffer"', testBelowMaxBuffer, true);169+test('"lines: true" can be below "maxBuffer", fd-specific', testBelowMaxBuffer, {stdout: true});170+171+const testAboveMaxBuffer = async (t, lines) => {172+ const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(getSimpleChunkSubprocessAsync({lines, maxBuffer}));173 t.true(isMaxBuffer);174 assertErrorMessage(t, shortMessage, {length: maxBuffer, unit: 'lines'});175 t.deepEqual(stdout, noNewlinesChunks.slice(0, maxBuffer));157-});176+};177 159-test('"maxBuffer" is measured in lines with "lines: true"', async t => {160- const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(execa('noop-repeat.js', ['1', '...\n'], {lines: true, maxBuffer}));178+test('"lines: true" can be above "maxBuffer"', testAboveMaxBuffer, true);179+test('"lines: true" can be above "maxBuffer", fd-specific', testAboveMaxBuffer, {stdout: true});180+181+const testMaxBufferUnit = async (t, lines) => {182+ const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(execa('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer}));183 t.true(isMaxBuffer);184 assertErrorMessage(t, shortMessage, {length: maxBuffer, unit: 'lines'});185 t.deepEqual(stdout, ['...', '...']);164-});186+};187 166-test('"maxBuffer" is measured in bytes with "lines: true", sync', t => {188+test('"maxBuffer" is measured in lines with "lines: true"', testMaxBufferUnit, true);189+test('"maxBuffer" is measured in lines with "lines: true", fd-specific', testMaxBufferUnit, {stdout: true});190+191+const testMaxBufferUnitSync = (t, lines) => {192 const {isMaxBuffer, shortMessage, stdout} = t.throws(() => {168- execaSync('noop-repeat.js', ['1', '...\n'], {lines: true, maxBuffer});193+ execaSync('noop-repeat.js', ['1', '...\n'], {lines, maxBuffer});194 }, {code: 'ENOBUFS'});195 t.true(isMaxBuffer);196 assertErrorMessage(t, shortMessage, {execaMethod: execaSync, length: maxBuffer});197 t.deepEqual(stdout, ['..']);173-});198+};199 200+test('"maxBuffer" is measured in bytes with "lines: true", sync', testMaxBufferUnitSync, true);201+test('"maxBuffer" is measured in bytes with "lines: true", fd-specific, sync', testMaxBufferUnitSync, {stdout: true});202+203 test('"lines: true" stops on stream error', async t => {204 const cause = new Error(foobarString);205 const error = await t.throwsAsync(getSimpleChunkSubprocessAsync({206 * stdout(line) {67 unmodified linesmodified:test/stream/all.js+42 added-26 removed
21 unmodified lines22 t.is(exitCode, isFailure ? 1 : 0);23 t.deepEqual(all, expectedOutput);24 };25 26-const stripOne = {stderr: true};27-const stripBoth = {stdout: true, stderr: true};26+const fdOne = {stderr: true};27+const fdBoth = {stdout: true, stderr: true};28 29 test('result.all is defined', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execa);30 test('result.all is defined, encoding "buffer"', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execa);31 test('result.all is defined, lines', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execa);32+test('result.all is defined, lines, fd-specific one', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, false, execa);33+test('result.all is defined, lines, fd-specific both', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, false, execa);34 test('result.all is defined, stripFinalNewline', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execa);33-test('result.all is defined, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, false, execa);34-test('result.all is defined, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, false, execa);35+test('result.all is defined, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, false, execa);36+test('result.all is defined, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, false, execa);37 test('result.all is defined, encoding "buffer", stripFinalNewline', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execa);36-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, false, execa);37-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, false, execa);38+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, false, execa);39+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, false, execa);40 test('result.all is defined, lines, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execa);41+test('result.all is defined, lines, fd-specific one, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, false, execa);42+test('result.all is defined, lines, fd-specific both, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, false, execa);39-test('result.all is defined, lines, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, false, execa);40-test('result.all is defined, lines, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, false, execa);43+test('result.all is defined, lines, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, false, execa);44+test('result.all is defined, lines, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, false, execa);45 test('result.all is defined, failure', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execa);46 test('result.all is defined, encoding "buffer", failure', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execa);47 test('result.all is defined, lines, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execa);48+test('result.all is defined, lines, fd-specific one, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, true, execa);49+test('result.all is defined, lines, fd-specific both, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, true, execa);50 test('result.all is defined, stripFinalNewline, failure', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execa);45-test('result.all is defined, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, true, execa);46-test('result.all is defined, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, true, execa);51+test('result.all is defined, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, true, execa);52+test('result.all is defined, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, true, execa);53 test('result.all is defined, encoding "buffer", stripFinalNewline, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execa);48-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, true, execa);49-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, true, execa);54+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, true, execa);55+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, true, execa);56 test('result.all is defined, lines, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execa);57+test('result.all is defined, lines, fd-specific one, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, true, execa);58+test('result.all is defined, lines, fd-specific both, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, true, execa);51-test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, true, execa);52-test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, true, execa);59+test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, true, execa);60+test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, true, execa);61 test('result.all is defined, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execaSync);62 test('result.all is defined, encoding "buffer", sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execaSync);63 test('result.all is defined, lines, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execaSync);64+test('result.all is defined, lines, fd-specific one, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, false, execaSync);65+test('result.all is defined, lines, fd-specific both, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, false, execaSync);66 test('result.all is defined, stripFinalNewline, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execaSync);57-test('result.all is defined, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, false, execaSync);58-test('result.all is defined, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, false, execaSync);67+test('result.all is defined, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, false, execaSync);68+test('result.all is defined, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, false, execaSync);69 test('result.all is defined, encoding "buffer", stripFinalNewline, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execaSync);60-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, false, execaSync);61-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, false, execaSync);70+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, false, execaSync);71+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, false, execaSync);72 test('result.all is defined, lines, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execaSync);73+test('result.all is defined, lines, fd-specific one, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, false, execaSync);74+test('result.all is defined, lines, fd-specific both, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, false, execaSync);63-test('result.all is defined, lines, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, false, execaSync);64-test('result.all is defined, lines, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, false, execaSync);75+test('result.all is defined, lines, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, false, execaSync);76+test('result.all is defined, lines, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, false, execaSync);77 test('result.all is defined, failure, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execaSync);78 test('result.all is defined, encoding "buffer", failure, sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execaSync);79 test('result.all is defined, lines, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execaSync);80+test('result.all is defined, lines, fd-specific one, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, true, execaSync);81+test('result.all is defined, lines, fd-specific both, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, true, execaSync);82 test('result.all is defined, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execaSync);69-test('result.all is defined, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, true, execaSync);70-test('result.all is defined, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, true, execaSync);83+test('result.all is defined, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, true, execaSync);84+test('result.all is defined, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, true, execaSync);85 test('result.all is defined, encoding "buffer", stripFinalNewline, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execaSync);72-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, true, execaSync);73-test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, true, execaSync);86+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, true, execaSync);87+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, true, execaSync);88 test('result.all is defined, lines, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execaSync);89+test('result.all is defined, lines, fd-specific one, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, true, execaSync);90+test('result.all is defined, lines, fd-specific both, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, true, execaSync);75-test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, true, execaSync);76-test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, true, execaSync);91+test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, true, execaSync);92+test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, true, execaSync);93 94 test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {95 const {all} = await execa('noop-132.js', {all: true});96 t.is(all, '1\n2\n3');75 unmodified linesmodified:test/verbose/output.js+8 added-6 removed
158 unmodified lines159 160 test('Does not change subprocess.stdout', testStdioSame, 1);161 test('Does not change subprocess.stderr', testStdioSame, 2);162 163-const testLines = async (t, stripFinalNewline, execaMethod) => {164- const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines: true, stripFinalNewline});163+const testLines = async (t, lines, stripFinalNewline, execaMethod) => {164+ const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines, stripFinalNewline});165 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));166 };167 168-test('Prints stdout, "lines: true"', testLines, false, parentExecaAsync);169-test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, parentExecaAsync);170-test('Prints stdout, "lines: true", sync', testLines, false, parentExecaSync);171-test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, parentExecaSync);168+test('Prints stdout, "lines: true"', testLines, true, false, parentExecaAsync);169+test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, parentExecaAsync);170+test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, parentExecaAsync);171+test('Prints stdout, "lines: true", sync', testLines, true, false, parentExecaSync);172+test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, parentExecaSync);173+test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, parentExecaSync);174 175 const testOnlyTransforms = async (t, type, isSync) => {176 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', type, isSync});177 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);180 unmodified linesmodified:index.d.ts+85 added-20 removed
303 unmodified lines304 : undefined305 : undefined;306 307 // Type of `result.stdout|stderr`308-type StdioOutput<308+type NonAllStdioOutput<309 FdNumber extends string,310 OptionsType extends CommonOptions = CommonOptions,311-> = StdioOutputResult<FdNumber, IgnoresStreamOutput<FdNumber, OptionsType>, OptionsType>;311+> = StdioOutput<FdNumber, FdNumber, FdNumber, OptionsType>;312 313+type StdioOutput<314+ MainFdNumber extends string,315+ ObjectFdNumber extends string,316+ LinesFdNumber extends string,317+ OptionsType extends CommonOptions = CommonOptions,318+> = StdioOutputResult<319+ObjectFdNumber,320+LinesFdNumber,321+IgnoresStreamOutput<MainFdNumber, OptionsType>,322+OptionsType323+>;324+325 type StdioOutputResult<314- FdNumber extends string,326+ ObjectFdNumber extends string,327+ LinesFdNumber extends string,328 StreamOutputIgnored extends boolean,329 OptionsType extends CommonOptions = CommonOptions,330 > = StreamOutputIgnored extends true331 ? undefined319- : StreamEncoding<IsObjectStream<FdNumber, OptionsType>, OptionsType['lines'], OptionsType['encoding']>;332+ : StreamEncoding<333+ IsObjectStream<ObjectFdNumber, OptionsType>,334+ FdSpecificOption<OptionsType['lines'], LinesFdNumber>,335+ OptionsType['encoding']336+ >;337 338 type StreamEncoding<339 IsObjectResult extends boolean,323- LinesOption extends CommonOptions['lines'],340+ LinesOption extends boolean | undefined,341 Encoding extends CommonOptions['encoding'],342 > = IsObjectResult extends true ? unknown[]343 : Encoding extends BufferEncodingOption344 ? Uint8Array9 unmodified lines354 type AllOutputProperty<355 AllOption extends CommonOptions['all'] = CommonOptions['all'],356 OptionsType extends CommonOptions = CommonOptions,357 > = AllOption extends true341- ? StdioOutput<AllUsesStdout<OptionsType> extends true ? '1' : '2', OptionsType>358+ ? StdioOutput<359+ AllMainFd<OptionsType>,360+ AllObjectFd<OptionsType>,361+ AllLinesFd<OptionsType>,362+ OptionsType363+ >364 : undefined;365 344-type AllUsesStdout<OptionsType extends CommonOptions = CommonOptions> = IgnoresStreamOutput<'1', OptionsType> extends true345- ? false346- : IgnoresStreamOutput<'2', OptionsType> extends true347- ? true348- : IsObjectStream<'2', OptionsType> extends true349- ? false350- : IsObjectStream<'1', OptionsType>;366+type AllMainFd<OptionsType extends CommonOptions = CommonOptions> = IgnoresStreamOutput<'1', OptionsType> extends true ? '2' : '1';367 368+type AllObjectFd<OptionsType extends CommonOptions = CommonOptions> = IsObjectStream<'1', OptionsType> extends true ? '1' : '2';369+370+type AllLinesFd<OptionsType extends CommonOptions = CommonOptions> = FdSpecificOption<OptionsType['lines'], '1'> extends true ? '1' : '2';371+372 // Type of `result.stdio`373 type StdioArrayOutput<OptionsType extends CommonOptions = CommonOptions> = MapStdioOptions<StdioArrayOption<OptionsType>, OptionsType>;374 375 type MapStdioOptions<376 StdioOptionsArrayType extends StdioOptionsArray,377 OptionsType extends CommonOptions = CommonOptions,378 > = {359- -readonly [FdNumber in keyof StdioOptionsArrayType]: StdioOutput<379+ -readonly [FdNumber in keyof StdioOptionsArrayType]: NonAllStdioOutput<380 FdNumber extends string ? FdNumber : string,381 OptionsType382 >383 };15 unmodified lines399 WideOptions extends CommonOptions,400 StrictOptions extends CommonOptions,401 > = WideOptions extends StrictOptions ? WideOptions : StrictOptions;402 383-type FdGenericOption<OptionType> = OptionType | {403+// Options which can be fd-specific like `{verbose: {stdout: 'none', stderr: 'full'}}`404+type FdGenericOption<OptionType = unknown> = OptionType | GenericOptionObject<OptionType>;405+406+type GenericOptionObject<OptionType = unknown> = {407 readonly [FdName in FromOption]?: OptionType408 };409 410+// Retrieve fd-specific option's value411+type FdSpecificOption<412+ GenericOption extends FdGenericOption,413+ FdNumber extends string,414+> = GenericOption extends GenericOptionObject415+ ? FdSpecificObjectOption<GenericOption, FdNumber>416+ : GenericOption;417+418+type FdSpecificObjectOption<419+ GenericOption extends GenericOptionObject,420+ FdNumber extends string,421+> = keyof GenericOption extends FromOption422+ ? FdNumberToFromOption<FdNumber, keyof GenericOption> extends never423+ ? undefined424+ : GenericOption[FdNumberToFromOption<FdNumber, keyof GenericOption>]425+ : GenericOption;426+427+type FdNumberToFromOption<428+ FdNumber extends string,429+ FromOptions extends FromOption,430+> = FdNumber extends '1'431+ ? 'stdout' extends FromOptions432+ ? 'stdout'433+ : 'fd1' extends FromOptions434+ ? 'fd1'435+ : 'all' extends FromOptions436+ ? 'all'437+ : never438+ : FdNumber extends '2'439+ ? 'stderr' extends FromOptions440+ ? 'stderr'441+ : 'fd2' extends FromOptions442+ ? 'fd2'443+ : 'all' extends FromOptions444+ ? 'all'445+ : never446+ : `fd${FdNumber}` extends FromOptions447+ ? `fd${FdNumber}`448+ : never;449+450 type CommonOptions<IsSync extends boolean = boolean> = {451 /**452 Prefer locally installed binaries when looking for a binary to execute.453 128 unmodified lines582 Set `result.stdout`, `result.stderr`, `result.all` and `result.stdio` as arrays of strings, splitting the subprocess' output into lines.583 584 This cannot be used if the `encoding` option is binary.585 586+ By default, this applies to both `stdout` and `stderr`, but different values can also be passed.587+588 @default false589 */525- readonly lines?: boolean;590+ readonly lines?: FdGenericOption<boolean>;591 592 /**593 Setting this to `false` resolves the promise with the error instead of rejecting it.594 244 unmodified lines839 840 /**841 Subprocess options.842 778-Some options are related to the subprocess output: `verbose`, `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.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.844 845 @example846 847 ```5 unmodified lines853 854 /**855 Subprocess options, with synchronous methods.856 792-Some options are related to the subprocess output: `verbose`, `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.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.858 859 @example860 861 ```35 unmodified lines897 The output of the subprocess on `stdout`.898 899 This is `undefined` if the `stdout` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. This is an array if the `lines` option is `true`, or if the `stdout` option is a transform in object mode.900 */836- stdout: StdioOutput<'1', OptionsType>;901+ stdout: NonAllStdioOutput<'1', OptionsType>;902 903 /**904 The output of the subprocess on `stderr`.905 906 This is `undefined` if the `stderr` option is set to only `'inherit'`, `'ignore'`, `Writable` or `integer`. This is an array if the `lines` option is `true`, or if the `stderr` option is a transform in object mode.907 */843- stderr: StdioOutput<'2', OptionsType>;908+ stderr: NonAllStdioOutput<'2', OptionsType>;909 910 /**911 The output of the subprocess on `stdin`, `stdout`, `stderr` and other file descriptors.912 979 unmodified linesmodified:index.test-d.ts+108 added
1592 unmodified lines1593 execaSync('unicorns', {stripFinalNewline: {fd1: true}});1594 execaSync('unicorns', {stripFinalNewline: {fd2: true}});1595 execaSync('unicorns', {stripFinalNewline: {fd3: true}});1596 expectError(execaSync('unicorns', {stripFinalNewline: {stdout: 'true'}}));1597+execa('unicorns', {lines: {}});1598+expectError(execa('unicorns', {lines: []}));1599+execa('unicorns', {lines: {stdout: true}});1600+execa('unicorns', {lines: {stderr: true}});1601+execa('unicorns', {lines: {stdout: true, stderr: true} as const});1602+execa('unicorns', {lines: {all: true}});1603+execa('unicorns', {lines: {fd1: true}});1604+execa('unicorns', {lines: {fd2: true}});1605+execa('unicorns', {lines: {fd3: true}});1606+expectError(execa('unicorns', {lines: {stdout: 'true'}}));1607+execaSync('unicorns', {lines: {}});1608+expectError(execaSync('unicorns', {lines: []}));1609+execaSync('unicorns', {lines: {stdout: true}});1610+execaSync('unicorns', {lines: {stderr: true}});1611+execaSync('unicorns', {lines: {stdout: true, stderr: true} as const});1612+execaSync('unicorns', {lines: {all: true}});1613+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 1618+const linesStdoutResult = await execa('unicorns', {all: true, lines: {stdout: true}});1619+expectType<string[]>(linesStdoutResult.stdout);1620+expectType<string[]>(linesStdoutResult.stdio[1]);1621+expectType<string>(linesStdoutResult.stderr);1622+expectType<string>(linesStdoutResult.stdio[2]);1623+expectType<string[]>(linesStdoutResult.all);1624+1625+const linesStderrResult = await execa('unicorns', {all: true, lines: {stderr: true}});1626+expectType<string>(linesStderrResult.stdout);1627+expectType<string>(linesStderrResult.stdio[1]);1628+expectType<string[]>(linesStderrResult.stderr);1629+expectType<string[]>(linesStderrResult.stdio[2]);1630+expectType<string[]>(linesStderrResult.all);1631+1632+const linesFd1Result = await execa('unicorns', {all: true, lines: {fd1: true}});1633+expectType<string[]>(linesFd1Result.stdout);1634+expectType<string[]>(linesFd1Result.stdio[1]);1635+expectType<string>(linesFd1Result.stderr);1636+expectType<string>(linesFd1Result.stdio[2]);1637+expectType<string[]>(linesFd1Result.all);1638+1639+const linesFd2Result = await execa('unicorns', {all: true, lines: {fd2: true}});1640+expectType<string>(linesFd2Result.stdout);1641+expectType<string>(linesFd2Result.stdio[1]);1642+expectType<string[]>(linesFd2Result.stderr);1643+expectType<string[]>(linesFd2Result.stdio[2]);1644+expectType<string[]>(linesFd2Result.all);1645+1646+const linesAllResult = await execa('unicorns', {all: true, lines: {all: true}});1647+expectType<string[]>(linesAllResult.stdout);1648+expectType<string[]>(linesAllResult.stdio[1]);1649+expectType<string[]>(linesAllResult.stderr);1650+expectType<string[]>(linesAllResult.stdio[2]);1651+expectType<string[]>(linesAllResult.all);1652+1653+const linesFd3Result = await execa('unicorns', {all: true, lines: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1654+expectType<string>(linesFd3Result.stdout);1655+expectType<string>(linesFd3Result.stdio[1]);1656+expectType<string>(linesFd3Result.stderr);1657+expectType<string>(linesFd3Result.stdio[2]);1658+expectType<string>(linesFd3Result.all);1659+expectType<string[]>(linesFd3Result.stdio[3]);1660+expectType<string>(linesFd3Result.stdio[4]);1661+1662+const linesStdoutResultSync = execaSync('unicorns', {all: true, lines: {stdout: true}});1663+expectType<string[]>(linesStdoutResultSync.stdout);1664+expectType<string[]>(linesStdoutResultSync.stdio[1]);1665+expectType<string>(linesStdoutResultSync.stderr);1666+expectType<string>(linesStdoutResultSync.stdio[2]);1667+expectType<string[]>(linesStdoutResultSync.all);1668+1669+const linesStderrResultSync = execaSync('unicorns', {all: true, lines: {stderr: true}});1670+expectType<string>(linesStderrResultSync.stdout);1671+expectType<string>(linesStderrResultSync.stdio[1]);1672+expectType<string[]>(linesStderrResultSync.stderr);1673+expectType<string[]>(linesStderrResultSync.stdio[2]);1674+expectType<string[]>(linesStderrResultSync.all);1675+1676+const linesFd1ResultSync = execaSync('unicorns', {all: true, lines: {fd1: true}});1677+expectType<string[]>(linesFd1ResultSync.stdout);1678+expectType<string[]>(linesFd1ResultSync.stdio[1]);1679+expectType<string>(linesFd1ResultSync.stderr);1680+expectType<string>(linesFd1ResultSync.stdio[2]);1681+expectType<string[]>(linesFd1ResultSync.all);1682+1683+const linesFd2ResultSync = execaSync('unicorns', {all: true, lines: {fd2: true}});1684+expectType<string>(linesFd2ResultSync.stdout);1685+expectType<string>(linesFd2ResultSync.stdio[1]);1686+expectType<string[]>(linesFd2ResultSync.stderr);1687+expectType<string[]>(linesFd2ResultSync.stdio[2]);1688+expectType<string[]>(linesFd2ResultSync.all);1689+1690+const linesAllResultSync = execaSync('unicorns', {all: true, lines: {all: true}});1691+expectType<string[]>(linesAllResultSync.stdout);1692+expectType<string[]>(linesAllResultSync.stdio[1]);1693+expectType<string[]>(linesAllResultSync.stderr);1694+expectType<string[]>(linesAllResultSync.stdio[2]);1695+expectType<string[]>(linesAllResultSync.all);1696+1697+const linesFd3ResultSync = execaSync('unicorns', {all: true, lines: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1698+expectType<string>(linesFd3ResultSync.stdout);1699+expectType<string>(linesFd3ResultSync.stdio[1]);1700+expectType<string>(linesFd3ResultSync.stderr);1701+expectType<string>(linesFd3ResultSync.stdio[2]);1702+expectType<string>(linesFd3ResultSync.all);1703+expectType<string[]>(linesFd3ResultSync.stdio[3]);1704+expectType<string>(linesFd3ResultSync.stdio[4]);1705+1706 expectError(execa('unicorns', {stdio: []}));1707 expectError(execaSync('unicorns', {stdio: []}));1708 expectError(execa('unicorns', {stdio: ['pipe']}));1709 expectError(execaSync('unicorns', {stdio: ['pipe']}));2303 unmodified linesmodified:readme.md+5 added-3 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), [`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), [`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 values99 unmodified lines938 - the [`encoding`](#optionsencoding) option is binary.939 940 This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.941 942-By default, this applies to both `stdout` and `stderr`, but different values can also be passed.942+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).943 944 #### options.buffer945 946 Type: `boolean`\117 unmodified lines1064 Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.1065 1066 This cannot be used if the [`encoding`](#optionsencoding) option is binary.1067 1068+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).1069+1070 #### options.encoding1071 1072 Type: `string`\1073 Default: `'utf8'`14 unmodified lines1088 Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.1089 1090 If the [`lines`](#optionslines) option is true, this applies to each output line instead.1091 1090-By default, this applies to both `stdout` and `stderr`, but different values can also be passed.1092+By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).1093 1094 #### options.maxBuffer1095 1096 Type: `number`\247 unmodified lines