Line-wise standard streams (#741)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 17993a8 · Browse files · 10 files·+306 added−93 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+306 added−93 removed
- tests:+197 added−72 removed
- other:+109 added−21 removed
Provenance
- Commit
479d12e- Tree
af1a342- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
17993a8
10 files changed+306 added−93 removed
modified:docs/transform.md+2 added
54 unmodified lines5556575859606162636439 unmodified lines54 unmodified linesThis is more efficient and recommended if the data is either: - Binary: Which does not have lines. - Text: But the transform works even if a line or word is split across multiple chunks.
Please note the [`lines`](../readme.md#lines) option is unrelated: it has no impact on transforms.
## Object mode
By default, `stdout` and `stderr`'s transforms must return a string or an `Uint8Array`. However, if a `{transform, objectMode: true}` plain object is passed, any type can be returned instead, except `null`. The process' [`stdout`](../readme.md#stdout)/[`stderr`](../readme.md#stderr) will be an array of values.
39 unmodified linesmodified:lib/stdio/handle.js+2 added
123456789103 unmodified lines14151617181920212274 unmodified linesimport {getStdioOptionType, isRegularUrl, isUnknownStdioString} from './type.js';import {addStreamDirection} from './direction.js';import {normalizeStdio} from './normalize.js';import {handleNativeStream} from './native.js';import {handleInputOptions} from './input.js';import {handleStreamsLines} from './lines.js';import {handleStreamsEncoding} from './encoding.js';import {normalizeGenerators} from './generator.js';import {updateStdio} from './pipe.js';
3 unmodified lines const [stdinStreams, ...otherStreamsGroups] = stdio.map((stdioOption, index) => getStdioStreams(stdioOption, index)); const stdioStreamsGroups = [[...stdinStreams, ...handleInputOptions(options)], ...otherStreamsGroups] .map(stdioStreams => validateStreams(stdioStreams)) .map(stdioStreams => addStreamDirection(stdioStreams)) .map(stdioStreams => handleStreamsLines(stdioStreams, options, isSync)) .map(stdioStreams => handleStreamsEncoding(stdioStreams, options, isSync)) .map(stdioStreams => normalizeGenerators(stdioStreams)) .map(stdioStreams => addStreamsProperties(stdioStreams, addProperties)); options.stdio = updateStdio(stdioStreamsGroups);74 unmodified linesmodified:lib/stdio/lines.js+24 added-1 removed
1 import {isUint8Array} from './utils.js';2+import {willPipeStreams} from './pipe.js';3 3-// Split chunks line-wise4+// Split chunks line-wise for streams exposed to users like `childProcess.stdout`.5+// Appending a noop transform in object mode is enough to do this, since every non-binary transform iterates line-wise.6+export const handleStreamsLines = (stdioStreams, {lines}, isSync) => shouldSplitLines(stdioStreams, lines, isSync)7+ ? [8+ ...stdioStreams,9+ {10+ ...stdioStreams[0],11+ type: 'generator',12+ value: {transform: linesEndGenerator, objectMode: true},13+ },14+ ]15+ : stdioStreams;16+17+const shouldSplitLines = (stdioStreams, lines, isSync) => stdioStreams[0].direction === 'output'18+ && lines19+ && !isSync20+ && willPipeStreams(stdioStreams);21+22+const linesEndGenerator = async function * (chunks) {23+ yield * chunks;24+};25+26+// Split chunks line-wise for generators passed to the `std*` options27 export const getLinesGenerator = (encoding, binary) => {28 if (binary) {29 return;30 }70 unmodified linesmodified:test/helpers/generator.js+2 added-1 removed
37 unmodified lines38 });39 40 export const outputObjectGenerator = getOutputGenerator(foobarObject, true);41 42-export const getChunksGenerator = (chunks, objectMode) => ({42+export const getChunksGenerator = (chunks, objectMode, binary) => ({43 async * transform(lines) {44 // eslint-disable-next-line no-unused-vars45 for await (const line of lines) {46 for (const chunk of chunks) {3 unmodified lines50 }51 }52 },53 objectMode,54+ binary,55 });modified:test/stdio/encoding.js+40 added-19 removed
147 unmodified lines148 const {stdout} = await execa('noop.js', {stdout: outputObjectGenerator, encoding: 'base64'});149 t.deepEqual(stdout, [foobarObject]);150 });151 152-const testIgnoredEncoding = async (t, stdoutOption, isUndefined) => {153- const {stdout} = await execa('empty.js', {stdout: stdoutOption, encoding: 'base64'});152+const testIgnoredEncoding = async (t, stdoutOption, isUndefined, options) => {153+ const {stdout} = await execa('empty.js', {stdout: stdoutOption, ...options});154 t.is(stdout === undefined, isUndefined);155 };156 157+const base64Options = {encoding: 'base64'};158+const linesOptions = {lines: true};157-test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true);158-test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true);159-test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true);160-test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true);161-test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true);162-test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true);163-test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true);164-test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true);165-test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true);166-test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true);167-test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false);168-test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false);169-test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false);170-test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false);171-test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false);172-test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false);173-test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false);159+test('Is ignored with other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, base64Options);160+test('Is ignored with other encodings and ["ignore"]', testIgnoredEncoding, ['ignore'], true, base64Options);161+test('Is ignored with other encodings and "ipc"', testIgnoredEncoding, 'ipc', true, base64Options);162+test('Is ignored with other encodings and ["ipc"]', testIgnoredEncoding, ['ipc'], true, base64Options);163+test('Is ignored with other encodings and "inherit"', testIgnoredEncoding, 'inherit', true, base64Options);164+test('Is ignored with other encodings and ["inherit"]', testIgnoredEncoding, ['inherit'], true, base64Options);165+test('Is ignored with other encodings and 1', testIgnoredEncoding, 1, true, base64Options);166+test('Is ignored with other encodings and [1]', testIgnoredEncoding, [1], true, base64Options);167+test('Is ignored with other encodings and process.stdout', testIgnoredEncoding, process.stdout, true, base64Options);168+test('Is ignored with other encodings and [process.stdout]', testIgnoredEncoding, [process.stdout], true, base64Options);169+test('Is not ignored with other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, base64Options);170+test('Is not ignored with other encodings and ["pipe"]', testIgnoredEncoding, ['pipe'], false, base64Options);171+test('Is not ignored with other encodings and "overlapped"', testIgnoredEncoding, 'overlapped', false, base64Options);172+test('Is not ignored with other encodings and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, base64Options);173+test('Is not ignored with other encodings and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, base64Options);174+test('Is not ignored with other encodings and undefined', testIgnoredEncoding, undefined, false, base64Options);175+test('Is not ignored with other encodings and null', testIgnoredEncoding, null, false, base64Options);176+test('Is ignored with "lines: true" and "ignore"', testIgnoredEncoding, 'ignore', true, linesOptions);177+test('Is ignored with "lines: true" and ["ignore"]', testIgnoredEncoding, ['ignore'], true, linesOptions);178+test('Is ignored with "lines: true" and "ipc"', testIgnoredEncoding, 'ipc', true, linesOptions);179+test('Is ignored with "lines: true" and ["ipc"]', testIgnoredEncoding, ['ipc'], true, linesOptions);180+test('Is ignored with "lines: true" and "inherit"', testIgnoredEncoding, 'inherit', true, linesOptions);181+test('Is ignored with "lines: true" and ["inherit"]', testIgnoredEncoding, ['inherit'], true, linesOptions);182+test('Is ignored with "lines: true" and 1', testIgnoredEncoding, 1, true, linesOptions);183+test('Is ignored with "lines: true" and [1]', testIgnoredEncoding, [1], true, linesOptions);184+test('Is ignored with "lines: true" and process.stdout', testIgnoredEncoding, process.stdout, true, linesOptions);185+test('Is ignored with "lines: true" and [process.stdout]', testIgnoredEncoding, [process.stdout], true, linesOptions);186+test('Is not ignored with "lines: true" and "pipe"', testIgnoredEncoding, 'pipe', false, linesOptions);187+test('Is not ignored with "lines: true" and ["pipe"]', testIgnoredEncoding, ['pipe'], false, linesOptions);188+test('Is not ignored with "lines: true" and "overlapped"', testIgnoredEncoding, 'overlapped', false, linesOptions);189+test('Is not ignored with "lines: true" and ["overlapped"]', testIgnoredEncoding, ['overlapped'], false, linesOptions);190+test('Is not ignored with "lines: true" and ["inherit", "pipe"]', testIgnoredEncoding, ['inherit', 'pipe'], false, linesOptions);191+test('Is not ignored with "lines: true" and undefined', testIgnoredEncoding, undefined, false, linesOptions);192+test('Is not ignored with "lines: true" and null', testIgnoredEncoding, null, false, linesOptions);193+test('Is ignored with "lines: true", other encodings and "ignore"', testIgnoredEncoding, 'ignore', true, {...base64Options, ...linesOptions});194+test('Is not ignored with "lines: true", other encodings and "pipe"', testIgnoredEncoding, 'pipe', false, {...base64Options, ...linesOptions});modified:test/stdio/lines.js+155 added-52 removed
1+import {once} from 'node:events';2+import {Writable} from 'node:stream';3 import {scheduler} from 'node:timers/promises';4 import test from 'ava';3-import {execa} from '../../index.js';5+import {execa, execaSync} from '../../index.js';6 import {setFixtureDir} from '../helpers/fixtures-dir.js';5-import {getStdio} from '../helpers/stdio.js';7+import {fullStdio, getStdio} from '../helpers/stdio.js';8+import {getChunksGenerator} from '../helpers/generator.js';9+import {foobarObject} from '../helpers/input.js';10 11 setFixtureDir();12 13+const simpleChunk = ['aaa\nbbb\nccc'];14+const simpleLines = ['aaa\n', 'bbb\n', 'ccc'];15+const windowsChunk = ['aaa\r\nbbb\r\nccc'];16+const windowsLines = ['aaa\r\n', 'bbb\r\n', 'ccc'];17+const newlineEndChunk = ['aaa\nbbb\nccc\n'];18+const newlineEndLines = ['aaa\n', 'bbb\n', 'ccc\n'];19+const noNewlinesChunk = ['aaa'];20+const noNewlinesChunks = ['aaa', 'bbb', 'ccc'];21+const noNewlinesLines = ['aaabbbccc'];22+const newlineChunk = ['\n'];23+const newlinesChunk = ['\n\n\n'];24+const newlinesLines = ['\n', '\n', '\n'];25+const windowsNewlinesChunk = ['\r\n\r\n\r\n'];26+const windowsNewlinesLines = ['\r\n', '\r\n', '\r\n'];27+const runOverChunks = ['aaa\nb', 'b', 'b\nccc'];28+29 const bigLine = '.'.repeat(1e5);30 const manyChunks = Array.from({length: 1e3}).fill('.');31 32 const inputGenerator = async function * (input, chunks) {43 unmodified lines76 t.is(input.join(''), serializeResult(stdio[index], isUint8Array, objectMode));77 t.deepEqual(lines, stringsToUint8Arrays(expectedLines, isUint8Array));78 };79 60-test('Split string stdout - n newlines, 1 chunk', testLines, 1, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, false);61-test('Split string stderr - n newlines, 1 chunk', testLines, 2, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, false);62-test('Split string stdio[*] - n newlines, 1 chunk', testLines, 3, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, false);63-test('Split string stdout - no newline, n chunks', testLines, 1, ['aaa', 'bbb', 'ccc'], ['aaabbbccc'], false, false);64-test('Split string stdout - 0 newlines, 1 chunk', testLines, 1, ['aaa'], ['aaa'], false, false);65-test('Split string stdout - Windows newlines', testLines, 1, ['aaa\r\nbbb\r\nccc'], ['aaa\r\n', 'bbb\r\n', 'ccc'], false, false);66-test('Split string stdout - chunk ends with newline', testLines, 1, ['aaa\nbbb\nccc\n'], ['aaa\n', 'bbb\n', 'ccc\n'], false, false);67-test('Split string stdout - single newline', testLines, 1, ['\n'], ['\n'], false, false);68-test('Split string stdout - only newlines', testLines, 1, ['\n\n\n'], ['\n', '\n', '\n'], false, false);69-test('Split string stdout - only Windows newlines', testLines, 1, ['\r\n\r\n\r\n'], ['\r\n', '\r\n', '\r\n'], false, false);70-test('Split string stdout - line split over multiple chunks', testLines, 1, ['aaa\nb', 'b', 'b\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, false);80+test('Split string stdout - n newlines, 1 chunk', testLines, 1, simpleChunk, simpleLines, false, false);81+test('Split string stderr - n newlines, 1 chunk', testLines, 2, simpleChunk, simpleLines, false, false);82+test('Split string stdio[*] - n newlines, 1 chunk', testLines, 3, simpleChunk, simpleLines, false, false);83+test('Split string stdout - no newline, n chunks', testLines, 1, noNewlinesChunks, noNewlinesLines, false, false);84+test('Split string stdout - 0 newlines, 1 chunk', testLines, 1, noNewlinesChunk, noNewlinesChunk, false, false);85+test('Split string stdout - Windows newlines', testLines, 1, windowsChunk, windowsLines, false, false);86+test('Split string stdout - chunk ends with newline', testLines, 1, newlineEndChunk, newlineEndLines, false, false);87+test('Split string stdout - single newline', testLines, 1, newlineChunk, newlineChunk, false, false);88+test('Split string stdout - only newlines', testLines, 1, newlinesChunk, newlinesLines, false, false);89+test('Split string stdout - only Windows newlines', testLines, 1, windowsNewlinesChunk, windowsNewlinesLines, false, false);90+test('Split string stdout - line split over multiple chunks', testLines, 1, runOverChunks, simpleLines, false, false);91 test('Split string stdout - 0 newlines, big line', testLines, 1, [bigLine], [bigLine], false, false);92 test('Split string stdout - 0 newlines, many chunks', testLines, 1, manyChunks, [manyChunks.join('')], false, false);73-test('Split Uint8Array stdout - n newlines, 1 chunk', testLines, 1, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, false);74-test('Split Uint8Array stderr - n newlines, 1 chunk', testLines, 2, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, false);75-test('Split Uint8Array stdio[*] - n newlines, 1 chunk', testLines, 3, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, false);76-test('Split Uint8Array stdout - no newline, n chunks', testLines, 1, ['aaa', 'bbb', 'ccc'], ['aaabbbccc'], true, false);77-test('Split Uint8Array stdout - 0 newlines, 1 chunk', testLines, 1, ['aaa'], ['aaa'], true, false);78-test('Split Uint8Array stdout - Windows newlines', testLines, 1, ['aaa\r\nbbb\r\nccc'], ['aaa\r\n', 'bbb\r\n', 'ccc'], true, false);79-test('Split Uint8Array stdout - chunk ends with newline', testLines, 1, ['aaa\nbbb\nccc\n'], ['aaa\n', 'bbb\n', 'ccc\n'], true, false);80-test('Split Uint8Array stdout - single newline', testLines, 1, ['\n'], ['\n'], true, false);81-test('Split Uint8Array stdout - only newlines', testLines, 1, ['\n\n\n'], ['\n', '\n', '\n'], true, false);82-test('Split Uint8Array stdout - only Windows newlines', testLines, 1, ['\r\n\r\n\r\n'], ['\r\n', '\r\n', '\r\n'], true, false);83-test('Split Uint8Array stdout - line split over multiple chunks', testLines, 1, ['aaa\nb', 'b', 'b\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, false);93+test('Split Uint8Array stdout - n newlines, 1 chunk', testLines, 1, simpleChunk, simpleLines, true, false);94+test('Split Uint8Array stderr - n newlines, 1 chunk', testLines, 2, simpleChunk, simpleLines, true, false);95+test('Split Uint8Array stdio[*] - n newlines, 1 chunk', testLines, 3, simpleChunk, simpleLines, true, false);96+test('Split Uint8Array stdout - no newline, n chunks', testLines, 1, noNewlinesChunks, noNewlinesLines, true, false);97+test('Split Uint8Array stdout - 0 newlines, 1 chunk', testLines, 1, noNewlinesChunk, noNewlinesChunk, true, false);98+test('Split Uint8Array stdout - Windows newlines', testLines, 1, windowsChunk, windowsLines, true, false);99+test('Split Uint8Array stdout - chunk ends with newline', testLines, 1, newlineEndChunk, newlineEndLines, true, false);100+test('Split Uint8Array stdout - single newline', testLines, 1, newlineChunk, newlineChunk, true, false);101+test('Split Uint8Array stdout - only newlines', testLines, 1, newlinesChunk, newlinesLines, true, false);102+test('Split Uint8Array stdout - only Windows newlines', testLines, 1, windowsNewlinesChunk, windowsNewlinesLines, true, false);103+test('Split Uint8Array stdout - line split over multiple chunks', testLines, 1, runOverChunks, simpleLines, true, false);104 test('Split Uint8Array stdout - 0 newlines, big line', testLines, 1, [bigLine], [bigLine], true, false);105 test('Split Uint8Array stdout - 0 newlines, many chunks', testLines, 1, manyChunks, [manyChunks.join('')], true, false);86-test('Split string stdout - n newlines, 1 chunk, objectMode', testLines, 1, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, true);87-test('Split string stderr - n newlines, 1 chunk, objectMode', testLines, 2, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, true);88-test('Split string stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, true);89-test('Split string stdout - no newline, n chunks, objectMode', testLines, 1, ['aaa', 'bbb', 'ccc'], ['aaabbbccc'], false, true);90-test('Split string stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, ['aaa'], ['aaa'], false, true);91-test('Split string stdout - Windows newlines, objectMode', testLines, 1, ['aaa\r\nbbb\r\nccc'], ['aaa\r\n', 'bbb\r\n', 'ccc'], false, true);92-test('Split string stdout - chunk ends with newline, objectMode', testLines, 1, ['aaa\nbbb\nccc\n'], ['aaa\n', 'bbb\n', 'ccc\n'], false, true);93-test('Split string stdout - single newline, objectMode', testLines, 1, ['\n'], ['\n'], false, true);94-test('Split string stdout - only newlines, objectMode', testLines, 1, ['\n\n\n'], ['\n', '\n', '\n'], false, true);95-test('Split string stdout - only Windows newlines, objectMode', testLines, 1, ['\r\n\r\n\r\n'], ['\r\n', '\r\n', '\r\n'], false, true);96-test('Split string stdout - line split over multiple chunks, objectMode', testLines, 1, ['aaa\nb', 'b', 'b\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false, true);106+test('Split string stdout - n newlines, 1 chunk, objectMode', testLines, 1, simpleChunk, simpleLines, false, true);107+test('Split string stderr - n newlines, 1 chunk, objectMode', testLines, 2, simpleChunk, simpleLines, false, true);108+test('Split string stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, simpleChunk, simpleLines, false, true);109+test('Split string stdout - no newline, n chunks, objectMode', testLines, 1, noNewlinesChunks, noNewlinesLines, false, true);110+test('Split string stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, noNewlinesChunk, noNewlinesChunk, false, true);111+test('Split string stdout - Windows newlines, objectMode', testLines, 1, windowsChunk, windowsLines, false, true);112+test('Split string stdout - chunk ends with newline, objectMode', testLines, 1, newlineEndChunk, newlineEndLines, false, true);113+test('Split string stdout - single newline, objectMode', testLines, 1, newlineChunk, newlineChunk, false, true);114+test('Split string stdout - only newlines, objectMode', testLines, 1, newlinesChunk, newlinesLines, false, true);115+test('Split string stdout - only Windows newlines, objectMode', testLines, 1, windowsNewlinesChunk, windowsNewlinesLines, false, true);116+test('Split string stdout - line split over multiple chunks, objectMode', testLines, 1, runOverChunks, simpleLines, false, true);117 test('Split string stdout - 0 newlines, big line, objectMode', testLines, 1, [bigLine], [bigLine], false, true);118 test('Split string stdout - 0 newlines, many chunks, objectMode', testLines, 1, manyChunks, [manyChunks.join('')], false, true);99-test('Split Uint8Array stdout - n newlines, 1 chunk, objectMode', testLines, 1, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, true);100-test('Split Uint8Array stderr - n newlines, 1 chunk, objectMode', testLines, 2, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, true);101-test('Split Uint8Array stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, true);102-test('Split Uint8Array stdout - no newline, n chunks, objectMode', testLines, 1, ['aaa', 'bbb', 'ccc'], ['aaabbbccc'], true, true);103-test('Split Uint8Array stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, ['aaa'], ['aaa'], true, true);104-test('Split Uint8Array stdout - Windows newlines, objectMode', testLines, 1, ['aaa\r\nbbb\r\nccc'], ['aaa\r\n', 'bbb\r\n', 'ccc'], true, true);105-test('Split Uint8Array stdout - chunk ends with newline, objectMode', testLines, 1, ['aaa\nbbb\nccc\n'], ['aaa\n', 'bbb\n', 'ccc\n'], true, true);106-test('Split Uint8Array stdout - single newline, objectMode', testLines, 1, ['\n'], ['\n'], true, true);107-test('Split Uint8Array stdout - only newlines, objectMode', testLines, 1, ['\n\n\n'], ['\n', '\n', '\n'], true, true);108-test('Split Uint8Array stdout - only Windows newlines, objectMode', testLines, 1, ['\r\n\r\n\r\n'], ['\r\n', '\r\n', '\r\n'], true, true);109-test('Split Uint8Array stdout - line split over multiple chunks, objectMode', testLines, 1, ['aaa\nb', 'b', 'b\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true, true);119+test('Split Uint8Array stdout - n newlines, 1 chunk, objectMode', testLines, 1, simpleChunk, simpleLines, true, true);120+test('Split Uint8Array stderr - n newlines, 1 chunk, objectMode', testLines, 2, simpleChunk, simpleLines, true, true);121+test('Split Uint8Array stdio[*] - n newlines, 1 chunk, objectMode', testLines, 3, simpleChunk, simpleLines, true, true);122+test('Split Uint8Array stdout - no newline, n chunks, objectMode', testLines, 1, noNewlinesChunks, noNewlinesLines, true, true);123+test('Split Uint8Array stdout - 0 newlines, 1 chunk, objectMode', testLines, 1, noNewlinesChunk, noNewlinesChunk, true, true);124+test('Split Uint8Array stdout - Windows newlines, objectMode', testLines, 1, windowsChunk, windowsLines, true, true);125+test('Split Uint8Array stdout - chunk ends with newline, objectMode', testLines, 1, newlineEndChunk, newlineEndLines, true, true);126+test('Split Uint8Array stdout - single newline, objectMode', testLines, 1, newlineChunk, newlineChunk, true, true);127+test('Split Uint8Array stdout - only newlines, objectMode', testLines, 1, newlinesChunk, newlinesLines, true, true);128+test('Split Uint8Array stdout - only Windows newlines, objectMode', testLines, 1, windowsNewlinesChunk, windowsNewlinesLines, true, true);129+test('Split Uint8Array stdout - line split over multiple chunks, objectMode', testLines, 1, runOverChunks, simpleLines, true, true);130 test('Split Uint8Array stdout - 0 newlines, big line, objectMode', testLines, 1, [bigLine], [bigLine], true, true);131 test('Split Uint8Array stdout - 0 newlines, many chunks, objectMode', testLines, 1, manyChunks, [manyChunks.join('')], true, true);132 133 // eslint-disable-next-line max-params8 unmodified lines142 t.is(input.join(''), objectMode ? stdout.join('') : stdout);143 t.deepEqual(lines, expectedLines);144 };145 126-test('Does not split lines when "binary" is true', testBinaryOption, true, ['aaa\nbbb\nccc'], ['aaa\nbbb\nccc'], false);127-test('Splits lines when "binary" is false', testBinaryOption, false, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false);128-test('Splits lines when "binary" is undefined', testBinaryOption, undefined, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], false);129-test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, ['aaa\nbbb\nccc'], ['aaa\nbbb\nccc'], true);130-test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true);131-test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, ['aaa\nbbb\nccc'], ['aaa\n', 'bbb\n', 'ccc'], true);146+test('Does not split lines when "binary" is true', testBinaryOption, true, simpleChunk, simpleChunk, false);147+test('Splits lines when "binary" is false', testBinaryOption, false, simpleChunk, simpleLines, false);148+test('Splits lines when "binary" is undefined', testBinaryOption, undefined, simpleChunk, simpleLines, false);149+test('Does not split lines when "binary" is true, objectMode', testBinaryOption, true, simpleChunk, simpleChunk, true);150+test('Splits lines when "binary" is false, objectMode', testBinaryOption, false, simpleChunk, simpleLines, true);151+test('Splits lines when "binary" is undefined, objectMode', testBinaryOption, undefined, simpleChunk, simpleLines, true);152+153+// eslint-disable-next-line max-params154+const testStreamLines = async (t, index, input, expectedLines, isUint8Array) => {155+ const {stdio} = await execa('noop-fd.js', [`${index}`, input], {156+ ...fullStdio,157+ lines: true,158+ encoding: isUint8Array ? 'buffer' : 'utf8',159+ });160+ t.deepEqual(stdio[index], stringsToUint8Arrays(expectedLines, isUint8Array));161+};162+163+test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleChunk[0], simpleLines, false);164+test('"lines: true" splits lines, stdout, Uint8Array', testStreamLines, 1, simpleChunk[0], simpleLines, true);165+test('"lines: true" splits lines, stderr, string', testStreamLines, 2, simpleChunk[0], simpleLines, false);166+test('"lines: true" splits lines, stderr, Uint8Array', testStreamLines, 2, simpleChunk[0], simpleLines, true);167+test('"lines: true" splits lines, stdio[*], string', testStreamLines, 3, simpleChunk[0], simpleLines, false);168+test('"lines: true" splits lines, stdio[*], Uint8Array', testStreamLines, 3, simpleChunk[0], simpleLines, true);169+170+const testStreamLinesNoop = async (t, lines, execaMethod) => {171+ const {stdout} = await execaMethod('noop-fd.js', ['1', simpleChunk[0]], {lines});172+ t.is(stdout, simpleChunk[0]);173+};174+175+test('"lines: false" is a noop with execa()', testStreamLinesNoop, false, execa);176+test('"lines: false" is a noop with execaSync()', testStreamLinesNoop, false, execaSync);177+test('"lines: true" is a noop with execaSync()', testStreamLinesNoop, true, execaSync);178+179+const bigArray = Array.from({length: 1e5}).fill('.\n');180+const bigString = bigArray.join('');181+const bigStringNoNewlines = '.'.repeat(1e6);182+183+// eslint-disable-next-line max-params184+const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary) => {185+ const {stdout} = await execa('noop.js', {lines: true, stdout: getChunksGenerator(input, objectMode, binary)});186+ t.deepEqual(stdout, expectedLines);187+};188+189+test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunk, simpleLines, false, false);190+test('"lines: true" works with strings generators, objectMode', testStreamLinesGenerator, simpleChunk, simpleLines, true, false);191+test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunk, simpleLines, false, true);192+test('"lines: true" works with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunk, simpleLines, true, true);193+test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false);194+test('"lines: true" works with big strings generators, objectMode', testStreamLinesGenerator, [bigString], bigArray, true, false);195+test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], false, false);196+test('"lines: true" works with big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false);197+198+test('"lines: true" is a noop with objects generators, objectMode', async t => {199+ const {stdout} = await execa('noop.js', {lines: true, stdout: getChunksGenerator([foobarObject], true)});200+ t.deepEqual(stdout, [foobarObject]);201+});202+203+const singleLine = 'a\n';204+205+test('"lines: true" works with other encodings', async t => {206+ const {stdout} = await execa('noop-fd.js', ['1', `${singleLine}${singleLine}`], {lines: true, encoding: 'base64'});207+ const expectedLines = [singleLine, singleLine].map(line => btoa(line));208+ t.not(btoa(`${singleLine}${singleLine}`), expectedLines.join(''));209+ t.deepEqual(stdout, expectedLines);210+});211+212+test('"lines: true" works with stream async iteration', async t => {213+ const childProcess = execa('noop.js', {lines: true, stdout: getChunksGenerator(simpleChunk), buffer: false});214+ const [stdout] = await Promise.all([childProcess.stdout.toArray(), childProcess]);215+ t.deepEqual(stdout, simpleLines);216+});217+218+test('"lines: true" works with stream "data" events', async t => {219+ const childProcess = execa('noop.js', {lines: true, stdout: getChunksGenerator(simpleChunk), buffer: false});220+ const [[firstLine]] = await Promise.all([once(childProcess.stdout, 'data'), childProcess]);221+ t.is(firstLine, simpleLines[0]);222+});223+224+test('"lines: true" works with writable streams targets', async t => {225+ const lines = [];226+ const writable = new Writable({227+ write(line, encoding, done) {228+ lines.push(line.toString());229+ done();230+ },231+ });232+ await execa('noop.js', {lines: true, stdout: [getChunksGenerator(simpleChunk), writable]});233+ t.deepEqual(lines, simpleLines);234+});modified:index.d.ts+22 added-9 removed
206 unmodified lines207 StreamOutputIgnored extends boolean,208 OptionsType extends CommonOptions = CommonOptions,209 > = StreamOutputIgnored extends true210 ? undefined211- : StreamEncoding<IsObjectStream<StreamIndex, OptionsType>, OptionsType['encoding']>;211+ : StreamEncoding<IsObjectStream<StreamIndex, OptionsType>, OptionsType['lines'], OptionsType['encoding']>;212 213 type StreamEncoding<214 IsObjectResult extends boolean,215+ LinesOption extends CommonOptions['lines'],216 Encoding extends CommonOptions['encoding'],217 > = IsObjectResult extends true ? unknown[]218+ : LinesOption extends true219+ ? Encoding extends 'buffer' ? Uint8Array[] : string[]217- : Encoding extends 'buffer' ? Uint8Array : string;220+ : Encoding extends 'buffer' ? Uint8Array : string;221 222 // Type of `result.all`223 type AllOutput<OptionsType extends Options = Options> = AllOutputProperty<OptionsType['all'], OptionsType>;224 153 unmodified lines378 */379 readonly stdio?: StdioOptions<IsSync>;380 381 /**382+ Split `stdout` and `stderr` into lines.383+ - `result.stdout`, `result.stderr`, `result.all` and `result.stdio` are arrays of lines.384+ - `childProcess.stdout`, `childProcess.stderr`, `childProcess.all` and `childProcess.stdio` iterate over lines instead of arbitrary chunks.385+ - Any stream passed to the `stdout`, `stderr` or `stdio` option receives lines instead of arbitrary chunks.386+387+ @default false388+ */389+ readonly lines?: IfAsync<IsSync, boolean>;390+391+ /**392 Setting this to `false` resolves the promise with the error instead of rejecting it.393 394 @default true395 */256 unmodified lines652 653 /**654 The output of the process on `stdout`.655 643- This is `undefined` if the `stdout` option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `stdout` option is a transform in object mode.656+ This is `undefined` if the `stdout` option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `lines` option is `true, or if the `stdout` option is a transform in object mode.657 */658 stdout: StdioOutput<'1', OptionsType>;659 660 /**661 The output of the process on `stderr`.662 650- This is `undefined` if the `stderr` option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `stderr` option is a transform in object mode.663+ This is `undefined` if the `stderr` option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `lines` option is `true, or if the `stderr` option is a transform in object mode.664 */665 stderr: StdioOutput<'2', OptionsType>;666 667 /**52 unmodified lines720 This is `undefined` if either:721 - the `all` option is `false` (default value)722 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)723 711- This is an array if either the `stdout` or `stderr` option is a transform in object mode.724+ This is an array if the `lines` option is `true, or if either the `stdout` or `stderr` option is a transform in object mode.725 */726 all: IfAsync<IsSync, AllOutput<OptionsType>>;727 // Workaround for a TypeScript bug: https://github.com/microsoft/TypeScript/issues/57062728 } & {};222 unmodified lines951 952 /**953 Same as `execa()` but synchronous.954 942-Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization` and `signal`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.955+Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization`, `signal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.956 957 @param file - The program/script to execute, as a string or file URL958 @param arguments - Arguments to pass to `file` on execution.959 @returns A `childProcessResult` object90 unmodified lines1050 1051 /**1052 Same as `execaCommand()` but synchronous.1053 1041-Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization` and `signal`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1054+Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization`, `signal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1055 1056 @param command - The program/script to execute and its arguments.1057 @returns A `childProcessResult` object1058 @throws A `childProcessResult` error48 unmodified lines1107 1108 /**1109 Same as $\`command\` but synchronous.1110 1098- Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization` and `signal`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1111+ Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization`, `signal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1112 1113 @returns A `childProcessResult` object1114 @throws A `childProcessResult` error1115 43 unmodified lines1159 1160 /**1161 Same as $\`command\` but synchronous.1162 1150- Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization` and `signal`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1163+ Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `serialization`, `signal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1164 1165 @returns A `childProcessResult` object1166 @throws A `childProcessResult` error1167 135 unmodified linesmodified:index.js+2 added
80 unmodified lines81 windowsHide = true,82 verbose = verboseDefault,83 killSignal = 'SIGTERM',84 forceKillAfterDelay = true,85+ lines = false,86 ...options87 }) => ({88 ...options,89 maxBuffer,11 unmodified lines101 windowsHide,102 verbose,103 killSignal,104 forceKillAfterDelay,105+ lines,106 });107 108 // Prevent passing the `timeout` option directly to `child_process.spawn()`109 const handleAsyncOptions = ({timeout, ...options}) => ({...options, timeoutDuration: timeout});248 unmodified linesmodified:index.test-d.ts+37 added-1 removed
20 unmodified lines21 type ExecaSyncError,22 } from './index.js';23 24 type AnySyncChunk = string | Uint8Array | undefined;25-type AnyChunk = AnySyncChunk | unknown[];25+type AnyChunk = AnySyncChunk | string[] | Uint8Array[] | unknown[];26 expectType<Readable | null>({} as ExecaChildProcess['stdout']);27 expectType<Readable | null>({} as ExecaChildProcess['stderr']);28 expectType<Readable | undefined>({} as ExecaChildProcess['all']);29 expectType<AnyChunk>({} as ExecaReturnValue['stdout']);115 unmodified lines145 expectType<Uint8Array>(bufferResult.stderr);146 expectType<Uint8Array>(bufferResult.stdio[2]);147 expectType<Uint8Array>(bufferResult.all);148 149+ const linesResult = await execa('unicorns', {lines: true, all: true});150+ expectType<string[]>(linesResult.stdout);151+ expectType<string[]>(linesResult.stdio[1]);152+ expectType<string[]>(linesResult.stderr);153+ expectType<string[]>(linesResult.stdio[2]);154+ expectType<string[]>(linesResult.all);155+156+ const linesBufferResult = await execa('unicorns', {lines: true, encoding: 'buffer', all: true});157+ expectType<Uint8Array[]>(linesBufferResult.stdout);158+ expectType<Uint8Array[]>(linesBufferResult.stdio[1]);159+ expectType<Uint8Array[]>(linesBufferResult.stderr);160+ expectType<Uint8Array[]>(linesBufferResult.stdio[2]);161+ expectType<Uint8Array[]>(linesBufferResult.all);162+163 const noBufferPromise = execa('unicorns', {buffer: false, all: true});164 expectType<Readable>(noBufferPromise.stdout);165 expectType<Readable>(noBufferPromise.stderr);166 expectType<Readable>(noBufferPromise.all);167 unmodified lines334 335 const bufferFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe'], encoding: 'buffer'});336 expectType<Uint8Array>(bufferFd3Result.stdio[3]);337 338+ const linesFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe'], lines: true});339+ expectType<string[]>(linesFd3Result.stdio[3]);340+341+ const linesBufferFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe'], lines: true, encoding: 'buffer'});342+ expectType<Uint8Array[]>(linesBufferFd3Result.stdio[3]);343+344 const noBufferFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe'], buffer: false});345 expectType<undefined>(noBufferFd3Result.stdio[3]);346 347 const ignoreFd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'ignore']});95 unmodified lines443 expectType<Uint8Array>(execaBufferError.stderr);444 expectType<Uint8Array>(execaBufferError.stdio[2]);445 expectType<Uint8Array>(execaBufferError.all);446 447+ const execaLinesError = error as ExecaError<{lines: true; all: true}>;448+ expectType<string[]>(execaLinesError.stdout);449+ expectType<string[]>(execaLinesError.stdio[1]);450+ expectType<string[]>(execaLinesError.stderr);451+ expectType<string[]>(execaLinesError.stdio[2]);452+ expectType<string[]>(execaLinesError.all);453+454+ const execaLinesBufferError = error as ExecaError<{lines: true; encoding: 'buffer'; all: true}>;455+ expectType<Uint8Array[]>(execaLinesBufferError.stdout);456+ expectType<Uint8Array[]>(execaLinesBufferError.stdio[1]);457+ expectType<Uint8Array[]>(execaLinesBufferError.stderr);458+ expectType<Uint8Array[]>(execaLinesBufferError.stdio[2]);459+ expectType<Uint8Array[]>(execaLinesBufferError.all);460+461 const noBufferError = error as ExecaError<{buffer: false; all: true}>;462 expectType<undefined>(noBufferError.stdout);463 expectType<undefined>(noBufferError.stdio[1]);464 expectType<undefined>(noBufferError.stderr);283 unmodified lines748 execa('unicorns', {execPath: fileUrl});749 execaSync('unicorns', {execPath: fileUrl});750 execa('unicorns', {buffer: false});751 expectError(execaSync('unicorns', {buffer: false}));752+execa('unicorns', {lines: false});753+expectError(execaSync('unicorns', {lines: false}));754 execa('unicorns', {input: ''});755 execaSync('unicorns', {input: ''});756 execa('unicorns', {input: new Uint8Array()});757 execaSync('unicorns', {input: new Uint8Array()});592 unmodified linesmodified:readme.md+20 added-10 removed
276 unmodified lines277 ### execaSync(file, arguments?, options?)278 279 Same as [`execa()`](#execacommandcommand-options) but synchronous.280 281-Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization) and [`signal`](#signal). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.281+Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization), [`signal`](#signal) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.282 283 Returns or throws a [`childProcessResult`](#childProcessResult).284 285 ### $.sync\`command\`286 ### $.s\`command\`287 288 Same as [$\`command\`](#command) but synchronous.289 290-Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization) and [`signal`](#signal). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.290+Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization), [`signal`](#signal) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.291 292 Returns or throws a [`childProcessResult`](#childProcessResult).293 294 ### execaCommandSync(command, options?)295 296 Same as [`execaCommand()`](#execacommand-command-options) but synchronous.297 298-Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization) and [`signal`](#signal). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.298+Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`serialization`](#serialization), [`signal`](#signal) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.299 300 Returns or throws a [`childProcessResult`](#childProcessResult).301 302 ### Shell syntax78 unmodified lines381 This is `undefined` when the process could not be spawned or was terminated by a [signal](#signal-1).382 383 #### stdout384 385-Type: `string | Uint8Array | unknown[] | undefined`385+Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`386 387 The output of the process on `stdout`.388 389-This is `undefined` if the [`stdout`](#stdout-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).389+This is `undefined` if the [`stdout`](#stdout-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the [`lines` option](#lines) is `true, or if the `stdout` option is a [transform in object mode](docs/transform.md#object-mode).390 391 #### stderr392 393-Type: `string | Uint8Array | unknown[] | undefined`393+Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`394 395 The output of the process on `stderr`.396 397-This is `undefined` if the [`stderr`](#stderr-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).397+This is `undefined` if the [`stderr`](#stderr-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). This is an array if the [`lines` option](#lines) is `true, or if the `stderr` option is a [transform in object mode](docs/transform.md#object-mode).398 399 #### all400 401-Type: `string | Uint8Array | unknown[] | undefined`401+Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`402 403 The output of the process with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).404 405 This is `undefined` if either:406 - the [`all` option](#all-2) is `false` (the default value)407 - both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)408 409-This is an array if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).409+This is an array if the [`lines` option](#lines) is `true, or if either the `stdout` or `stderr` option is a [transform in object mode](docs/transform.md#object-mode).410 411 #### stdio412 413-Type: `Array<string | Uint8Array | unknown[] | undefined>`413+Type: `Array<string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined>`414 415 The output of the process on [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1) and [other file descriptors](#stdio-1).416 417 Items are `undefined` when their corresponding [`stdio`](#stdio-1) option is set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio). Items are arrays when their corresponding `stdio` option is a [transform in object mode](docs/transform.md#object-mode).218 unmodified lines636 Default: `false`637 638 Add an `.all` property on the [promise](#all) and the [resolved value](#all-1). The property contains the output of the process with `stdout` and `stderr` [interleaved](#ensuring-all-output-is-interleaved).639 640+#### lines641+642+Type: `boolean`\643+Default: `false`644+645+Split `stdout` and `stderr` into lines.646+- [`result.stdout`](#stdout), [`result.stderr`](#stderr), [`result.all`](#all-1) and [`result.stdio`](#stdio) are arrays of lines.647+- [`childProcess.stdout`](https://nodejs.org/api/child_process.html#subprocessstdout), [`childProcess.stderr`](https://nodejs.org/api/child_process.html#subprocessstderr), [`childProcess.all`](#all) and [`childProcess.stdio`](https://nodejs.org/api/child_process.html#subprocessstdio) iterate over lines instead of arbitrary chunks.648+- Any stream passed to the [`stdout`](#stdout-1), [`stderr`](#stderr-1) or [`stdio`](#stdio-1) option receives lines instead of arbitrary chunks.649+650 #### reject651 652 Type: `boolean`\653 Default: `true`301 unmodified lines