Allow setting different `verbose` values for `stdout`/`stderr` (#970)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent fe330a9 · Browse files · 16 files·+194 added−57 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+194 added−57 removed
- tests:+129 added−28 removed
- other:+65 added−29 removed
Provenance
- Commit
6f279c0- Tree
152905c- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
fe330a9
16 files changed+194 added−57 removed
modified:lib/arguments/create.js+2 added-1 removed
1234567891049 unmodified lines606162636364import isPlainObject from 'is-plain-obj';import {execaCoreAsync} from '../async.js';import {execaCoreSync} from '../sync.js';import {normalizeArguments} from './normalize.js';import {isTemplateString, parseTemplates} from './template.js';import {FD_SPECIFIC_OPTIONS} from './specific.js';
export const createExeca = (mapArguments, boundOptions, deepOptions, setBoundExeca) => { const createNested = (mapArguments, boundOptions, setBoundExeca) => createExeca(mapArguments, boundOptions, deepOptions, setBoundExeca); const boundExeca = (...args) => callBoundExeca({mapArguments, deepOptions, boundOptions, setBoundExeca, createNested}, ...args);49 unmodified lines
return optionValue;};
const DEEP_OPTIONS = new Set(['env', 'maxBuffer']);const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);modified:lib/arguments/options.js+2 added-2 removed
9 unmodified lines1011121314141516171819192021222370 unmodified lines9 unmodified linesimport {validateEncoding, BINARY_ENCODINGS} from './encoding.js';import {handleNodeOption} from './node.js';import {joinCommand} from './escape.js';import {normalizeCwd, normalizeFileUrl} from './cwd.js';import {normalizeFdSpecificOptions} from './specific.js';import {normalizeFdSpecificOptions, normalizeFdSpecificOption} from './specific.js';
export const handleCommand = (filePath, rawArgs, rawOptions) => { const startTime = getStartTime(); const {command, escapedCommand} = joinCommand(filePath, rawArgs); const verboseInfo = getVerboseInfo(rawOptions); const verboseInfo = getVerboseInfo(normalizeFdSpecificOption(rawOptions, 'verbose')); logCommand(escapedCommand, verboseInfo, rawOptions); return {command, escapedCommand, startTime, verboseInfo};};
70 unmodified linesmodified:lib/arguments/specific.js+13 added-7 removed
1 import isPlainObject from 'is-plain-obj';2 import {STANDARD_STREAMS_ALIASES} from '../utils.js';3+import {verboseDefault} from '../verbose/info.js';4 5 export const normalizeFdSpecificOptions = options => {5- const optionBaseArray = Array.from({length: getStdioLength(options)});6-6 const optionsCopy = {...options};7+8 for (const optionName of FD_SPECIFIC_OPTIONS) {9- const optionArray = normalizeFdSpecificOption(options[optionName], [...optionBaseArray], optionName);10- optionsCopy[optionName] = addDefaultValue(optionArray, optionName);9+ optionsCopy[optionName] = normalizeFdSpecificOption(options, optionName);10 }11 12 return optionsCopy;13 };14 15+export const normalizeFdSpecificOption = (options, optionName) => {16+ const optionBaseArray = Array.from({length: getStdioLength(options)});17+ const optionArray = normalizeFdSpecificValue(options[optionName], optionBaseArray, optionName);18+ return addDefaultValue(optionArray, optionName);19+};20+21 const getStdioLength = ({stdio}) => Array.isArray(stdio)22 ? Math.max(stdio.length, STANDARD_STREAMS_ALIASES.length)23 : STANDARD_STREAMS_ALIASES.length;24 20-const FD_SPECIFIC_OPTIONS = ['maxBuffer'];21-22-const normalizeFdSpecificOption = (optionValue, optionArray, optionName) => isPlainObject(optionValue)25+const normalizeFdSpecificValue = (optionValue, optionArray, optionName) => isPlainObject(optionValue)26 ? normalizeOptionObject(optionValue, optionArray, optionName)27 : optionArray.fill(optionValue);28 29 const normalizeOptionObject = (optionValue, optionArray, optionName) => {43 unmodified lines73 : optionValue);74 75 const DEFAULT_OPTIONS = {76 maxBuffer: 1000 * 1000 * 100,77+ verbose: verboseDefault,78 };79+80+export const FD_SPECIFIC_OPTIONS = ['maxBuffer', 'verbose'];modified:lib/stdio/option.js+2 added-2 removed
39 unmodified lines40 41 return stdioOption;42 };43 44-const normalizeStdioSync = (stdioArray, buffer, verbose) => buffer || verbose === 'full'44+const normalizeStdioSync = (stdioArray, buffer, verbose) => buffer45 ? stdioArray46- : stdioArray.map((stdioOption, fdNumber) => fdNumber !== 0 && isOutputPipeOnly(stdioOption) ? 'ignore' : stdioOption);46+ : stdioArray.map((stdioOption, fdNumber) => fdNumber !== 0 && verbose[fdNumber] !== 'full' && isOutputPipeOnly(stdioOption) ? 'ignore' : stdioOption);47 48 const isOutputPipeOnly = stdioOption => stdioOption === 'pipe'49 || (Array.isArray(stdioOption) && stdioOption.every(item => item === 'pipe'));50 3 unmodified linesmodified:lib/verbose/complete.js+2 added-1 removed
1 import prettyMs from 'pretty-ms';2 import {gray} from 'yoctocolors';3 import {escapeLines} from '../arguments/escape.js';4 import {getDurationMs} from '../return/duration.js';5+import {isVerbose} from './info.js';6 import {verboseLog} from './log.js';7 import {logError} from './error.js';8 9 // When `verbose` is `short|full`, print each command's completion, duration and error12 unmodified lines22 });23 };24 25 const logResult = ({message, failed, reject, durationMs, verboseInfo: {verbose, verboseId}}) => {25- if (verbose === 'none') {26+ if (!isVerbose(verbose)) {27 return;28 }29 30 const icon = getIcon(failed, reject);16 unmodified linesmodified:lib/verbose/info.js+7 added-4 removed
12345347567891011121314151617import {debuglog} from 'node:util';
export const getVerboseInfo = ({verbose = verboseDefault}) => verbose === 'none' ? {verbose} : {verbose, verboseId: VERBOSE_ID++};export const verboseDefault = debuglog('execa').enabled ? 'full' : 'none';
const verboseDefault = debuglog('execa').enabled ? 'full' : 'none';export const getVerboseInfo = verbose => { const verboseId = isVerbose(verbose) ? VERBOSE_ID++ : undefined; return {verbose, verboseId};};
// Prepending the `pid` is useful when multiple commands print their output at the same time.// However, we cannot use the real PID since this is not available with `child_process.spawnSync()`.// Also, we cannot use the real PID if we want to print it before `child_process.spawn()` is run.// As a pro, it is shorter than a normal PID and never re-uses the same id.// As a con, it cannot be used to send signals.let VERBOSE_ID = 0n;
export const isVerbose = verbose => verbose.some(fdVerbose => fdVerbose !== 'none');modified:lib/verbose/output.js+1 added-1 removed
7 unmodified lines8 // `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`.12-export const shouldLogOutput = ({stdioItems, encoding, verboseInfo: {verbose}, fdNumber}) => verbose === 'full'12+export const shouldLogOutput = ({stdioItems, encoding, verboseInfo: {verbose}, fdNumber}) => verbose[fdNumber] === 'full'13 && !BINARY_ENCODINGS.has(encoding)14 && fdUsesVerbose(fdNumber)15 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))16 || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));42 unmodified linesmodified:lib/verbose/start.js+2 added-1 removed
123456678910112 unmodified linesimport {bold} from 'yoctocolors';import {isVerbose} from './info.js';import {verboseLog} from './log.js';
// When `verbose` is `short|full`, print each commandexport const logCommand = (escapedCommand, {verbose, verboseId}, {piped = false}) => { if (verbose === 'none') { if (!isVerbose(verbose)) { return; }
const icon = piped ? 'pipedCommand' : 'command';2 unmodified linesmodified:test/helpers/verbose.js+13 added-2 removed
5 unmodified lines6 7 const isWindows = platform === 'win32';8 export const QUOTE = isWindows ? '"' : '\'';9 10-const runErrorSubprocess = async (execaMethod, t, verbose) => {10+const runErrorSubprocess = async (execaMethod, t, verbose, expectExitCode = true) => {11 const subprocess = execaMethod('noop-fail.js', ['1', foobarString], {verbose});12 await t.throwsAsync(subprocess);13 const {stderr} = await subprocess.parent;14- if (verbose !== 'none') {14+ if (expectExitCode) {15 t.true(stderr.includes('exit code 2'));16 }17 18 return stderr;42 unmodified lines61 const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}]/gm, testTimestamp);62 const normalizeDuration = stderr => stderr.replaceAll(/\(done in [^)]+\)/g, '(done in 0ms)');63 64 export const getVerboseOption = (isVerbose, verbose = 'short') => ({verbose: isVerbose ? verbose : 'none'});65+66+export const fdNoneOption = {stdout: 'none', stderr: 'none'};67+export const fdShortOption = {stdout: 'short', stderr: 'none'};68+export const fdFullOption = {stdout: 'full', stderr: 'none'};69+export const fdStdoutNoneOption = {stdout: 'none', stderr: 'full'};70+export const fdStderrNoneOption = {stdout: 'full', stderr: 'none'};71+export const fdStderrShortOption = {stdout: 'none', stderr: 'short'};72+export const fdStderrFullOption = {stdout: 'none', stderr: 'full'};73+export const fd3NoneOption = {stdout: 'full', fd3: 'none'};74+export const fd3ShortOption = {stdout: 'none', fd3: 'short'};75+export const fd3FullOption = {stdout: 'none', fd3: 'full'};modified:test/verbose/complete.js+17 added-4 removed
13 unmodified lines14 getCompletionLine,15 getCompletionLines,16 testTimestamp,17 getVerboseOption,18+ fdNoneOption,19+ fdShortOption,20+ fdFullOption,21 } from '../helpers/verbose.js';22 23 setFixtureDir();24 3 unmodified lines28 };29 30 test('Prints completion, verbose "short"', testPrintCompletion, 'short', parentExecaAsync);31 test('Prints completion, verbose "full"', testPrintCompletion, 'full', parentExecaAsync);32+test('Prints completion, verbose "short", fd-specific', testPrintCompletion, fdShortOption, parentExecaAsync);33+test('Prints completion, verbose "full", fd-specific', testPrintCompletion, fdFullOption, parentExecaAsync);34 test('Prints completion, verbose "short", sync', testPrintCompletion, 'short', parentExecaSync);35 test('Prints completion, verbose "full", sync', testPrintCompletion, 'full', parentExecaSync);36+test('Prints completion, verbose "short", fd-specific, sync', testPrintCompletion, fdShortOption, parentExecaSync);37+test('Prints completion, verbose "full", fd-specific, sync', testPrintCompletion, fdFullOption, parentExecaSync);38 32-const testNoPrintCompletion = async (t, execaMethod) => {33- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});39+const testNoPrintCompletion = async (t, verbose, execaMethod) => {40+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});41 t.is(stderr, '');42 };43 37-test('Does not print completion, verbose "none"', testNoPrintCompletion, parentExecaAsync);38-test('Does not print completion, verbose "none", sync', testNoPrintCompletion, parentExecaSync);44+test('Does not print completion, verbose "none"', testNoPrintCompletion, 'none', parentExecaAsync);45+test('Does not print completion, verbose default"', testNoPrintCompletion, undefined, parentExecaAsync);46+test('Does not print completion, verbose "none", fd-specific', testNoPrintCompletion, fdNoneOption, parentExecaAsync);47+test('Does not print completion, verbose default", fd-specific', testNoPrintCompletion, {}, parentExecaAsync);48+test('Does not print completion, verbose "none", sync', testNoPrintCompletion, 'none', parentExecaSync);49+test('Does not print completion, verbose default", sync', testNoPrintCompletion, undefined, parentExecaSync);50+test('Does not print completion, verbose "none", fd-specific, sync', testNoPrintCompletion, fdNoneOption, parentExecaSync);51+test('Does not print completion, verbose default", fd-specific, sync', testNoPrintCompletion, {}, parentExecaSync);52 53 const testPrintCompletionError = async (t, execaMethod) => {54 const stderr = await execaMethod(t, 'short');55 t.is(getCompletionLine(stderr), `${testTimestamp} [0] × (done in 0ms)`);52 unmodified linesmodified:test/verbose/error.js+17 added-4 removed
12 unmodified lines13 getErrorLine,14 getErrorLines,15 testTimestamp,16 getVerboseOption,17+ fdNoneOption,18+ fdShortOption,19+ fdFullOption,20 } from '../helpers/verbose.js';21 22 setFixtureDir();23 5 unmodified lines29 };30 31 test('Prints error, verbose "short"', testPrintError, 'short', runErrorSubprocessAsync);32 test('Prints error, verbose "full"', testPrintError, 'full', runErrorSubprocessAsync);33+test('Prints error, verbose "short", fd-specific', testPrintError, fdShortOption, runErrorSubprocessAsync);34+test('Prints error, verbose "full", fd-specific', testPrintError, fdFullOption, runErrorSubprocessAsync);35 test('Prints error, verbose "short", sync', testPrintError, 'short', runErrorSubprocessSync);36 test('Prints error, verbose "full", sync', testPrintError, 'full', runErrorSubprocessSync);37+test('Prints error, verbose "short", fd-specific, sync', testPrintError, fdShortOption, runErrorSubprocessSync);38+test('Prints error, verbose "full", fd-specific, sync', testPrintError, fdFullOption, runErrorSubprocessSync);39 33-const testNoPrintError = async (t, execaMethod) => {34- const stderr = await execaMethod(t, 'none');40+const testNoPrintError = async (t, verbose, execaMethod) => {41+ const stderr = await execaMethod(t, verbose, false);42 t.is(getErrorLine(stderr), undefined);43 };44 38-test('Does not print error, verbose "none"', testNoPrintError, runErrorSubprocessAsync);39-test('Does not print error, verbose "none", sync', testNoPrintError, runErrorSubprocessSync);45+test('Does not print error, verbose "none"', testNoPrintError, 'none', runErrorSubprocessAsync);46+test('Does not print error, verbose default', testNoPrintError, undefined, runErrorSubprocessAsync);47+test('Does not print error, verbose "none", fd-specific', testNoPrintError, fdNoneOption, runErrorSubprocessAsync);48+test('Does not print error, verbose default, fd-specific', testNoPrintError, {}, runErrorSubprocessAsync);49+test('Does not print error, verbose "none", sync', testNoPrintError, 'none', runErrorSubprocessSync);50+test('Does not print error, verbose default, sync', testNoPrintError, undefined, runErrorSubprocessSync);51+test('Does not print error, verbose "none", fd-specific, sync', testNoPrintError, fdNoneOption, runErrorSubprocessSync);52+test('Does not print error, verbose default, fd-specific, sync', testNoPrintError, {}, runErrorSubprocessSync);53 54 const testPrintNoError = async (t, execaMethod) => {55 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'});56 t.is(getErrorLine(stderr), undefined);89 unmodified linesmodified:test/verbose/output.js+63 added-14 removed
15 unmodified lines16 getOutputLine,17 getOutputLines,18 testTimestamp,19 getVerboseOption,20+ fdShortOption,21+ fdFullOption,22+ fdStdoutNoneOption,23+ fdStderrNoneOption,24+ fdStderrShortOption,25+ fdStderrFullOption,26+ fd3NoneOption,27+ fd3ShortOption,28+ fd3FullOption,29 } from '../helpers/verbose.js';30 31 setFixtureDir();32 24-const testPrintOutput = async (t, fdNumber, execaMethod) => {25- const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: 'full'});33+const testPrintOutput = async (t, verbose, fdNumber, execaMethod) => {34+ const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose});35 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);36 };37 29-test('Prints stdout, verbose "full"', testPrintOutput, 1, parentExecaAsync);30-test('Prints stdout, verbose "full", sync', testPrintOutput, 1, parentExecaSync);31-test('Prints stderr, verbose "full"', testPrintOutput, 2, parentExecaAsync);32-test('Prints stderr, verbose "full", sync', testPrintOutput, 2, parentExecaSync);38+test('Prints stdout, verbose "full"', testPrintOutput, 'full', 1, parentExecaAsync);39+test('Prints stderr, verbose "full"', testPrintOutput, 'full', 2, parentExecaAsync);40+test('Prints stdout, verbose "full", fd-specific', testPrintOutput, fdFullOption, 1, parentExecaAsync);41+test('Prints stderr, verbose "full", fd-specific', testPrintOutput, fdStderrFullOption, 2, parentExecaAsync);42+test('Prints stdout, verbose "full", sync', testPrintOutput, 'full', 1, parentExecaSync);43+test('Prints stderr, verbose "full", sync', testPrintOutput, 'full', 2, parentExecaSync);44+test('Prints stdout, verbose "full", fd-specific, sync', testPrintOutput, fdFullOption, 1, parentExecaSync);45+test('Prints stderr, verbose "full", fd-specific, sync', testPrintOutput, fdStderrFullOption, 2, parentExecaSync);46 47 const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {48 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});49 t.is(getOutputLine(stderr), undefined);50 };51 52+test('Does not print stdout, verbose default', testNoPrintOutput, undefined, 1, parentExecaAsync);53 test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, parentExecaAsync);54 test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, parentExecaAsync);41-test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);42-test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);55+test('Does not print stderr, verbose default', testNoPrintOutput, undefined, 2, parentExecaAsync);56 test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, parentExecaAsync);57 test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, parentExecaAsync);45-test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);46-test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);58+test('Does not print stdio[*], verbose default', testNoPrintOutput, undefined, 3, parentExecaAsync);59 test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, parentExecaAsync);60 test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, parentExecaAsync);61 test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, parentExecaAsync);62+test('Does not print stdout, verbose default, fd-specific', testNoPrintOutput, {}, 1, parentExecaAsync);63+test('Does not print stdout, verbose "none", fd-specific', testNoPrintOutput, fdStdoutNoneOption, 1, parentExecaAsync);64+test('Does not print stdout, verbose "short", fd-specific', testNoPrintOutput, fdShortOption, 1, parentExecaAsync);65+test('Does not print stderr, verbose default, fd-specific', testNoPrintOutput, {}, 2, parentExecaAsync);66+test('Does not print stderr, verbose "none", fd-specific', testNoPrintOutput, fdStderrNoneOption, 2, parentExecaAsync);67+test('Does not print stderr, verbose "short", fd-specific', testNoPrintOutput, fdStderrShortOption, 2, parentExecaAsync);68+test('Does not print stdio[*], verbose default, fd-specific', testNoPrintOutput, {}, 3, parentExecaAsync);69+test('Does not print stdio[*], verbose "none", fd-specific', testNoPrintOutput, fd3NoneOption, 3, parentExecaAsync);70+test('Does not print stdio[*], verbose "short", fd-specific', testNoPrintOutput, fd3ShortOption, 3, parentExecaAsync);71+test('Does not print stdio[*], verbose "full", fd-specific', testNoPrintOutput, fd3FullOption, 3, parentExecaAsync);72+test('Does not print stdout, verbose default, sync', testNoPrintOutput, undefined, 1, parentExecaSync);73+test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, parentExecaSync);74+test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, parentExecaSync);75+test('Does not print stderr, verbose default, sync', testNoPrintOutput, undefined, 2, parentExecaSync);76+test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, parentExecaSync);77+test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, parentExecaSync);78+test('Does not print stdio[*], verbose default, sync', testNoPrintOutput, undefined, 3, parentExecaSync);79 test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, parentExecaSync);80 test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, parentExecaSync);81 test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, parentExecaSync);82+test('Does not print stdout, verbose default, fd-specific, sync', testNoPrintOutput, {}, 1, parentExecaSync);83+test('Does not print stdout, verbose "none", fd-specific, sync', testNoPrintOutput, fdStdoutNoneOption, 1, parentExecaSync);84+test('Does not print stdout, verbose "short", fd-specific, sync', testNoPrintOutput, fdShortOption, 1, parentExecaSync);85+test('Does not print stderr, verbose default, fd-specific, sync', testNoPrintOutput, {}, 2, parentExecaSync);86+test('Does not print stderr, verbose "none", fd-specific, sync', testNoPrintOutput, fdStderrNoneOption, 2, parentExecaSync);87+test('Does not print stderr, verbose "short", fd-specific, sync', testNoPrintOutput, fdStderrShortOption, 2, parentExecaSync);88+test('Does not print stdio[*], verbose default, fd-specific, sync', testNoPrintOutput, {}, 3, parentExecaSync);89+test('Does not print stdio[*], verbose "none", fd-specific, sync', testNoPrintOutput, fd3NoneOption, 3, parentExecaSync);90+test('Does not print stdio[*], verbose "short", fd-specific, sync', testNoPrintOutput, fd3ShortOption, 3, parentExecaSync);91+test('Does not print stdio[*], verbose "full", fd-specific, sync', testNoPrintOutput, fd3FullOption, 3, parentExecaSync);92 93 const testPrintError = async (t, execaMethod) => {94 const stderr = await execaMethod(t, 'full');95 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);215 unmodified lines311 test('Prints stdout, stdout "pipe", sync', testPrintOutputOptions, {stdout: 'pipe'}, parentExecaSync);312 test('Prints stdout, stdout null, sync', testPrintOutputOptions, {stdout: null}, parentExecaSync);313 test('Prints stdout, stdout ["pipe"], sync', testPrintOutputOptions, {stdout: ['pipe']}, parentExecaSync);314 276-const testPrintOutputNoBuffer = async (t, execaMethod) => {277- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'full', buffer: false});315+const testPrintOutputNoBuffer = async (t, verbose, execaMethod) => {316+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer: false});317 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);318 };319 281-test('Prints stdout, buffer: false', testPrintOutputNoBuffer, parentExecaAsync);282-test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, parentExecaSync);320+test('Prints stdout, buffer: false', testPrintOutputNoBuffer, 'full', parentExecaAsync);321+test('Prints stdout, buffer: false, fd-specific', testPrintOutputNoBuffer, fdFullOption, parentExecaAsync);322+test('Prints stdout, buffer: false, sync', testPrintOutputNoBuffer, 'full', parentExecaSync);323+test('Prints stdout, buffer: false, fd-specific, sync', testPrintOutputNoBuffer, fdFullOption, parentExecaSync);324 325+const testPrintOutputNoBufferFalse = async (t, execaMethod) => {326+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: fdStderrFullOption, buffer: false});327+ t.is(getOutputLine(stderr), undefined);328+};329+330+test('Does not print stdout, buffer: false, different fd', testPrintOutputNoBufferFalse, parentExecaAsync);331+test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, parentExecaSync);332+333 const testPrintOutputNoBufferTransform = async (t, isSync) => {334 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer: false, type: 'generator', isSync});335 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);336 };19 unmodified linesmodified:test/verbose/start.js+19 added-4 removed
12 unmodified lines13 getCommandLine,14 getCommandLines,15 testTimestamp,16 getVerboseOption,17+ fdNoneOption,18+ fdShortOption,19+ fdFullOption,20 } from '../helpers/verbose.js';21 22 setFixtureDir();23 3 unmodified lines27 };28 29 test('Prints command, verbose "short"', testPrintCommand, 'short', parentExecaAsync);30 test('Prints command, verbose "full"', testPrintCommand, 'full', parentExecaAsync);31+test('Prints command, verbose "short", fd-specific', testPrintCommand, fdShortOption, parentExecaAsync);32+test('Prints command, verbose "full", fd-specific', testPrintCommand, fdFullOption, parentExecaAsync);33 test('Prints command, verbose "short", sync', testPrintCommand, 'short', parentExecaSync);34 test('Prints command, verbose "full", sync', testPrintCommand, 'full', parentExecaSync);35+test('Prints command, verbose "short", fd-specific, sync', testPrintCommand, fdShortOption, parentExecaSync);36+test('Prints command, verbose "full", fd-specific, sync', testPrintCommand, fdFullOption, parentExecaSync);37 test('Prints command, verbose "short", worker', testPrintCommand, 'short', parentWorker);38 test('Prints command, verbose "full", work', testPrintCommand, 'full', parentWorker);39+test('Prints command, verbose "short", fd-specific, worker', testPrintCommand, fdShortOption, parentWorker);40+test('Prints command, verbose "full", fd-specific, work', testPrintCommand, fdFullOption, parentWorker);41 33-const testNoPrintCommand = async (t, execaMethod) => {34- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});42+const testNoPrintCommand = async (t, verbose, execaMethod) => {43+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});44 t.is(stderr, '');45 };46 38-test('Does not print command, verbose "none"', testNoPrintCommand, parentExecaAsync);39-test('Does not print command, verbose "none", sync', testNoPrintCommand, parentExecaSync);47+test('Does not print command, verbose "none"', testNoPrintCommand, 'none', parentExecaAsync);48+test('Does not print command, verbose default', testNoPrintCommand, undefined, parentExecaAsync);49+test('Does not print command, verbose "none", fd-specific', testNoPrintCommand, fdNoneOption, parentExecaAsync);50+test('Does not print command, verbose default, fd-specific', testNoPrintCommand, {}, parentExecaAsync);51+test('Does not print command, verbose "none", sync', testNoPrintCommand, 'none', parentExecaSync);52+test('Does not print command, verbose default, sync', testNoPrintCommand, undefined, parentExecaSync);53+test('Does not print command, verbose "none", fd-specific, sync', testNoPrintCommand, fdNoneOption, parentExecaSync);54+test('Does not print command, verbose default, fd-specific, sync', testNoPrintCommand, {}, parentExecaSync);55 56 const testPrintCommandError = async (t, execaMethod) => {57 const stderr = await execaMethod(t, 'short');58 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop-fail.js 1 ${foobarString}`);64 unmodified linesmodified:index.d.ts+9 added-7 removed
683 unmodified lines684 - the `encoding` option is binary.685 686 This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.687 688+ By default, this applies to both `stdout` and `stderr`, but different values can also be passed.689+690 @default 'none'691 */690- readonly verbose?: 'none' | 'short' | 'full';692+ readonly verbose?: FdGenericOption<'none' | 'short' | 'full'>;693 694 /**695 Kill the subprocess when the current process exits unless either:696 - the subprocess is `detached`.75 unmodified lines772 773 /**774 Subprocess options.775 774-Some options are related to the subprocess output: `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.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.777 778 @example779 780 ```779-await execa('./run.js', {maxBuffer: 1e6}) // Same value for stdout and stderr780-await execa('./run.js', {maxBuffer: {stdout: 1e4, stderr: 1e6}}) // Different values781+await execa('./run.js', {verbose: 'full'}) // Same value for stdout and stderr782+await execa('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values783 ```784 */785 export type Options = CommonOptions<false>;786 787 /**788 Subprocess options, with synchronous methods.789 788-Some options are related to the subprocess output: `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.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.791 792 @example793 794 ```793-execaSync('./run.js', {maxBuffer: 1e6}) // Same value for stdout and stderr794-execaSync('./run.js', {maxBuffer: {stdout: 1e4, stderr: 1e6}}) // Different values795+execaSync('./run.js', {verbose: 'full'}) // Same value for stdout and stderr796+execaSync('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values797 ```798 */799 export type SyncOptions = CommonOptions<true>;800 1024 unmodified linesmodified:index.test-d.ts+20 added
1552 unmodified lines1553 execaSync('unicorns', {maxBuffer: {fd1: 0}});1554 execaSync('unicorns', {maxBuffer: {fd2: 0}});1555 execaSync('unicorns', {maxBuffer: {fd3: 0}});1556 expectError(execaSync('unicorns', {maxBuffer: {stdout: '0'}}));1557+execa('unicorns', {verbose: {}});1558+expectError(execa('unicorns', {verbose: []}));1559+execa('unicorns', {verbose: {stdout: 'none'}});1560+execa('unicorns', {verbose: {stderr: 'none'}});1561+execa('unicorns', {verbose: {stdout: 'none', stderr: 'none'} as const});1562+execa('unicorns', {verbose: {all: 'none'}});1563+execa('unicorns', {verbose: {fd1: 'none'}});1564+execa('unicorns', {verbose: {fd2: 'none'}});1565+execa('unicorns', {verbose: {fd3: 'none'}});1566+expectError(execa('unicorns', {verbose: {stdout: 'other'}}));1567+execaSync('unicorns', {verbose: {}});1568+expectError(execaSync('unicorns', {verbose: []}));1569+execaSync('unicorns', {verbose: {stdout: 'none'}});1570+execaSync('unicorns', {verbose: {stderr: 'none'}});1571+execaSync('unicorns', {verbose: {stdout: 'none', stderr: 'none'} as const});1572+execaSync('unicorns', {verbose: {all: 'none'}});1573+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 1578 expectError(execa('unicorns', {stdio: []}));1579 expectError(execaSync('unicorns', {stdio: []}));1580 expectError(execa('unicorns', {stdio: ['pipe']}));2304 unmodified linesmodified:readme.md+5 added-3 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: [`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), [`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', {maxBuffer: 1e6}) // Same value for stdout and stderr838-await execa('./run.js', {maxBuffer: {stdout: 1e4, stderr: 1e6}}) // Different values837+await execa('./run.js', {verbose: 'full'}) // Same value for stdout and stderr838+await execa('./run.js', {verbose: {stdout: 'none', stderr: 'full'}}) // Different values839 ```840 841 #### options.reject842 95 unmodified lines938 - the [`encoding`](#optionsencoding) option is binary.939 940 This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.941 942+By default, this applies to both `stdout` and `stderr`, but different values can also be passed.943+944 #### options.buffer945 946 Type: `boolean`\947 Default: `true`392 unmodified lines