Skip to content
Myr

Allow setting different `stripFinalNewline` values for `stdout`/`stderr` (#971)

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

authored by ehmicky · committed by GitHub · parent 6f279c0 · Browse files · 16 files+167 added−73 removed
This commit

State

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

Diff stats

16 files+167 added−73 removed

  • tests:+120 added−55 removed
  • other:+47 added−18 removed

16 files+167 added−73 removed

modified:lib/arguments/options.js-2 removed
modified:lib/arguments/specific.js+2 added-1 removed
modified:lib/return/output.js+7 added-3 removed
modified:lib/stdio/output-sync.js+3 added-3 removed
29 unmodified lines
30 const chunks = runOutputGeneratorsSync([uint8ArrayResult], generators, encoding, state);31 const {32 serializedResult,33 finalResult = serializedResult,34 } = serializeChunks({chunks, objectMode, encoding, lines, stripFinalNewline});34 } = serializeChunks({chunks, objectMode, encoding, lines, stripFinalNewline, fdNumber});3536 if (shouldLogOutput({stdioItems, encoding, verboseInfo, fdNumber})) {37 const linesArray = splitLinesSync(serializedResult, false, objectMode);38 logLinesSync(linesArray, verboseInfo);
25 unmodified lines
64 return chunks;65 }66};6768const serializeChunks = ({chunks, objectMode, encoding, lines, stripFinalNewline}) => {68const serializeChunks = ({chunks, objectMode, encoding, lines, stripFinalNewline, fdNumber}) => {69 if (objectMode) {70 return {serializedResult: chunks};71 }72
2 unmodified lines
75 }7677 const serializedResult = joinToString(chunks, encoding);78 if (lines) {79 return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline, objectMode)};79 return {serializedResult, finalResult: splitLinesSync(serializedResult, !stripFinalNewline[fdNumber], objectMode)};80 }8182 return {serializedResult};83};
36 unmodified lines
modified:lib/stream/subprocess.js+3 added-1 removed
1 unmodified line
2import getStream, {getStreamAsArrayBuffer, getStreamAsArray} from 'get-stream';3import {iterateForResult} from '../convert/loop.js';4import {isArrayBuffer} from '../stdio/uint-array.js';5import {shouldLogOutput, logLines} from '../verbose/output.js';6import {getStripFinalNewline} from '../return/output.js';7import {handleMaxBuffer} from './max-buffer.js';8import {waitForStream, isInputFileDescriptor} from './wait.js';910export const waitForSubprocessStream = async ({stream, fdNumber, encoding, buffer, maxBuffer, lines, isAll, allMixed, stripFinalNewline, verboseInfo, streamInfo}) => {
23 unmodified lines
34 await resumeStream(stream);35 return;36 }3738 const stripFinalNewlineValue = getStripFinalNewline(stripFinalNewline, isAll, fdNumber);37 const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline, allMixed});39 const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline: stripFinalNewlineValue, allMixed});40 return getStreamContents({stream, iterable, fdNumber, encoding, maxBuffer, lines, isAll});41};4243// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away
39 unmodified lines
modified:lib/async.js+2 added-2 removed
80 unmodified lines
81 allResult,82 ] = await getSubprocessResult({subprocess, options, context, verboseInfo, fileDescriptors, originalStreams, controller});83 controller.abort();8485 const stdio = stdioResults.map(stdioResult => stripNewline(stdioResult, options));86 const all = stripNewline(allResult, options);85 const stdio = stdioResults.map((stdioResult, fdNumber) => stripNewline(stdioResult, options, false, fdNumber));86 const all = stripNewline(allResult, options, true);87 const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime});88 return handleResult(result, verboseInfo, options);89};90
17 unmodified lines
modified:lib/sync.js+2 added-2 removed
56 unmodified lines
57 }5859 const {resultError, exitCode, signal, timedOut, isMaxBuffer} = getSyncExitResult(syncResult, options);60 const {output, error = resultError} = transformOutputSync({fileDescriptors, syncResult, options, isMaxBuffer, verboseInfo});61 const stdio = output.map(stdioOutput => stripNewline(stdioOutput, options));62 const all = stripNewline(getAllSync(output, options), options);61 const stdio = output.map((stdioOutput, fdNumber) => stripNewline(stdioOutput, options, false, fdNumber));62 const all = stripNewline(getAllSync(output, options), options, true);63 return getSyncResult({error, exitCode, signal, timedOut, isMaxBuffer, stdio, all, options, command, escapedCommand, startTime});64};6566const runSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {
28 unmodified lines
modified:test/helpers/lines.js+1 added
18 unmodified lines
19const simpleFullUtf16Buffer = Buffer.from(simpleFull, 'utf16le');20export const simpleFullUtf16Uint8Array = new Uint8Array(simpleFullUtf16Buffer);21export const simpleFullEnd = `${simpleFull}\n`;22const simpleFullEndBuffer = Buffer.from(simpleFullEnd);23export const simpleFullEndChunks = [simpleFullEnd];24export const simpleFullEndUtf16Inverted = simpleFullEndBuffer.toString('utf16le');25export const simpleLines = ['aaa\n', 'bbb\n', 'ccc'];26export const simpleFullEndLines = ['aaa\n', 'bbb\n', 'ccc\n'];27export const noNewlinesFull = 'aaabbbccc';
12 unmodified lines
modified:test/return/output.js+55 added-35 removed
1 unmodified line
2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {fullStdio, getStdio} from '../helpers/stdio.js';5import {noopGenerator} from '../helpers/generator.js';6import {foobarString} from '../helpers/input.js';78setFixtureDir();910const testOutput = async (t, fdNumber, execaMethod) => {10 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar'], fullStdio);11 t.is(stdio[fdNumber], 'foobar');11 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], fullStdio);12 t.is(stdio[fdNumber], foobarString);1314 if (fdNumber === 1) {15 t.is(stdio[fdNumber], stdout);16 } else if (fdNumber === 2) {
3 unmodified lines
2021test('can return stdout', testOutput, 1, execa);22test('can return stderr', testOutput, 2, execa);23test('can return output stdio[*]', testOutput, 3, execa);23test('can return stdout - sync', testOutput, 1, execaSync);24test('can return stderr - sync', testOutput, 2, execaSync);25test('can return output stdio[*] - sync', testOutput, 3, execaSync);24test('can return stdout, sync', testOutput, 1, execaSync);25test('can return stderr, sync', testOutput, 2, execaSync);26test('can return output stdio[*], sync', testOutput, 3, execaSync);2728const testNoStdin = async (t, execaMethod) => {28 const {stdio} = await execaMethod('noop.js', ['foobar']);29 const {stdio} = await execaMethod('noop.js', [foobarString]);30 t.is(stdio[0], undefined);31};3233test('cannot return stdin', testNoStdin, execa);33test('cannot return stdin - sync', testNoStdin, execaSync);34test('cannot return stdin, sync', testNoStdin, execaSync);3536test('cannot return input stdio[*]', async t => {36 const {stdio} = await execa('stdin-fd.js', ['3'], getStdio(3, [['foobar']]));37 const {stdio} = await execa('stdin-fd.js', ['3'], getStdio(3, [[foobarString]]));38 t.is(stdio[3], undefined);39});4041test('do not try to consume streams twice', async t => {
12 unmodified lines
54 t.deepEqual(stdio, [undefined, '', '']);55};5657test('empty error.stdout/stderr/stdio', testEmptyErrorStdio, execa);57test('empty error.stdout/stderr/stdio - sync', testEmptyErrorStdio, execaSync);58test('empty error.stdout/stderr/stdio, sync', testEmptyErrorStdio, execaSync);5960const testUndefinedErrorStdio = async (t, execaMethod) => {61 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});62 t.is(stdout, undefined);
1 unmodified line
64 t.deepEqual(stdio, [undefined, undefined, undefined]);65};6667test('undefined error.stdout/stderr/stdio', testUndefinedErrorStdio, execa);67test('undefined error.stdout/stderr/stdio - sync', testUndefinedErrorStdio, execaSync);68test('undefined error.stdout/stderr/stdio, sync', testUndefinedErrorStdio, execaSync);6970const testEmptyAll = async (t, options, expectedValue, execaMethod) => {71 const {all} = await execaMethod('empty.js', options);72 t.is(all, expectedValue);
23 unmodified lines
96 t.deepEqual(stdio, [undefined, undefined, undefined]);97};9899test('stdout/stderr/all/stdio on subprocess spawning errors', testSpawnError, execa);99test('stdout/stderr/all/stdio on subprocess spawning errors - sync', testSpawnError, execaSync);100test('stdout/stderr/all/stdio on subprocess spawning errors, sync', testSpawnError, execaSync);101102const testErrorOutput = async (t, execaMethod) => {103 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});104 t.true(failed);
2 unmodified lines
107 t.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);108};109110test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);110test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);111test('error.stdout/stderr/stdio is defined, sync', testErrorOutput, execaSync);112113// eslint-disable-next-line max-params112const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, execaMethod) => {113 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, 'foobar\n'], {...fullStdio, stripFinalNewline});114 t.is(stdio[fdNumber], `foobar${stripFinalNewline === false ? '\n' : ''}`);114const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, shouldStrip, execaMethod) => {115 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, `${foobarString}\n`], {...fullStdio, stripFinalNewline});116 t.is(stdio[fdNumber], `${foobarString}${shouldStrip ? '' : '\n'}`);117};118117test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);118test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);119test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, execa);120test('stripFinalNewline: undefined with stderr', testStripFinalNewline, 2, undefined, execa);121test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, execa);122test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, execa);123test('stripFinalNewline: undefined with stdio[*]', testStripFinalNewline, 3, undefined, execa);124test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, execa);125test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, execa);126test('stripFinalNewline: undefined with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);127test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, true, execaSync);128test('stripFinalNewline: false with stdout - sync', testStripFinalNewline, 1, false, execaSync);129test('stripFinalNewline: undefined with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);130test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, true, execaSync);131test('stripFinalNewline: false with stderr - sync', testStripFinalNewline, 2, false, execaSync);132test('stripFinalNewline: undefined with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);133test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, true, execaSync);134test('stripFinalNewline: false with stdio[*] - sync', testStripFinalNewline, 3, false, execaSync);119test('stripFinalNewline: default with stdout', testStripFinalNewline, 1, undefined, true, execa);120test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, true, execa);121test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, false, execa);122test('stripFinalNewline: default with stderr', testStripFinalNewline, 2, undefined, true, execa);123test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, true, execa);124test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, false, execa);125test('stripFinalNewline: default with stdio[*]', testStripFinalNewline, 3, undefined, true, execa);126test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, true, execa);127test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, false, execa);128test('stripFinalNewline: default with stdout, fd-specific', testStripFinalNewline, 1, {}, true, execa);129test('stripFinalNewline: true with stdout, fd-specific', testStripFinalNewline, 1, {stdout: true}, true, execa);130test('stripFinalNewline: false with stdout, fd-specific', testStripFinalNewline, 1, {stdout: false}, false, execa);131test('stripFinalNewline: default with stderr, fd-specific', testStripFinalNewline, 2, {}, true, execa);132test('stripFinalNewline: true with stderr, fd-specific', testStripFinalNewline, 2, {stderr: true}, true, execa);133test('stripFinalNewline: false with stderr, fd-specific', testStripFinalNewline, 2, {stderr: false}, false, execa);134test('stripFinalNewline: default with stdio[*], fd-specific', testStripFinalNewline, 3, {}, true, execa);135test('stripFinalNewline: true with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: true}, true, execa);136test('stripFinalNewline: false with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: false}, false, execa);137test('stripFinalNewline: default with stdout, sync', testStripFinalNewline, 1, undefined, true, execaSync);138test('stripFinalNewline: true with stdout, sync', testStripFinalNewline, 1, true, true, execaSync);139test('stripFinalNewline: false with stdout, sync', testStripFinalNewline, 1, false, false, execaSync);140test('stripFinalNewline: default with stderr, sync', testStripFinalNewline, 2, undefined, true, execaSync);141test('stripFinalNewline: true with stderr, sync', testStripFinalNewline, 2, true, true, execaSync);142test('stripFinalNewline: false with stderr, sync', testStripFinalNewline, 2, false, false, execaSync);143test('stripFinalNewline: default with stdio[*], sync', testStripFinalNewline, 3, undefined, true, execaSync);144test('stripFinalNewline: true with stdio[*], sync', testStripFinalNewline, 3, true, true, execaSync);145test('stripFinalNewline: false with stdio[*], sync', testStripFinalNewline, 3, false, false, execaSync);146test('stripFinalNewline: default with stdout, fd-specific, sync', testStripFinalNewline, 1, {}, true, execaSync);147test('stripFinalNewline: true with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: true}, true, execaSync);148test('stripFinalNewline: false with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: false}, false, execaSync);149test('stripFinalNewline: default with stderr, fd-specific, sync', testStripFinalNewline, 2, {}, true, execaSync);150test('stripFinalNewline: true with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: true}, true, execaSync);151test('stripFinalNewline: false with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: false}, false, execaSync);152test('stripFinalNewline: default with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {}, true, execaSync);153test('stripFinalNewline: true with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: true}, true, execaSync);154test('stripFinalNewline: false with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: false}, false, execaSync);155156test('stripFinalNewline is not used in objectMode', async t => {137 const {stdout} = await execa('noop-fd.js', ['1', 'foobar\n'], {stripFinalNewline: true, stdout: noopGenerator(true, false, true)});138 t.deepEqual(stdout, ['foobar\n']);157 const {stdout} = await execa('noop-fd.js', ['1', `${foobarString}\n`], {stripFinalNewline: true, stdout: noopGenerator(true, false, true)});158 t.deepEqual(stdout, [`${foobarString}\n`]);159});
modified:test/stdio/lines.js+35 added-18 removed
7 unmodified lines
8import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';9import {10 simpleFull,11 simpleChunks,12 simpleFullEndChunks,13 simpleFullUint8Array,14 simpleFullHex,15 simpleFullUtf16Uint8Array,16 simpleLines,
20 unmodified lines
37test('"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);5556const testStreamLinesNoop = async (t, lines, execaMethod) => {57 const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});58 t.is(stdout, simpleFull);
7 unmodified lines
66const bigStringNoNewlines = '.'.repeat(1e6);67const bigStringNoNewlinesEnd = `${bigStringNoNewlines}\n`;6869// eslint-disable-next-line max-params63const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary, execaMethod) => {70const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary, stripFinalNewline, execaMethod) => {71 const {stdout} = await execaMethod('noop.js', {72 stdout: getOutputsGenerator(input)(objectMode, binary),73 lines: true,67 stripFinalNewline: false,74 stripFinalNewline,75 });76 t.deepEqual(stdout, expectedLines);77};7872test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, execa);73test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, execa);74test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, execa);75test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, execa);76test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false, execa);77test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, execa);78test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, execa);79test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, execa);80test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, execaSync);81test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, execaSync);82test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, execaSync);83test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, execaSync);84test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false, execaSync);85test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, execaSync);86test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, execaSync);87test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, execaSync);79test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execa);80test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execa);81test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execa);82test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execa);83test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execa);84test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execa);85test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execa);86test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execa);87test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execa);88test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execa);89test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execaSync);90test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execaSync);91test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execaSync);92test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execaSync);93test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execaSync);94test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execaSync);95test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execaSync);96test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execaSync);97test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execaSync);98test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync);99100const testLinesObjectMode = async (t, execaMethod) => {101 const {stdout} = await execaMethod('noop.js', {102 stdout: getOutputsGenerator([foobarObject])(true),
12 unmodified lines
115};116117test('"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);135136const testLinesNoBuffer = async (t, execaMethod) => {137 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {buffer: false});138 t.is(stdout, undefined);
107 unmodified lines
modified:test/stdio/split.js+1 added-1 removed
15 unmodified lines
16 simpleFullUtf16Inverted,17 simpleFullUtf16Uint8Array,18 simpleChunksUint8Array,19 simpleFullEnd,20 simpleFullEndChunks,21 simpleFullEndUtf16Inverted,22 simpleFullHex,23 simpleLines,24 simpleFullEndLines,
2 unmodified lines
27} from '../helpers/lines.js';2829setFixtureDir();3030const simpleFullEndChunks = [simpleFullEnd];31const windowsFull = 'aaa\r\nbbb\r\nccc';32const windowsFullEnd = `${windowsFull}\r\n`;33const windowsChunks = [windowsFull];34const windowsLines = ['aaa\r\n', 'bbb\r\n', 'ccc'];
328 unmodified lines
modified:test/stream/all.js+27 added
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};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, 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, 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, lines, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', true, 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);41test('result.all is defined, failure', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execa);42test('result.all is defined, encoding "buffer", failure', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execa);43test('result.all is defined, lines, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execa);44test('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);47test('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);50test('result.all is defined, lines, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', true, 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);53test('result.all is defined, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execaSync);54test('result.all is defined, encoding "buffer", sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execaSync);55test('result.all is defined, lines, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execaSync);56test('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);59test('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);62test('result.all is defined, lines, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', true, 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);65test('result.all is defined, failure, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execaSync);66test('result.all is defined, encoding "buffer", failure, sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execaSync);67test('result.all is defined, lines, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execaSync);68test('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);71test('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);74test('result.all is defined, lines, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, 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);7778test.serial('result.all shows both `stdout` and `stderr` intermixed', async t => {79 const {all} = await execa('noop-132.js', {all: true});80 t.is(all, '1\n2\n3');
75 unmodified lines
modified:test/verbose/output.js+1 added-1 removed
159 unmodified lines
160test('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});164 const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines: true, stripFinalNewline});165 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));166};167168test('Prints stdout, "lines: true"', testLines, false, parentExecaAsync);
187 unmodified lines
modified:index.d.ts+5 added-3 removed
534 unmodified lines
535 Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.536537 If the `lines` option is true, this applies to each output line instead.538539 By default, this applies to both `stdout` and `stderr`, but different values can also be passed.540541 @default true542 */541 readonly stripFinalNewline?: boolean;543 readonly stripFinalNewline?: FdGenericOption<boolean>;544545 /**546 If `true`, the subprocess uses both the `env` option and the current process' environment variables ([`process.env`](https://nodejs.org/api/process.html#processenv)).547 If `false`, only the `env` option is used, not `process.env`.
226 unmodified lines
774775/**776Subprocess options.777776Some options are related to the subprocess output: `verbose`, `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.778Some 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.779780@example781782```
5 unmodified lines
788789/**790Subprocess options, with synchronous methods.791790Some options are related to the subprocess output: `verbose`, `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.792Some 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.793794@example795796```
1030 unmodified lines
modified:index.test-d.ts+20 added
1572 unmodified lines
1573execaSync('unicorns', {verbose: {fd1: 'none'}});1574execaSync('unicorns', {verbose: {fd2: 'none'}});1575execaSync('unicorns', {verbose: {fd3: 'none'}});1576expectError(execaSync('unicorns', {verbose: {stdout: 'other'}}));1577execa('unicorns', {stripFinalNewline: {}});1578expectError(execa('unicorns', {stripFinalNewline: []}));1579execa('unicorns', {stripFinalNewline: {stdout: true}});1580execa('unicorns', {stripFinalNewline: {stderr: true}});1581execa('unicorns', {stripFinalNewline: {stdout: true, stderr: true} as const});1582execa('unicorns', {stripFinalNewline: {all: true}});1583execa('unicorns', {stripFinalNewline: {fd1: true}});1584execa('unicorns', {stripFinalNewline: {fd2: true}});1585execa('unicorns', {stripFinalNewline: {fd3: true}});1586expectError(execa('unicorns', {stripFinalNewline: {stdout: 'true'}}));1587execaSync('unicorns', {stripFinalNewline: {}});1588expectError(execaSync('unicorns', {stripFinalNewline: []}));1589execaSync('unicorns', {stripFinalNewline: {stdout: true}});1590execaSync('unicorns', {stripFinalNewline: {stderr: true}});1591execaSync('unicorns', {stripFinalNewline: {stdout: true, stderr: true} as const});1592execaSync('unicorns', {stripFinalNewline: {all: true}});1593execaSync('unicorns', {stripFinalNewline: {fd1: true}});1594execaSync('unicorns', {stripFinalNewline: {fd2: true}});1595execaSync('unicorns', {stripFinalNewline: {fd3: true}});1596expectError(execaSync('unicorns', {stripFinalNewline: {stdout: 'true'}}));15971598expectError(execa('unicorns', {stdio: []}));1599expectError(execaSync('unicorns', {stdio: []}));1600expectError(execa('unicorns', {stdio: ['pipe']}));
2304 unmodified lines
modified:readme.md+3 added-1 removed
829 unmodified lines
830Type: `object`831832This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).833834Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`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), [`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
247 unmodified lines
1086Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.10871088If the [`lines`](#optionslines) option is true, this applies to each output line instead.10891090By default, this applies to both `stdout` and `stderr`, but different values can also be passed.10911092#### options.maxBuffer10931094Type: `number`\1095Default: `100_000_000`
246 unmodified lines