Skip to content
Myr

Refactor `all` option (#975)

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

authored by ehmicky · committed by GitHub · parent 4940511 · Browse files · 10 files+23 added−23 removed
This commit

State

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

Diff stats

10 files+23 added−23 removed

  • other:+23 added−23 removed

10 files+23 added−23 removed

modified:lib/return/output.js+2 added-2 removed
modified:lib/stdio/output-sync.js+2 added-2 removed
modified:lib/stream/all.js+1 added-2 removed
modified:lib/stream/max-buffer.js+2 added-2 removed
1import {MaxBufferError} from 'get-stream';2import {getStreamName} from '../utils.js';34export const handleMaxBuffer = ({error, stream, readableObjectMode, lines, encoding, fdNumber, isAll}) => {4export const handleMaxBuffer = ({error, stream, readableObjectMode, lines, encoding, fdNumber}) => {5 if (!(error instanceof MaxBufferError)) {6 throw error;7 }89 if (isAll) {9 if (fdNumber === 'all') {10 return error;11 }1213 const unit = getMaxBufferUnit(readableObjectMode, lines, encoding);
42 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: buffer[fdNumber], maxBuffer: maxBuffer[fdNumber], lines: lines[fdNumber], isAll: false, allMixed: false, stripFinalNewline, verboseInfo, streamInfo}));59 subprocess.stdio.map((stream, fdNumber) => waitForSubprocessStream({stream, fdNumber, encoding, buffer: buffer[fdNumber], maxBuffer: maxBuffer[fdNumber], lines: lines[fdNumber], 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:lib/stream/subprocess.js+8 added-8 removed
5 unmodified lines
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}) => {10export const waitForSubprocessStream = async ({stream, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}) => {11 if (!stream) {12 return;13 }1415 const onStreamEnd = waitForStream(stream, fdNumber, streamInfo);16 const [output] = await Promise.all([17 waitForDefinedStream({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, isAll, allMixed, stripFinalNewline, verboseInfo, streamInfo}),17 waitForDefinedStream({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}),18 onStreamEnd,19 ]);20 return output;21};2223const waitForDefinedStream = async ({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, isAll, allMixed, stripFinalNewline, verboseInfo, streamInfo, streamInfo: {fileDescriptors}}) => {23const waitForDefinedStream = async ({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo, streamInfo: {fileDescriptors}}) => {24 if (isInputFileDescriptor(streamInfo, fdNumber)) {25 return;26 }2728 if (!isAll && shouldLogOutput({stdioItems: fileDescriptors[fdNumber].stdioItems, encoding, verboseInfo, fdNumber})) {28 if (shouldLogOutput({stdioItems: fileDescriptors[fdNumber]?.stdioItems, encoding, verboseInfo, fdNumber})) {29 const linesIterable = iterateForResult({stream, onStreamEnd, lines: true, encoding, stripFinalNewline: true, allMixed});30 logLines(linesIterable, stream, verboseInfo);31 }32
1 unmodified line
34 await resumeStream(stream);35 return;36 }3738 const stripFinalNewlineValue = getStripFinalNewline(stripFinalNewline, isAll, fdNumber);38 const stripFinalNewlineValue = getStripFinalNewline(stripFinalNewline, fdNumber);39 const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline: stripFinalNewlineValue, allMixed});40 return getStreamContents({stream, iterable, fdNumber, encoding, maxBuffer, lines, isAll});40 return getStreamContents({stream, iterable, fdNumber, encoding, maxBuffer, lines});41};4243// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away44// See https://github.com/sindresorhus/execa/issues/730 and https://github.com/sindresorhus/execa/pull/729#discussion_r1465496310
3 unmodified lines
48 stream.resume();49 }50};5152const getStreamContents = async ({stream, stream: {readableObjectMode}, iterable, fdNumber, encoding, maxBuffer, lines, isAll}) => {52const getStreamContents = async ({stream, stream: {readableObjectMode}, iterable, fdNumber, encoding, maxBuffer, lines}) => {53 try {54 if (readableObjectMode || lines) {55 return await getStreamAsArray(iterable, {maxBuffer});56 }
3 unmodified lines
60 }6162 return await getStream(iterable, {maxBuffer});63 } catch (error) {64 return handleBufferedData(handleMaxBuffer({error, stream, readableObjectMode, lines, encoding, fdNumber, isAll}));64 return handleBufferedData(handleMaxBuffer({error, stream, readableObjectMode, lines, encoding, fdNumber}));65 }66};6768// On failure, `result.stdout|stderr|all` should contain the currently buffered stream
14 unmodified lines
modified:lib/stream/wait.js+1 added-1 removed
79 unmodified lines
80// For example, `subprocess.stdin` is technically a Duplex, but can only be used as a writable.81// Therefore, we need to use the file descriptor's direction (`stdin` is input, `stdout` is output, etc.).82// However, while `subprocess.std*` and transforms follow that direction, any stream passed the `std*` option has the opposite direction.83// For example, `subprocess.stdin` is a writable, but the `stdin` option is a readable.84export const isInputFileDescriptor = ({fileDescriptors}, fdNumber) => fileDescriptors[fdNumber].direction === 'input';84export const isInputFileDescriptor = ({fileDescriptors}, fdNumber) => fdNumber !== 'all' && fileDescriptors[fdNumber].direction === 'input';8586// When `stream.destroy()` is called without an `error` argument, stream is aborted.87// This is the only way to abort a readable stream, which can be useful in some instances.88// Therefore, we ignore this error on readable streams.
8 unmodified lines
modified:lib/verbose/output.js+2 added-1 removed
7 unmodified lines
8// `ipc` cannot use piping.9// `inherit` would result in double printing.10// They can also lead to double printing when passing file descriptor integers or `process.std*`.11// This only leaves with `pipe` and `overlapped`.12export const shouldLogOutput = ({stdioItems, encoding, verboseInfo: {verbose}, fdNumber}) => verbose[fdNumber] === 'full'12export const shouldLogOutput = ({stdioItems, encoding, verboseInfo: {verbose}, fdNumber}) => fdNumber !== 'all'13 && verbose[fdNumber] === 'full'14 && !BINARY_ENCODINGS.has(encoding)15 && fdUsesVerbose(fdNumber)16 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))17 || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));
42 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, fdNumber) => stripNewline(stdioResult, options, false, fdNumber));86 const all = stripNewline(allResult, options, true);85 const stdio = stdioResults.map((stdioResult, fdNumber) => stripNewline(stdioResult, options, fdNumber));86 const all = stripNewline(allResult, options, 'all');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, fdNumber) => stripNewline(stdioOutput, options, false, fdNumber));62 const all = stripNewline(getAllSync(output, options), options, true);61 const stdio = output.map((stdioOutput, fdNumber) => stripNewline(stdioOutput, options, fdNumber));62 const all = stripNewline(getAllSync(output, options), options, 'all');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