Skip to content
Myr

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

11 files+358 added−132 removed

modified:lib/arguments/options.js+4 added-3 removed
modified:lib/arguments/specific.js+2 added-1 removed
modified:lib/stdio/output-sync.js+8 added-5 removed
1import {writeFileSync} from 'node:fs';2import {shouldLogOutput, logLinesSync} from '../verbose/output.js';3import {getMaxBufferSync} from '../stream/max-buffer.js';4import {stripNewline} from '../return/output.js';5import {joinToString, joinToUint8Array, bufferToUint8Array, isUint8Array, concatUint8Arrays} from './uint-array.js';6import {getGenerators, runGeneratorsSync} from './generator.js';7import {splitLinesSync} from './split.js';8import {FILE_TYPES} from './type.js';
66 unmodified lines
75 return {serializedResult: joinToUint8Array(chunks)};76 }7778 const serializedResult = joinToString(chunks, encoding);78 if (lines) {79 if (lines[fdNumber]) {80 return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline[fdNumber], objectMode)};81 }8283 return {serializedResult};
6 unmodified lines
90 }91 }92};9393export const getAllSync = ([, stdout, stderr], {all}) => {94 if (!all) {94export const getAllSync = ([, stdout, stderr], options) => {95 if (!options.all) {96 return;97 }9899 if (stdout === undefined) {
4 unmodified lines
104 return stdout;105 }106107 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 }112113 if (Array.isArray(stderr)) {111 return [stdout, ...stderr];114 return [stripNewline(stdout, options, true, 1), ...stderr];115 }116117 if (isUint8Array(stdout) && isUint8Array(stderr)) {118 return concatUint8Arrays([stdout, stderr]);
4 unmodified lines
modified:lib/stream/all.js+1 added-1 removed
11 unmodified lines
12 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 lines
modified:lib/stream/resolve.js+1 added-1 removed
54 unmodified lines
55};5657// Read the contents of `subprocess.std*` and|or wait for its completion58const waitForSubprocessStreams = ({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo}) =>59 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, fdNumber, encoding, buffer, maxBuffer: maxBuffer[fdNumber], lines, 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}));6061// Transforms replace `subprocess.std*`, which means they are not exposed to users.62// However, we still want to wait for their completion.63const waitForOriginalStreams = (originalStreams, subprocess, streamInfo) =>
23 unmodified lines
modified:test/stdio/lines.js+94 added-66 removed
23 unmodified lines
24const getSimpleChunkSubprocessAsync = options => getSimpleChunkSubprocess(execa, options);25const getSimpleChunkSubprocess = (execaMethod, options) => execaMethod('noop-fd.js', ['1', simpleFull], {lines: true, ...options});2627// eslint-disable-next-line max-params28const 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 });28const 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};3237test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleFull, simpleLines, false, execa);38test('"lines: true" splits lines, stderr, string', testStreamLines, 2, simpleFull, simpleLines, false, execa);39test('"lines: true" splits lines, stdio[*], string', testStreamLines, 3, simpleFull, simpleLines, false, execa);40test('"lines: true" splits lines, stdout, string, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execa);41test('"lines: true" splits lines, stdout, string, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, {stdout: true}, execa);42test('"lines: true" splits lines, stderr, string, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execa);43test('"lines: true" splits lines, stderr, string, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, {stderr: true}, execa);44test('"lines: true" splits lines, stdio[*], string, stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execa);45test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, {fd3: true}, execa);46test('"lines: true" splits lines, stdout, string, sync', testStreamLines, 1, simpleFull, simpleLines, false, execaSync);47test('"lines: true" splits lines, stderr, string, sync', testStreamLines, 2, simpleFull, simpleLines, false, execaSync);48test('"lines: true" splits lines, stdio[*], string, sync', testStreamLines, 3, simpleFull, simpleLines, false, execaSync);49test('"lines: true" splits lines, stdout, string, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execaSync);50test('"lines: true" splits lines, stdout, string, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, {stdout: true}, execaSync);51test('"lines: true" splits lines, stderr, string, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execaSync);52test('"lines: true" splits lines, stderr, string, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, {stderr: true}, execaSync);53test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execaSync);54test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, {fd3: true}, execaSync);33test('"lines: true" splits lines, stdout', testStreamLines, 1, simpleFull, simpleLines, true, false, execa);34test('"lines: true" splits lines, stdout, fd-specific', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execa);35test('"lines: true" splits lines, stderr', testStreamLines, 2, simpleFull, simpleLines, true, false, execa);36test('"lines: true" splits lines, stderr, fd-specific', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execa);37test('"lines: true" splits lines, stdio[*]', testStreamLines, 3, simpleFull, simpleLines, true, false, execa);38test('"lines: true" splits lines, stdio[*], fd-specific', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execa);39test('"lines: true" splits lines, stdout, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execa);40test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execa);41test('"lines: true" splits lines, stderr, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execa);42test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execa);43test('"lines: true" splits lines, stdio[*], stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execa);44test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execa);45test('"lines: true" splits lines, stdout, sync', testStreamLines, 1, simpleFull, simpleLines, true, false, execaSync);46test('"lines: true" splits lines, stdout, fd-specific, sync', testStreamLines, 1, simpleFull, simpleLines, {stdout: true}, false, execaSync);47test('"lines: true" splits lines, stderr, sync', testStreamLines, 2, simpleFull, simpleLines, true, false, execaSync);48test('"lines: true" splits lines, stderr, fd-specific, sync', testStreamLines, 2, simpleFull, simpleLines, {stderr: true}, false, execaSync);49test('"lines: true" splits lines, stdio[*], sync', testStreamLines, 3, simpleFull, simpleLines, true, false, execaSync);50test('"lines: true" splits lines, stdio[*], fd-specific, sync', testStreamLines, 3, simpleFull, simpleLines, {fd3: true}, false, execaSync);51test('"lines: true" splits lines, stdout, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, true, execaSync);52test('"lines: true" splits lines, stdout, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, {stdout: true}, execaSync);53test('"lines: true" splits lines, stderr, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, true, execaSync);54test('"lines: true" splits lines, stderr, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, {stderr: true}, execaSync);55test('"lines: true" splits lines, stdio[*], stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, true, execaSync);56test('"lines: true" splits lines, stdio[*], stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, {fd3: true}, execaSync);5758const testStreamLinesNoop = async (t, lines, execaMethod) => {59 const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});60 t.is(stdout, simpleFull);61};6261test('"lines: false" is a noop with execa()', testStreamLinesNoop, false, execa);62test('"lines: false" is a noop with execaSync()', testStreamLinesNoop, false, execaSync);63test('"lines: false" is a noop', testStreamLinesNoop, false, execa);64test('"lines: false" is a noop, fd-specific', testStreamLinesNoop, {stderr: true}, execa);65test('"lines: false" is a noop, fd-specific none', testStreamLinesNoop, {}, execa);66test('"lines: false" is a noop, sync', testStreamLinesNoop, false, execaSync);67test('"lines: false" is a noop, fd-specific, sync', testStreamLinesNoop, {stderr: true}, execaSync);68test('"lines: false" is a noop, fd-specific none, sync', testStreamLinesNoop, {}, execaSync);6970const bigArray = Array.from({length: 1e5}).fill('.\n');71const bigString = bigArray.join('');72const bigStringNoNewlines = '.'.repeat(1e6);
29 unmodified lines
102test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execaSync);103test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execaSync);104test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync);105100const testLinesObjectMode = async (t, execaMethod) => {106const 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};113108test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, execa);109test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, execaSync);114test('"lines: true" is a noop with objects generators, objectMode', testLinesObjectMode, true, execa);115test('"lines: true" is a noop with objects generators, fd-specific, objectMode', testLinesObjectMode, {stdout: true}, execa);116test('"lines: true" is a noop with objects generators, objectMode, sync', testLinesObjectMode, true, execaSync);117test('"lines: true" is a noop with objects generators, fd-specific, objectMode, sync', testLinesObjectMode, {stdout: true}, execaSync);118119// eslint-disable-next-line max-params112const testEncoding = async (t, input, expectedOutput, encoding, stripFinalNewline, execaMethod) => {113 const {stdout} = await execaMethod('stdin.js', {lines: true, stripFinalNewline, encoding, input});120const 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};124117test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execa);118test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execa);119test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', {stdout: true}, execa);120test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);121test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);122test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: false}, execa);123test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', false, execa);124test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, execa);125test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, execa);126test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execaSync);127test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execaSync);128test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', {stdout: true}, execaSync);129test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);130test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);131test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: false}, execaSync);132test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', false, execaSync);133test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, execaSync);134test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, execaSync);125test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execa);126test('"lines: true" is a noop with "encoding: utf16", fd-specific', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execa);127test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execa);128test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execa);129test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);130test('"lines: true" is a noop with "encoding: buffer", fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execa);131test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execa);132test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execa);133test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execa);134test('"lines: true" is a noop with "encoding: hex", fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execa);135test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execa);136test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execa);137test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execaSync);138test('"lines: true" is a noop with "encoding: utf16", fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', {stdout: true}, false, execaSync);139test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, true, execaSync);140test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, {stdout: true}, execaSync);141test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);142test('"lines: true" is a noop with "encoding: buffer", fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: true}, false, execaSync);143test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, false, execaSync);144test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', true, {stdout: false}, execaSync);145test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, false, execaSync);146test('"lines: true" is a noop with "encoding: hex", fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, false, execaSync);147test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, true, execaSync);148test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, {stdout: true}, execaSync);149136const testLinesNoBuffer = async (t, execaMethod) => {137 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {buffer: false});150const testLinesNoBuffer = async (t, lines, execaMethod) => {151 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {lines, buffer: false});152 t.is(stdout, undefined);153};154141test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, execa);142test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, execaSync);155test('"lines: true" is a noop with "buffer: false"', testLinesNoBuffer, true, execa);156test('"lines: true" is a noop with "buffer: false", fd-specific', testLinesNoBuffer, {stdout: true}, execa);157test('"lines: true" is a noop with "buffer: false", sync', testLinesNoBuffer, true, execaSync);158test('"lines: true" is a noop with "buffer: false", fd-specific, sync', testLinesNoBuffer, {stdout: true}, execaSync);159160const maxBuffer = simpleLines.length - 1;161146test('"lines: true" can be below "maxBuffer"', async t => {147 const {isMaxBuffer, stdout} = await getSimpleChunkSubprocessAsync({maxBuffer: maxBuffer + 1});162const 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};167152test('"lines: true" can be above "maxBuffer"', async t => {153 const {isMaxBuffer, shortMessage, stdout} = await t.throwsAsync(getSimpleChunkSubprocessAsync({maxBuffer}));168test('"lines: true" can be below "maxBuffer"', testBelowMaxBuffer, true);169test('"lines: true" can be below "maxBuffer", fd-specific', testBelowMaxBuffer, {stdout: true});170171const 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};177159test('"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}));178test('"lines: true" can be above "maxBuffer"', testAboveMaxBuffer, true);179test('"lines: true" can be above "maxBuffer", fd-specific', testAboveMaxBuffer, {stdout: true});180181const 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};187166test('"maxBuffer" is measured in bytes with "lines: true", sync', t => {188test('"maxBuffer" is measured in lines with "lines: true"', testMaxBufferUnit, true);189test('"maxBuffer" is measured in lines with "lines: true", fd-specific', testMaxBufferUnit, {stdout: true});190191const 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};199200test('"maxBuffer" is measured in bytes with "lines: true", sync', testMaxBufferUnitSync, true);201test('"maxBuffer" is measured in bytes with "lines: true", fd-specific, sync', testMaxBufferUnitSync, {stdout: true});202203test('"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 lines
modified:test/stream/all.js+42 added-26 removed
21 unmodified lines
22 t.is(exitCode, isFailure ? 1 : 0);23 t.deepEqual(all, expectedOutput);24};2526const stripOne = {stderr: true};27const stripBoth = {stdout: true, stderr: true};26const fdOne = {stderr: true};27const fdBoth = {stdout: true, stderr: true};2829test('result.all is defined', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execa);30test('result.all is defined, encoding "buffer"', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execa);31test('result.all is defined, lines', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execa);32test('result.all is defined, lines, fd-specific one', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, false, execa);33test('result.all is defined, lines, fd-specific both', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, false, execa);34test('result.all is defined, stripFinalNewline', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execa);33test('result.all is defined, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, false, execa);34test('result.all is defined, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, false, execa);35test('result.all is defined, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, false, execa);36test('result.all is defined, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, false, execa);37test('result.all is defined, encoding "buffer", stripFinalNewline', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execa);36test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, false, execa);37test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, false, execa);38test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, false, execa);39test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, false, execa);40test('result.all is defined, lines, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execa);41test('result.all is defined, lines, fd-specific one, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, false, execa);42test('result.all is defined, lines, fd-specific both, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, false, execa);39test('result.all is defined, lines, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, false, execa);40test('result.all is defined, lines, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, false, execa);43test('result.all is defined, lines, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, false, execa);44test('result.all is defined, lines, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, false, execa);45test('result.all is defined, failure', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execa);46test('result.all is defined, encoding "buffer", failure', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execa);47test('result.all is defined, lines, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execa);48test('result.all is defined, lines, fd-specific one, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, true, execa);49test('result.all is defined, lines, fd-specific both, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, true, execa);50test('result.all is defined, stripFinalNewline, failure', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execa);45test('result.all is defined, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, true, execa);46test('result.all is defined, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, true, execa);51test('result.all is defined, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, true, execa);52test('result.all is defined, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, true, execa);53test('result.all is defined, encoding "buffer", stripFinalNewline, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execa);48test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, true, execa);49test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, true, execa);54test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, true, execa);55test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, true, execa);56test('result.all is defined, lines, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execa);57test('result.all is defined, lines, fd-specific one, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, true, execa);58test('result.all is defined, lines, fd-specific both, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, true, execa);51test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, true, execa);52test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, true, execa);59test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, true, execa);60test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, true, execa);61test('result.all is defined, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execaSync);62test('result.all is defined, encoding "buffer", sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execaSync);63test('result.all is defined, lines, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execaSync);64test('result.all is defined, lines, fd-specific one, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, false, execaSync);65test('result.all is defined, lines, fd-specific both, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, false, execaSync);66test('result.all is defined, stripFinalNewline, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execaSync);57test('result.all is defined, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, false, execaSync);58test('result.all is defined, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, false, execaSync);67test('result.all is defined, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, false, execaSync);68test('result.all is defined, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, false, execaSync);69test('result.all is defined, encoding "buffer", stripFinalNewline, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execaSync);60test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, false, execaSync);61test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, false, execaSync);70test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, false, execaSync);71test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, false, execaSync);72test('result.all is defined, lines, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execaSync);73test('result.all is defined, lines, fd-specific one, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, false, execaSync);74test('result.all is defined, lines, fd-specific both, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, false, execaSync);63test('result.all is defined, lines, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, false, execaSync);64test('result.all is defined, lines, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, false, execaSync);75test('result.all is defined, lines, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, false, execaSync);76test('result.all is defined, lines, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, false, execaSync);77test('result.all is defined, failure, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execaSync);78test('result.all is defined, encoding "buffer", failure, sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execaSync);79test('result.all is defined, lines, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execaSync);80test('result.all is defined, lines, fd-specific one, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdOne, false, true, execaSync);81test('result.all is defined, lines, fd-specific both, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', fdBoth, false, true, execaSync);82test('result.all is defined, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execaSync);69test('result.all is defined, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, true, execaSync);70test('result.all is defined, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, true, execaSync);83test('result.all is defined, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdOne, true, execaSync);84test('result.all is defined, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, fdBoth, true, execaSync);85test('result.all is defined, encoding "buffer", stripFinalNewline, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execaSync);72test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, true, execaSync);73test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, true, execaSync);86test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdOne, true, execaSync);87test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, fdBoth, true, execaSync);88test('result.all is defined, lines, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execaSync);89test('result.all is defined, lines, fd-specific one, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', fdOne, true, true, execaSync);90test('result.all is defined, lines, fd-specific both, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', fdBoth, true, true, execaSync);75test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, true, execaSync);76test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, true, execaSync);91test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdOne, true, execaSync);92test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, fdBoth, true, execaSync);9394test.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 lines
modified:test/verbose/output.js+8 added-6 removed
158 unmodified lines
159160test('Does not change subprocess.stdout', testStdioSame, 1);161test('Does not change subprocess.stderr', testStdioSame, 2);162163const testLines = async (t, stripFinalNewline, execaMethod) => {164 const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines: true, stripFinalNewline});163const 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};167168test('Prints stdout, "lines: true"', testLines, false, parentExecaAsync);169test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, parentExecaAsync);170test('Prints stdout, "lines: true", sync', testLines, false, parentExecaSync);171test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, parentExecaSync);168test('Prints stdout, "lines: true"', testLines, true, false, parentExecaAsync);169test('Prints stdout, "lines: true", fd-specific', testLines, {stdout: true}, false, parentExecaAsync);170test('Prints stdout, "lines: true", stripFinalNewline', testLines, true, true, parentExecaAsync);171test('Prints stdout, "lines: true", sync', testLines, true, false, parentExecaSync);172test('Prints stdout, "lines: true", fd-specific, sync', testLines, {stdout: true}, false, parentExecaSync);173test('Prints stdout, "lines: true", stripFinalNewline, sync', testLines, true, true, parentExecaSync);174175const 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 lines
modified:index.d.ts+85 added-20 removed
303 unmodified lines
304 : undefined305 : undefined;306307// Type of `result.stdout|stderr`308type StdioOutput<308type NonAllStdioOutput<309 FdNumber extends string,310 OptionsType extends CommonOptions = CommonOptions,311> = StdioOutputResult<FdNumber, IgnoresStreamOutput<FdNumber, OptionsType>, OptionsType>;311> = StdioOutput<FdNumber, FdNumber, FdNumber, OptionsType>;312313type StdioOutput<314 MainFdNumber extends string,315 ObjectFdNumber extends string,316 LinesFdNumber extends string,317 OptionsType extends CommonOptions = CommonOptions,318> = StdioOutputResult<319ObjectFdNumber,320LinesFdNumber,321IgnoresStreamOutput<MainFdNumber, OptionsType>,322OptionsType323>;324325type 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 >;337338type 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 ? Uint8Array
9 unmodified lines
354type 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;365344type 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>;366type AllMainFd<OptionsType extends CommonOptions = CommonOptions> = IgnoresStreamOutput<'1', OptionsType> extends true ? '2' : '1';367368type AllObjectFd<OptionsType extends CommonOptions = CommonOptions> = IsObjectStream<'1', OptionsType> extends true ? '1' : '2';369370type AllLinesFd<OptionsType extends CommonOptions = CommonOptions> = FdSpecificOption<OptionsType['lines'], '1'> extends true ? '1' : '2';371372// Type of `result.stdio`373type StdioArrayOutput<OptionsType extends CommonOptions = CommonOptions> = MapStdioOptions<StdioArrayOption<OptionsType>, OptionsType>;374375type 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 lines
399 WideOptions extends CommonOptions,400 StrictOptions extends CommonOptions,401> = WideOptions extends StrictOptions ? WideOptions : StrictOptions;402383type FdGenericOption<OptionType> = OptionType | {403// Options which can be fd-specific like `{verbose: {stdout: 'none', stderr: 'full'}}`404type FdGenericOption<OptionType = unknown> = OptionType | GenericOptionObject<OptionType>;405406type GenericOptionObject<OptionType = unknown> = {407 readonly [FdName in FromOption]?: OptionType408};409410// Retrieve fd-specific option's value411type FdSpecificOption<412 GenericOption extends FdGenericOption,413 FdNumber extends string,414> = GenericOption extends GenericOptionObject415 ? FdSpecificObjectOption<GenericOption, FdNumber>416 : GenericOption;417418type 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;426427type 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;449450type CommonOptions<IsSync extends boolean = boolean> = {451 /**452 Prefer locally installed binaries when looking for a binary to execute.453
128 unmodified lines
582 Set `result.stdout`, `result.stderr`, `result.all` and `result.stdio` as arrays of strings, splitting the subprocess' output into lines.583584 This cannot be used if the `encoding` option is binary.585586 By default, this applies to both `stdout` and `stderr`, but different values can also be passed.587588 @default false589 */525 readonly lines?: boolean;590 readonly lines?: FdGenericOption<boolean>;591592 /**593 Setting this to `false` resolves the promise with the error instead of rejecting it.594
244 unmodified lines
839840/**841Subprocess options.842778Some 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.843Some 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.844845@example846847```
5 unmodified lines
853854/**855Subprocess options, with synchronous methods.856792Some 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.857Some 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.858859@example860861```
35 unmodified lines
897 The output of the subprocess on `stdout`.898899 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>;902903 /**904 The output of the subprocess on `stderr`.905906 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>;909910 /**911 The output of the subprocess on `stdin`, `stdout`, `stderr` and other file descriptors.912
979 unmodified lines
modified:index.test-d.ts+108 added
1592 unmodified lines
1593execaSync('unicorns', {stripFinalNewline: {fd1: true}});1594execaSync('unicorns', {stripFinalNewline: {fd2: true}});1595execaSync('unicorns', {stripFinalNewline: {fd3: true}});1596expectError(execaSync('unicorns', {stripFinalNewline: {stdout: 'true'}}));1597execa('unicorns', {lines: {}});1598expectError(execa('unicorns', {lines: []}));1599execa('unicorns', {lines: {stdout: true}});1600execa('unicorns', {lines: {stderr: true}});1601execa('unicorns', {lines: {stdout: true, stderr: true} as const});1602execa('unicorns', {lines: {all: true}});1603execa('unicorns', {lines: {fd1: true}});1604execa('unicorns', {lines: {fd2: true}});1605execa('unicorns', {lines: {fd3: true}});1606expectError(execa('unicorns', {lines: {stdout: 'true'}}));1607execaSync('unicorns', {lines: {}});1608expectError(execaSync('unicorns', {lines: []}));1609execaSync('unicorns', {lines: {stdout: true}});1610execaSync('unicorns', {lines: {stderr: true}});1611execaSync('unicorns', {lines: {stdout: true, stderr: true} as const});1612execaSync('unicorns', {lines: {all: true}});1613execaSync('unicorns', {lines: {fd1: true}});1614execaSync('unicorns', {lines: {fd2: true}});1615execaSync('unicorns', {lines: {fd3: true}});1616expectError(execaSync('unicorns', {lines: {stdout: 'true'}}));16171618const linesStdoutResult = await execa('unicorns', {all: true, lines: {stdout: true}});1619expectType<string[]>(linesStdoutResult.stdout);1620expectType<string[]>(linesStdoutResult.stdio[1]);1621expectType<string>(linesStdoutResult.stderr);1622expectType<string>(linesStdoutResult.stdio[2]);1623expectType<string[]>(linesStdoutResult.all);16241625const linesStderrResult = await execa('unicorns', {all: true, lines: {stderr: true}});1626expectType<string>(linesStderrResult.stdout);1627expectType<string>(linesStderrResult.stdio[1]);1628expectType<string[]>(linesStderrResult.stderr);1629expectType<string[]>(linesStderrResult.stdio[2]);1630expectType<string[]>(linesStderrResult.all);16311632const linesFd1Result = await execa('unicorns', {all: true, lines: {fd1: true}});1633expectType<string[]>(linesFd1Result.stdout);1634expectType<string[]>(linesFd1Result.stdio[1]);1635expectType<string>(linesFd1Result.stderr);1636expectType<string>(linesFd1Result.stdio[2]);1637expectType<string[]>(linesFd1Result.all);16381639const linesFd2Result = await execa('unicorns', {all: true, lines: {fd2: true}});1640expectType<string>(linesFd2Result.stdout);1641expectType<string>(linesFd2Result.stdio[1]);1642expectType<string[]>(linesFd2Result.stderr);1643expectType<string[]>(linesFd2Result.stdio[2]);1644expectType<string[]>(linesFd2Result.all);16451646const linesAllResult = await execa('unicorns', {all: true, lines: {all: true}});1647expectType<string[]>(linesAllResult.stdout);1648expectType<string[]>(linesAllResult.stdio[1]);1649expectType<string[]>(linesAllResult.stderr);1650expectType<string[]>(linesAllResult.stdio[2]);1651expectType<string[]>(linesAllResult.all);16521653const linesFd3Result = await execa('unicorns', {all: true, lines: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1654expectType<string>(linesFd3Result.stdout);1655expectType<string>(linesFd3Result.stdio[1]);1656expectType<string>(linesFd3Result.stderr);1657expectType<string>(linesFd3Result.stdio[2]);1658expectType<string>(linesFd3Result.all);1659expectType<string[]>(linesFd3Result.stdio[3]);1660expectType<string>(linesFd3Result.stdio[4]);16611662const linesStdoutResultSync = execaSync('unicorns', {all: true, lines: {stdout: true}});1663expectType<string[]>(linesStdoutResultSync.stdout);1664expectType<string[]>(linesStdoutResultSync.stdio[1]);1665expectType<string>(linesStdoutResultSync.stderr);1666expectType<string>(linesStdoutResultSync.stdio[2]);1667expectType<string[]>(linesStdoutResultSync.all);16681669const linesStderrResultSync = execaSync('unicorns', {all: true, lines: {stderr: true}});1670expectType<string>(linesStderrResultSync.stdout);1671expectType<string>(linesStderrResultSync.stdio[1]);1672expectType<string[]>(linesStderrResultSync.stderr);1673expectType<string[]>(linesStderrResultSync.stdio[2]);1674expectType<string[]>(linesStderrResultSync.all);16751676const linesFd1ResultSync = execaSync('unicorns', {all: true, lines: {fd1: true}});1677expectType<string[]>(linesFd1ResultSync.stdout);1678expectType<string[]>(linesFd1ResultSync.stdio[1]);1679expectType<string>(linesFd1ResultSync.stderr);1680expectType<string>(linesFd1ResultSync.stdio[2]);1681expectType<string[]>(linesFd1ResultSync.all);16821683const linesFd2ResultSync = execaSync('unicorns', {all: true, lines: {fd2: true}});1684expectType<string>(linesFd2ResultSync.stdout);1685expectType<string>(linesFd2ResultSync.stdio[1]);1686expectType<string[]>(linesFd2ResultSync.stderr);1687expectType<string[]>(linesFd2ResultSync.stdio[2]);1688expectType<string[]>(linesFd2ResultSync.all);16891690const linesAllResultSync = execaSync('unicorns', {all: true, lines: {all: true}});1691expectType<string[]>(linesAllResultSync.stdout);1692expectType<string[]>(linesAllResultSync.stdio[1]);1693expectType<string[]>(linesAllResultSync.stderr);1694expectType<string[]>(linesAllResultSync.stdio[2]);1695expectType<string[]>(linesAllResultSync.all);16961697const linesFd3ResultSync = execaSync('unicorns', {all: true, lines: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe']});1698expectType<string>(linesFd3ResultSync.stdout);1699expectType<string>(linesFd3ResultSync.stdio[1]);1700expectType<string>(linesFd3ResultSync.stderr);1701expectType<string>(linesFd3ResultSync.stdio[2]);1702expectType<string>(linesFd3ResultSync.all);1703expectType<string[]>(linesFd3ResultSync.stdio[3]);1704expectType<string>(linesFd3ResultSync.stdio[4]);17051706expectError(execa('unicorns', {stdio: []}));1707expectError(execaSync('unicorns', {stdio: []}));1708expectError(execa('unicorns', {stdio: ['pipe']}));1709expectError(execaSync('unicorns', {stdio: ['pipe']}));
2303 unmodified lines
modified:readme.md+5 added-3 removed
829 unmodified lines
830Type: `object`831832This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).833834Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`stripFinalNewline`](#optionsstripfinalnewline), [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.834Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`lines`](#optionslines), [`stripFinalNewline`](#optionsstripfinalnewline), [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.835836```js837await execa('./run.js', {verbose: 'full'}) // Same value for stdout and stderr838await execa('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values
99 unmodified lines
938- the [`encoding`](#optionsencoding) option is binary.939940This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.941942By default, this applies to both `stdout` and `stderr`, but different values can also be passed.942By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).943944#### options.buffer945946Type: `boolean`\
117 unmodified lines
1064Set [`result.stdout`](#resultstdout), [`result.stderr`](#resultstdout), [`result.all`](#resultall) and [`result.stdio`](#resultstdio) as arrays of strings, splitting the subprocess' output into lines.10651066This cannot be used if the [`encoding`](#optionsencoding) option is binary.10671068By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).10691070#### options.encoding10711072Type: `string`\1073Default: `'utf8'`
14 unmodified lines
1088Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.10891090If the [`lines`](#optionslines) option is true, this applies to each output line instead.10911090By default, this applies to both `stdout` and `stderr`, but different values can also be passed.1092By default, this applies to both `stdout` and `stderr`, but [different values can also be passed](#options).10931094#### options.maxBuffer10951096Type: `number`\
247 unmodified lines