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
Provenance
- Commit
64d52db- Tree
c3d8dac- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
6f279c0
16 files changed+167 added−73 removed
modified:lib/arguments/options.js-2 removed
44 unmodified lines45464748494950515210 unmodified lines63646566686768697021 unmodified lines44 unmodified lines};
const addDefaultOptions = ({ buffer = true, stripFinalNewline = true, extendEnv = true, preferLocal = false, cwd, localDir = cwd,10 unmodified lines ...options}) => ({ ...options, buffer, stripFinalNewline, extendEnv, preferLocal, cwd, localDir,21 unmodified linesmodified:lib/arguments/specific.js+2 added-1 removed
73 unmodified lines74757677787980808173 unmodified lines
const DEFAULT_OPTIONS = { maxBuffer: 1000 * 1000 * 100, verbose: verboseDefault, stripFinalNewline: true,};
export const FD_SPECIFIC_OPTIONS = ['maxBuffer', 'verbose'];export const FD_SPECIFIC_OPTIONS = ['maxBuffer', 'verbose', 'stripFinalNewline'];modified:lib/return/output.js+7 added-3 removed
1123454567891011121314155 unmodified linesimport stripFinalNewline from 'strip-final-newline';import stripFinalNewlineFunction from 'strip-final-newline';import {logFinalResult} from '../verbose/complete.js';
export const stripNewline = (value, options) => options.stripFinalNewline && value !== undefined && !Array.isArray(value) ? stripFinalNewline(value)export const stripNewline = (value, {stripFinalNewline}, isAll, fdNumber) => getStripFinalNewline(stripFinalNewline, isAll, fdNumber) && value !== undefined && !Array.isArray(value) ? stripFinalNewlineFunction(value) : value;
export const getStripFinalNewline = (stripFinalNewline, isAll, fdNumber) => isAll ? stripFinalNewline[1] || stripFinalNewline[2] : stripFinalNewline[fdNumber];
export const handleResult = (result, verboseInfo, {reject}) => { logFinalResult(result, reject, verboseInfo);
if (result.failed && reject) {5 unmodified linesmodified:lib/stdio/output-sync.js+3 added-3 removed
29 unmodified lines30 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});35 36 if (shouldLogOutput({stdioItems, encoding, verboseInfo, fdNumber})) {37 const linesArray = splitLinesSync(serializedResult, false, objectMode);38 logLinesSync(linesArray, verboseInfo);25 unmodified lines64 return chunks;65 }66 };67 68-const serializeChunks = ({chunks, objectMode, encoding, lines, stripFinalNewline}) => {68+const serializeChunks = ({chunks, objectMode, encoding, lines, stripFinalNewline, fdNumber}) => {69 if (objectMode) {70 return {serializedResult: chunks};71 }72 2 unmodified lines75 }76 77 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 }81 82 return {serializedResult};83 };36 unmodified linesmodified:lib/stream/subprocess.js+3 added-1 removed
1 unmodified line2 import getStream, {getStreamAsArrayBuffer, getStreamAsArray} from 'get-stream';3 import {iterateForResult} from '../convert/loop.js';4 import {isArrayBuffer} from '../stdio/uint-array.js';5 import {shouldLogOutput, logLines} from '../verbose/output.js';6+import {getStripFinalNewline} from '../return/output.js';7 import {handleMaxBuffer} from './max-buffer.js';8 import {waitForStream, isInputFileDescriptor} from './wait.js';9 10 export const waitForSubprocessStream = async ({stream, fdNumber, encoding, buffer, maxBuffer, lines, isAll, allMixed, stripFinalNewline, verboseInfo, streamInfo}) => {23 unmodified lines34 await resumeStream(stream);35 return;36 }37 38+ 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 };42 43 // When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away39 unmodified linesmodified:lib/async.js+2 added-2 removed
80 unmodified lines81 allResult,82 ] = await getSubprocessResult({subprocess, options, context, verboseInfo, fileDescriptors, originalStreams, controller});83 controller.abort();84 85- 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 linesmodified:lib/sync.js+2 added-2 removed
56 unmodified lines57 }58 59 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 };65 66 const runSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {28 unmodified linesmodified:test/helpers/lines.js+1 added
18 unmodified lines19 const simpleFullUtf16Buffer = Buffer.from(simpleFull, 'utf16le');20 export const simpleFullUtf16Uint8Array = new Uint8Array(simpleFullUtf16Buffer);21 export const simpleFullEnd = `${simpleFull}\n`;22 const simpleFullEndBuffer = Buffer.from(simpleFullEnd);23+export const simpleFullEndChunks = [simpleFullEnd];24 export const simpleFullEndUtf16Inverted = simpleFullEndBuffer.toString('utf16le');25 export const simpleLines = ['aaa\n', 'bbb\n', 'ccc'];26 export const simpleFullEndLines = ['aaa\n', 'bbb\n', 'ccc\n'];27 export const noNewlinesFull = 'aaabbbccc';12 unmodified linesmodified:test/return/output.js+55 added-35 removed
1 unmodified line2 import {execa, execaSync} from '../../index.js';3 import {setFixtureDir} from '../helpers/fixtures-dir.js';4 import {fullStdio, getStdio} from '../helpers/stdio.js';5 import {noopGenerator} from '../helpers/generator.js';6+import {foobarString} from '../helpers/input.js';7 8 setFixtureDir();9 10 const 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);13 14 if (fdNumber === 1) {15 t.is(stdio[fdNumber], stdout);16 } else if (fdNumber === 2) {3 unmodified lines20 21 test('can return stdout', testOutput, 1, execa);22 test('can return stderr', testOutput, 2, execa);23 test('can return output stdio[*]', testOutput, 3, execa);23-test('can return stdout - sync', testOutput, 1, execaSync);24-test('can return stderr - sync', testOutput, 2, execaSync);25-test('can return output stdio[*] - sync', testOutput, 3, execaSync);24+test('can return stdout, sync', testOutput, 1, execaSync);25+test('can return stderr, sync', testOutput, 2, execaSync);26+test('can return output stdio[*], sync', testOutput, 3, execaSync);27 28 const 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 };32 33 test('cannot return stdin', testNoStdin, execa);33-test('cannot return stdin - sync', testNoStdin, execaSync);34+test('cannot return stdin, sync', testNoStdin, execaSync);35 36 test('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 });40 41 test('do not try to consume streams twice', async t => {12 unmodified lines54 t.deepEqual(stdio, [undefined, '', '']);55 };56 57 test('empty error.stdout/stderr/stdio', testEmptyErrorStdio, execa);57-test('empty error.stdout/stderr/stdio - sync', testEmptyErrorStdio, execaSync);58+test('empty error.stdout/stderr/stdio, sync', testEmptyErrorStdio, execaSync);59 60 const testUndefinedErrorStdio = async (t, execaMethod) => {61 const {stdout, stderr, stdio} = await execaMethod('empty.js', {stdio: 'ignore'});62 t.is(stdout, undefined);1 unmodified line64 t.deepEqual(stdio, [undefined, undefined, undefined]);65 };66 67 test('undefined error.stdout/stderr/stdio', testUndefinedErrorStdio, execa);67-test('undefined error.stdout/stderr/stdio - sync', testUndefinedErrorStdio, execaSync);68+test('undefined error.stdout/stderr/stdio, sync', testUndefinedErrorStdio, execaSync);69 70 const testEmptyAll = async (t, options, expectedValue, execaMethod) => {71 const {all} = await execaMethod('empty.js', options);72 t.is(all, expectedValue);23 unmodified lines96 t.deepEqual(stdio, [undefined, undefined, undefined]);97 };98 99 test('stdout/stderr/all/stdio on subprocess spawning errors', testSpawnError, execa);99-test('stdout/stderr/all/stdio on subprocess spawning errors - sync', testSpawnError, execaSync);100+test('stdout/stderr/all/stdio on subprocess spawning errors, sync', testSpawnError, execaSync);101 102 const testErrorOutput = async (t, execaMethod) => {103 const {failed, stdout, stderr, stdio} = await execaMethod('echo-fail.js', {...fullStdio, reject: false});104 t.true(failed);2 unmodified lines107 t.deepEqual(stdio, [undefined, 'stdout', 'stderr', 'fd3']);108 };109 110 test('error.stdout/stderr/stdio is defined', testErrorOutput, execa);110-test('error.stdout/stderr/stdio is defined - sync', testErrorOutput, execaSync);111+test('error.stdout/stderr/stdio is defined, sync', testErrorOutput, execaSync);112 113+// eslint-disable-next-line max-params112-const 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' : ''}`);114+const 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 };118 117-test('stripFinalNewline: undefined with stdout', testStripFinalNewline, 1, undefined, execa);118-test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, execa);119-test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, execa);120-test('stripFinalNewline: undefined with stderr', testStripFinalNewline, 2, undefined, execa);121-test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, execa);122-test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, execa);123-test('stripFinalNewline: undefined with stdio[*]', testStripFinalNewline, 3, undefined, execa);124-test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, execa);125-test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, execa);126-test('stripFinalNewline: undefined with stdout - sync', testStripFinalNewline, 1, undefined, execaSync);127-test('stripFinalNewline: true with stdout - sync', testStripFinalNewline, 1, true, execaSync);128-test('stripFinalNewline: false with stdout - sync', testStripFinalNewline, 1, false, execaSync);129-test('stripFinalNewline: undefined with stderr - sync', testStripFinalNewline, 2, undefined, execaSync);130-test('stripFinalNewline: true with stderr - sync', testStripFinalNewline, 2, true, execaSync);131-test('stripFinalNewline: false with stderr - sync', testStripFinalNewline, 2, false, execaSync);132-test('stripFinalNewline: undefined with stdio[*] - sync', testStripFinalNewline, 3, undefined, execaSync);133-test('stripFinalNewline: true with stdio[*] - sync', testStripFinalNewline, 3, true, execaSync);134-test('stripFinalNewline: false with stdio[*] - sync', testStripFinalNewline, 3, false, execaSync);119+test('stripFinalNewline: default with stdout', testStripFinalNewline, 1, undefined, true, execa);120+test('stripFinalNewline: true with stdout', testStripFinalNewline, 1, true, true, execa);121+test('stripFinalNewline: false with stdout', testStripFinalNewline, 1, false, false, execa);122+test('stripFinalNewline: default with stderr', testStripFinalNewline, 2, undefined, true, execa);123+test('stripFinalNewline: true with stderr', testStripFinalNewline, 2, true, true, execa);124+test('stripFinalNewline: false with stderr', testStripFinalNewline, 2, false, false, execa);125+test('stripFinalNewline: default with stdio[*]', testStripFinalNewline, 3, undefined, true, execa);126+test('stripFinalNewline: true with stdio[*]', testStripFinalNewline, 3, true, true, execa);127+test('stripFinalNewline: false with stdio[*]', testStripFinalNewline, 3, false, false, execa);128+test('stripFinalNewline: default with stdout, fd-specific', testStripFinalNewline, 1, {}, true, execa);129+test('stripFinalNewline: true with stdout, fd-specific', testStripFinalNewline, 1, {stdout: true}, true, execa);130+test('stripFinalNewline: false with stdout, fd-specific', testStripFinalNewline, 1, {stdout: false}, false, execa);131+test('stripFinalNewline: default with stderr, fd-specific', testStripFinalNewline, 2, {}, true, execa);132+test('stripFinalNewline: true with stderr, fd-specific', testStripFinalNewline, 2, {stderr: true}, true, execa);133+test('stripFinalNewline: false with stderr, fd-specific', testStripFinalNewline, 2, {stderr: false}, false, execa);134+test('stripFinalNewline: default with stdio[*], fd-specific', testStripFinalNewline, 3, {}, true, execa);135+test('stripFinalNewline: true with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: true}, true, execa);136+test('stripFinalNewline: false with stdio[*], fd-specific', testStripFinalNewline, 3, {fd3: false}, false, execa);137+test('stripFinalNewline: default with stdout, sync', testStripFinalNewline, 1, undefined, true, execaSync);138+test('stripFinalNewline: true with stdout, sync', testStripFinalNewline, 1, true, true, execaSync);139+test('stripFinalNewline: false with stdout, sync', testStripFinalNewline, 1, false, false, execaSync);140+test('stripFinalNewline: default with stderr, sync', testStripFinalNewline, 2, undefined, true, execaSync);141+test('stripFinalNewline: true with stderr, sync', testStripFinalNewline, 2, true, true, execaSync);142+test('stripFinalNewline: false with stderr, sync', testStripFinalNewline, 2, false, false, execaSync);143+test('stripFinalNewline: default with stdio[*], sync', testStripFinalNewline, 3, undefined, true, execaSync);144+test('stripFinalNewline: true with stdio[*], sync', testStripFinalNewline, 3, true, true, execaSync);145+test('stripFinalNewline: false with stdio[*], sync', testStripFinalNewline, 3, false, false, execaSync);146+test('stripFinalNewline: default with stdout, fd-specific, sync', testStripFinalNewline, 1, {}, true, execaSync);147+test('stripFinalNewline: true with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: true}, true, execaSync);148+test('stripFinalNewline: false with stdout, fd-specific, sync', testStripFinalNewline, 1, {stdout: false}, false, execaSync);149+test('stripFinalNewline: default with stderr, fd-specific, sync', testStripFinalNewline, 2, {}, true, execaSync);150+test('stripFinalNewline: true with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: true}, true, execaSync);151+test('stripFinalNewline: false with stderr, fd-specific, sync', testStripFinalNewline, 2, {stderr: false}, false, execaSync);152+test('stripFinalNewline: default with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {}, true, execaSync);153+test('stripFinalNewline: true with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: true}, true, execaSync);154+test('stripFinalNewline: false with stdio[*], fd-specific, sync', testStripFinalNewline, 3, {fd3: false}, false, execaSync);155 156 test('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 lines8 import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';9 import {10 simpleFull,11 simpleChunks,12+ simpleFullEndChunks,13 simpleFullUint8Array,14 simpleFullHex,15 simpleFullUtf16Uint8Array,16 simpleLines,20 unmodified lines37 test('"lines: true" splits lines, stdout, string', testStreamLines, 1, simpleFull, simpleLines, false, execa);38 test('"lines: true" splits lines, stderr, string', testStreamLines, 2, simpleFull, simpleLines, false, execa);39 test('"lines: true" splits lines, stdio[*], string', testStreamLines, 3, simpleFull, simpleLines, false, execa);40 test('"lines: true" splits lines, stdout, string, stripFinalNewline', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execa);41+test('"lines: true" splits lines, stdout, string, stripFinalNewline, fd-specific', testStreamLines, 1, simpleFull, noNewlinesChunks, {stdout: true}, execa);42 test('"lines: true" splits lines, stderr, string, stripFinalNewline', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execa);43+test('"lines: true" splits lines, stderr, string, stripFinalNewline, fd-specific', testStreamLines, 2, simpleFull, noNewlinesChunks, {stderr: true}, execa);44 test('"lines: true" splits lines, stdio[*], string, stripFinalNewline', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execa);45+test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, fd-specific', testStreamLines, 3, simpleFull, noNewlinesChunks, {fd3: true}, execa);46 test('"lines: true" splits lines, stdout, string, sync', testStreamLines, 1, simpleFull, simpleLines, false, execaSync);47 test('"lines: true" splits lines, stderr, string, sync', testStreamLines, 2, simpleFull, simpleLines, false, execaSync);48 test('"lines: true" splits lines, stdio[*], string, sync', testStreamLines, 3, simpleFull, simpleLines, false, execaSync);49 test('"lines: true" splits lines, stdout, string, stripFinalNewline, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, true, execaSync);50+test('"lines: true" splits lines, stdout, string, stripFinalNewline, fd-specific, sync', testStreamLines, 1, simpleFull, noNewlinesChunks, {stdout: true}, execaSync);51 test('"lines: true" splits lines, stderr, string, stripFinalNewline, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, true, execaSync);52+test('"lines: true" splits lines, stderr, string, stripFinalNewline, fd-specific, sync', testStreamLines, 2, simpleFull, noNewlinesChunks, {stderr: true}, execaSync);53 test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, true, execaSync);54+test('"lines: true" splits lines, stdio[*], string, stripFinalNewline, fd-specific, sync', testStreamLines, 3, simpleFull, noNewlinesChunks, {fd3: true}, execaSync);55 56 const testStreamLinesNoop = async (t, lines, execaMethod) => {57 const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});58 t.is(stdout, simpleFull);7 unmodified lines66 const bigStringNoNewlines = '.'.repeat(1e6);67 const bigStringNoNewlinesEnd = `${bigStringNoNewlines}\n`;68 69 // eslint-disable-next-line max-params63-const testStreamLinesGenerator = async (t, input, expectedLines, objectMode, binary, execaMethod) => {70+const 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 };78 72-test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, execa);73-test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, execa);74-test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, execa);75-test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, execa);76-test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false, execa);77-test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, execa);78-test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, execa);79-test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, execa);80-test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, execaSync);81-test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, execaSync);82-test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, execaSync);83-test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, execaSync);84-test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, false, execaSync);85-test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, execaSync);86-test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, execaSync);87-test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, execaSync);79+test('"lines: true" works with strings generators', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execa);80+test('"lines: true" works with strings generators, binary', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execa);81+test('"lines: true" works with big strings generators', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execa);82+test('"lines: true" works with big strings generators without newlines', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execa);83+test('"lines: true" is a noop with strings generators, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execa);84+test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execa);85+test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execa);86+test('"lines: true" is a noop with strings generators, binary, objectMode', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execa);87+test('"lines: true" is a noop big strings generators, objectMode', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execa);88+test('"lines: true" is a noop big strings generators without newlines, objectMode', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execa);89+test('"lines: true" works with strings generators, sync', testStreamLinesGenerator, simpleChunks, simpleFullEndLines, false, false, false, execaSync);90+test('"lines: true" works with strings generators, binary, sync', testStreamLinesGenerator, simpleChunks, simpleLines, false, true, false, execaSync);91+test('"lines: true" works with big strings generators, sync', testStreamLinesGenerator, [bigString], bigArray, false, false, false, execaSync);92+test('"lines: true" works with big strings generators without newlines, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlinesEnd], false, false, false, execaSync);93+test('"lines: true" is a noop with strings generators, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, false, execaSync);94+test('"lines: true" is a noop with strings generators, stripFinalNewline, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, true, execaSync);95+test('"lines: true" is a noop with strings generators, stripFinalNewline, fd-specific, objectMode, sync', testStreamLinesGenerator, simpleFullEndChunks, simpleFullEndChunks, true, false, {stdout: true}, execaSync);96+test('"lines: true" is a noop with strings generators, binary, objectMode, sync', testStreamLinesGenerator, simpleChunks, simpleChunks, true, true, false, execaSync);97+test('"lines: true" is a noop big strings generators, objectMode, sync', testStreamLinesGenerator, [bigString], [bigString], true, false, false, execaSync);98+test('"lines: true" is a noop big strings generators without newlines, objectMode, sync', testStreamLinesGenerator, [bigStringNoNewlines], [bigStringNoNewlines], true, false, false, execaSync);99 100 const testLinesObjectMode = async (t, execaMethod) => {101 const {stdout} = await execaMethod('noop.js', {102 stdout: getOutputsGenerator([foobarObject])(true),12 unmodified lines115 };116 117 test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execa);118 test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execa);119+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', {stdout: true}, execa);120 test('"lines: true" is a noop with "encoding: buffer"', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);121 test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execa);122+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: false}, execa);123 test('"lines: true" is a noop with "encoding: hex"', testEncoding, simpleFull, simpleFullHex, 'hex', false, execa);124 test('"lines: true" is a noop with "encoding: hex", stripFinalNewline', testEncoding, simpleFull, simpleFullHex, 'hex', true, execa);125+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, execa);126 test('"lines: true" is a noop with "encoding: utf16", sync', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', false, execaSync);127 test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', true, execaSync);128+test('"lines: true" is a noop with "encoding: utf16", stripFinalNewline, fd-specific, sync', testEncoding, simpleFullUtf16Uint8Array, noNewlinesChunks, 'utf16le', {stdout: true}, execaSync);129 test('"lines: true" is a noop with "encoding: buffer", sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);130 test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', false, execaSync);131+test('"lines: true" is a noop with "encoding: buffer", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullUint8Array, 'buffer', {stdout: false}, execaSync);132 test('"lines: true" is a noop with "encoding: hex", sync', testEncoding, simpleFull, simpleFullHex, 'hex', false, execaSync);133 test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, sync', testEncoding, simpleFull, simpleFullHex, 'hex', true, execaSync);134+test('"lines: true" is a noop with "encoding: hex", stripFinalNewline, fd-specific, sync', testEncoding, simpleFull, simpleFullHex, 'hex', {stdout: true}, execaSync);135 136 const testLinesNoBuffer = async (t, execaMethod) => {137 const {stdout} = await getSimpleChunkSubprocess(execaMethod, {buffer: false});138 t.is(stdout, undefined);107 unmodified linesmodified:test/stdio/split.js+1 added-1 removed
15 unmodified lines16 simpleFullUtf16Inverted,17 simpleFullUtf16Uint8Array,18 simpleChunksUint8Array,19 simpleFullEnd,20+ simpleFullEndChunks,21 simpleFullEndUtf16Inverted,22 simpleFullHex,23 simpleLines,24 simpleFullEndLines,2 unmodified lines27 } from '../helpers/lines.js';28 29 setFixtureDir();30 30-const simpleFullEndChunks = [simpleFullEnd];31 const windowsFull = 'aaa\r\nbbb\r\nccc';32 const windowsFullEnd = `${windowsFull}\r\n`;33 const windowsChunks = [windowsFull];34 const windowsLines = ['aaa\r\n', 'bbb\r\n', 'ccc'];328 unmodified linesmodified:test/stream/all.js+27 added
21 unmodified lines22 t.is(exitCode, isFailure ? 1 : 0);23 t.deepEqual(all, expectedOutput);24 };25 26+const stripOne = {stderr: true};27+const stripBoth = {stdout: true, stderr: true};28+29 test('result.all is defined', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execa);30 test('result.all is defined, encoding "buffer"', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execa);31 test('result.all is defined, lines', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execa);32 test('result.all is defined, stripFinalNewline', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execa);33+test('result.all is defined, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, false, execa);34+test('result.all is defined, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, false, execa);35 test('result.all is defined, encoding "buffer", stripFinalNewline', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execa);36+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, false, execa);37+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, false, execa);38 test('result.all is defined, lines, stripFinalNewline', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execa);39+test('result.all is defined, lines, stripFinalNewline, fd-specific one', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, false, execa);40+test('result.all is defined, lines, stripFinalNewline, fd-specific both', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, false, execa);41 test('result.all is defined, failure', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execa);42 test('result.all is defined, encoding "buffer", failure', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execa);43 test('result.all is defined, lines, failure', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execa);44 test('result.all is defined, stripFinalNewline, failure', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execa);45+test('result.all is defined, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, true, execa);46+test('result.all is defined, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, true, execa);47 test('result.all is defined, encoding "buffer", stripFinalNewline, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execa);48+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, true, execa);49+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, true, execa);50 test('result.all is defined, lines, stripFinalNewline, failure', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execa);51+test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, true, execa);52+test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, true, execa);53 test('result.all is defined, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, false, execaSync);54 test('result.all is defined, encoding "buffer", sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, false, execaSync);55 test('result.all is defined, lines, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, false, execaSync);56 test('result.all is defined, stripFinalNewline, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, false, execaSync);57+test('result.all is defined, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, false, execaSync);58+test('result.all is defined, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, false, execaSync);59 test('result.all is defined, encoding "buffer", stripFinalNewline, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, false, execaSync);60+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, false, execaSync);61+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, false, execaSync);62 test('result.all is defined, lines, stripFinalNewline, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, false, execaSync);63+test('result.all is defined, lines, stripFinalNewline, fd-specific one, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, false, execaSync);64+test('result.all is defined, lines, stripFinalNewline, fd-specific both, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, false, execaSync);65 test('result.all is defined, failure, sync', testAllBoth, doubleFoobarStringFull, 'utf8', false, false, true, execaSync);66 test('result.all is defined, encoding "buffer", failure, sync', testAllBoth, doubleFoobarUint8ArrayFull, 'buffer', false, false, true, execaSync);67 test('result.all is defined, lines, failure, sync', testAllBoth, doubleFoobarArrayFull, 'utf8', true, false, true, execaSync);68 test('result.all is defined, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, true, true, execaSync);69+test('result.all is defined, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripOne, true, execaSync);70+test('result.all is defined, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarString, 'utf8', false, stripBoth, true, execaSync);71 test('result.all is defined, encoding "buffer", stripFinalNewline, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, true, true, execaSync);72+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripOne, true, execaSync);73+test('result.all is defined, encoding "buffer", stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarUint8Array, 'buffer', false, stripBoth, true, execaSync);74 test('result.all is defined, lines, stripFinalNewline, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, true, true, execaSync);75+test('result.all is defined, lines, stripFinalNewline, fd-specific one, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripOne, true, execaSync);76+test('result.all is defined, lines, stripFinalNewline, fd-specific both, failure, sync', testAllBoth, doubleFoobarArray, 'utf8', true, stripBoth, true, execaSync);77 78 test.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 linesmodified:test/verbose/output.js+1 added-1 removed
159 unmodified lines160 test('Does not change subprocess.stdout', testStdioSame, 1);161 test('Does not change subprocess.stderr', testStdioSame, 2);162 163 const testLines = async (t, stripFinalNewline, execaMethod) => {164- const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines: true});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 };167 168 test('Prints stdout, "lines: true"', testLines, false, parentExecaAsync);187 unmodified linesmodified:index.d.ts+5 added-3 removed
534 unmodified lines535 Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.536 537 If the `lines` option is true, this applies to each output line instead.538 539+ By default, this applies to both `stdout` and `stderr`, but different values can also be passed.540+541 @default true542 */541- readonly stripFinalNewline?: boolean;543+ readonly stripFinalNewline?: FdGenericOption<boolean>;544 545 /**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 lines774 775 /**776 Subprocess options.777 776-Some 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.778+Some options are related to the subprocess output: `verbose`, `stripFinalNewline`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.779 780 @example781 782 ```5 unmodified lines788 789 /**790 Subprocess options, with synchronous methods.791 790-Some 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.792+Some options are related to the subprocess output: `verbose`, `stripFinalNewline`, `maxBuffer`. By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.793 794 @example795 796 ```1030 unmodified linesmodified:index.test-d.ts+20 added
1572 unmodified lines1573 execaSync('unicorns', {verbose: {fd1: 'none'}});1574 execaSync('unicorns', {verbose: {fd2: 'none'}});1575 execaSync('unicorns', {verbose: {fd3: 'none'}});1576 expectError(execaSync('unicorns', {verbose: {stdout: 'other'}}));1577+execa('unicorns', {stripFinalNewline: {}});1578+expectError(execa('unicorns', {stripFinalNewline: []}));1579+execa('unicorns', {stripFinalNewline: {stdout: true}});1580+execa('unicorns', {stripFinalNewline: {stderr: true}});1581+execa('unicorns', {stripFinalNewline: {stdout: true, stderr: true} as const});1582+execa('unicorns', {stripFinalNewline: {all: true}});1583+execa('unicorns', {stripFinalNewline: {fd1: true}});1584+execa('unicorns', {stripFinalNewline: {fd2: true}});1585+execa('unicorns', {stripFinalNewline: {fd3: true}});1586+expectError(execa('unicorns', {stripFinalNewline: {stdout: 'true'}}));1587+execaSync('unicorns', {stripFinalNewline: {}});1588+expectError(execaSync('unicorns', {stripFinalNewline: []}));1589+execaSync('unicorns', {stripFinalNewline: {stdout: true}});1590+execaSync('unicorns', {stripFinalNewline: {stderr: true}});1591+execaSync('unicorns', {stripFinalNewline: {stdout: true, stderr: true} as const});1592+execaSync('unicorns', {stripFinalNewline: {all: true}});1593+execaSync('unicorns', {stripFinalNewline: {fd1: true}});1594+execaSync('unicorns', {stripFinalNewline: {fd2: true}});1595+execaSync('unicorns', {stripFinalNewline: {fd3: true}});1596+expectError(execaSync('unicorns', {stripFinalNewline: {stdout: 'true'}}));1597 1598 expectError(execa('unicorns', {stdio: []}));1599 expectError(execaSync('unicorns', {stdio: []}));1600 expectError(execa('unicorns', {stdio: ['pipe']}));2304 unmodified linesmodified:readme.md+3 added-1 removed
829 unmodified lines830 Type: `object`831 832 This lists all options for [`execa()`](#execafile-arguments-options) and the [other methods](#methods).833 834-Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.834+Some options are related to the subprocess output: [`verbose`](#optionsverbose), [`stripFinalNewline`](#optionsstripfinalnewline), [`maxBuffer`](#optionsmaxbuffer). By default, those options apply to all file descriptors (`stdout`, `stderr`, etc.). A plain object can be passed instead to apply them to only `stdout`, `stderr`, `fd3`, etc.835 836 ```js837 await execa('./run.js', {verbose: 'full'}) // Same value for stdout and stderr838 await execa('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values247 unmodified lines1086 Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.1087 1088 If the [`lines`](#optionslines) option is true, this applies to each output line instead.1089 1090+By default, this applies to both `stdout` and `stderr`, but different values can also be passed.1091+1092 #### options.maxBuffer1093 1094 Type: `number`\1095 Default: `100_000_000`246 unmodified lines