Print output with `verbose` option (#884)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 231beaf · Browse files · 34 files·+554 added−87 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
34 files+554 added−87 removed
- tests:+387 added−42 removed
- other:+167 added−45 removed
Provenance
- Commit
6fda30f- Tree
422501f- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
231beaf
34 files changed+554 added−87 removed
modified:docs/scripts.md+4 added-2 removed
402 unmodified lines403 ```js404 // Execa405 import {$ as $_} from 'execa';406 407+// `verbose: 'short'` is also available407-const $ = $_({verbose: true});408+const $ = $_({verbose: 'full'});409 410 await $`echo example`;411 ```412 5 unmodified lines418 419 Which prints:420 421 ```421-[19:49:00.360] $ echo example422+[19:49:00.360] [0] $ echo example423+example424 ```425 426 ### Piping stdout to another command427 290 unmodified linesmodified:lib/arguments/options.js+4 added-2 removed
4 unmodified lines567891011121325 unmodified lines3940414243424344454647484967 unmodified lines4 unmodified linesimport isPlainObject from 'is-plain-obj';import {normalizeForceKillAfterDelay} from '../exit/kill.js';import {validateTimeout} from '../exit/timeout.js';import {logCommand} from '../verbose/start.js';import {getVerboseInfo} from '../verbose/info.js';import {handleNodeOption} from './node.js';import {joinCommand} from './escape.js';import {normalizeCwd, safeNormalizeFileUrl, normalizeFileUrl} from './cwd.js';
25 unmodified lines};
export const handleCommand = (filePath, rawArgs, rawOptions) => { const {command, escapedCommand} = joinCommand(filePath, rawArgs); const verboseInfo = getVerboseInfo(rawOptions); logCommand(escapedCommand, rawOptions); return {command, escapedCommand}; logCommand(escapedCommand, verboseInfo, rawOptions); return {command, escapedCommand, verboseInfo};};
export const handleArguments = (filePath, rawArgs, rawOptions) => { rawOptions.cwd = normalizeCwd(rawOptions.cwd);67 unmodified linesmodified:lib/stdio/async.js+3 added-2 removed
6 unmodified lines7 import {TYPE_TO_MESSAGE} from './type.js';8 import {generatorToDuplexStream, pipeGenerator} from './generator.js';9 10 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode11-export const handleInputAsync = options => handleInput(addPropertiesAsync, options, false);11+export const handleInputAsync = (options, verboseInfo) => handleInput(addPropertiesAsync, options, verboseInfo, false);12 13 const forbiddenIfAsync = ({type, optionName}) => {14 throw new TypeError(`The \`${optionName}\` option cannot be ${TYPE_TO_MESSAGE[type]}.`);15 };19 unmodified lines35 };36 37 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async mode38 // When multiple input streams are used, we merge them to ensure the output stream ends only once each input stream has ended39-export const pipeOutputAsync = (spawned, stdioStreamsGroups, controller) => {39+export const pipeOutputAsync = (spawned, stdioStreamsGroups, stdioState, controller) => {40+ stdioState.spawned = spawned;41 const inputStreamsGroups = {};42 43 for (const stdioStreams of stdioStreamsGroups) {44 for (const generatorStream of stdioStreams.filter(({type}) => type === 'generator')) {51 unmodified linesmodified:lib/stdio/forward.js+1 added-1 removed
4 unmodified lines567899101112135 unmodified lines4 unmodified lines
// Whether `childProcess.std*` will be setexport const willPipeStreams = stdioStreams => PIPED_STDIO_VALUES.has(forwardStdioItem(stdioStreams));
const PIPED_STDIO_VALUES = new Set(['pipe', 'overlapped', undefined, null]);export const PIPED_STDIO_VALUES = new Set(['pipe', 'overlapped', undefined, null]);
const forwardStdioItem = stdioStreams => { if (stdioStreams.length > 1) { return stdioStreams.some(({value}) => value === 'overlapped') ? 'overlapped' : 'pipe';5 unmodified linesmodified:lib/stdio/handle.js+5 added-2 removed
1+import {handleStreamsVerbose} from '../verbose/output.js';2 import {getStdioOptionType, isRegularUrl, isUnknownStdioString} from './type.js';3 import {addStreamDirection} from './direction.js';4 import {normalizeStdio} from './option.js';5 import {handleNativeStream} from './native.js';3 unmodified lines9 import {normalizeGenerators} from './generator.js';10 import {forwardStdio} from './forward.js';11 12 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode12-export const handleInput = (addProperties, options, isSync) => {13+export const handleInput = (addProperties, options, verboseInfo, isSync) => {14+ const stdioState = {};15 const stdio = normalizeStdio(options);16 const [stdinStreams, ...otherStreamsGroups] = stdio.map((stdioOption, fdNumber) => getStdioStreams(stdioOption, fdNumber));17 const stdioStreamsGroups = [[...stdinStreams, ...handleInputOptions(options)], ...otherStreamsGroups]18 .map(stdioStreams => validateStreams(stdioStreams))19 .map(stdioStreams => addStreamDirection(stdioStreams))20+ .map(stdioStreams => handleStreamsVerbose({stdioStreams, options, isSync, stdioState, verboseInfo}))21 .map(stdioStreams => handleStreamsLines(stdioStreams, options, isSync))22 .map(stdioStreams => handleStreamsEncoding(stdioStreams, options, isSync))23 .map(stdioStreams => normalizeGenerators(stdioStreams))24 .map(stdioStreams => addStreamsProperties(stdioStreams, addProperties));25 options.stdio = forwardStdio(stdioStreamsGroups);23- return stdioStreamsGroups;26+ return {stdioStreamsGroups, stdioState};27 };28 29 // We make sure passing an array with a single item behaves the same as passing that item without an array.30 // This is what users would expect.69 unmodified linesmodified:lib/stdio/sync.js+2 added-2 removed
2 unmodified lines3 import {handleInput} from './handle.js';4 import {TYPE_TO_MESSAGE} from './type.js';5 6 // Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode7-export const handleInputSync = options => {8- const stdioStreamsGroups = handleInput(addPropertiesSync, options, true);7+export const handleInputSync = (options, verboseInfo) => {8+ const {stdioStreamsGroups} = handleInput(addPropertiesSync, options, verboseInfo, true);9 addInputOptionSync(stdioStreamsGroups, options);10 return stdioStreamsGroups;11 };12 58 unmodified linesadded:lib/verbose/info.js+19 added
12345678910111213141516171819import {debuglog} from 'node:util';
export const getVerboseInfo = ({verbose = verboseDefault}) => { if (verbose === 'none') { return {verbose}; }
const verboseId = VERBOSE_ID++; return {verbose, verboseId};};
const verboseDefault = debuglog('execa').enabled ? 'full' : 'none';
// 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;modified:lib/verbose/log.js+18 added-2 removed
123456567891011121314151617181920212223242526273 unmodified lines313233343536import {writeFileSync} from 'node:fs';import process from 'node:process';
// Write synchronously to ensure lines are properly ordered and not interleaved with `stdout`export const verboseLog = (string, icon) => { writeFileSync(process.stderr.fd, `[${getTimestamp()}] ${ICONS[icon]} ${string}\n`);export const verboseLog = (string, verboseId, icon) => { const prefixedLines = addPrefix(string, verboseId, icon); writeFileSync(process.stderr.fd, `${prefixedLines}\n`);};
const addPrefix = (string, verboseId, icon) => string.includes('\n') ? string .split('\n') .map(line => addPrefixToLine(line, verboseId, icon)) .join('\n') : addPrefixToLine(string, verboseId, icon);
const addPrefixToLine = (line, verboseId, icon) => [ `[${getTimestamp()}]`, `[${verboseId}]`, ICONS[icon], line,].join(' ');
// Prepending the timestamp allows debugging the slow paths of a processconst getTimestamp = () => { const date = new Date(); return `${padField(date.getHours(), 2)}:${padField(date.getMinutes(), 2)}:${padField(date.getSeconds(), 2)}.${padField(date.getMilliseconds(), 3)}`;3 unmodified lines
const ICONS = { command: '$', pipedCommand: '|', output: ' ',};added:lib/verbose/output.js+68 added
1+import {inspect} from 'node:util';2+import stripFinalNewline from 'strip-final-newline';3+import {escapeLines} from '../arguments/escape.js';4+import {PIPED_STDIO_VALUES} from '../stdio/forward.js';5+import {verboseLog} from './log.js';6+7+export const handleStreamsVerbose = ({stdioStreams, options, isSync, stdioState, verboseInfo}) => {8+ if (!shouldLogOutput(stdioStreams, options, isSync, verboseInfo)) {9+ return stdioStreams;10+ }11+12+ const [{fdNumber}] = stdioStreams;13+ return [...stdioStreams, {14+ ...stdioStreams[0],15+ type: 'generator',16+ value: verboseGenerator.bind(undefined, {stdioState, fdNumber, verboseInfo}),17+ }];18+};19+20+// `ignore` opts-out of `verbose` for a specific stream.21+// `ipc` cannot use piping.22+// `inherit` would result in double printing.23+// They can also lead to double printing when passing file descriptor integers or `process.std*`.24+// This only leaves with `pipe` and `overlapped`.25+const shouldLogOutput = (stdioStreams, {encoding}, isSync, {verbose}) => verbose === 'full'26+ && !isSync27+ && ALLOWED_ENCODINGS.has(encoding)28+ && fdUsesVerbose(stdioStreams)29+ && (stdioStreams.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))30+ || stdioStreams.every(({type}) => type === 'generator'));31+32+// Only print text output, not binary33+// eslint-disable-next-line unicorn/text-encoding-identifier-case34+const ALLOWED_ENCODINGS = new Set(['utf8', 'utf-8']);35+36+// Printing input streams would be confusing.37+// Files and streams can produce big outputs, which we don't want to print.38+// We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue.39+// So we only print stdout and stderr.40+const fdUsesVerbose = ([{fdNumber}]) => fdNumber === 1 || fdNumber === 2;41+42+const verboseGenerator = function * ({stdioState: {spawned: {stdio}}, fdNumber, verboseInfo}, line) {43+ if (!isPiping(stdio[fdNumber])) {44+ logOutput(line, verboseInfo);45+ }46+47+ yield line;48+};49+50+// When `childProcess.stdout|stderr.pipe()` is called, `verbose` becomes a noop.51+// This prevents the following problems:52+// - `.pipe()` achieves the same result as using `stdout: 'inherit'`, `stdout: stream`, etc. which also make `verbose` a noop.53+// For example, `childProcess.stdout.pipe(process.stdin)` would print each line twice.54+// - When chaining processes with `childProcess.pipe(otherProcess)`, only the last one should print its output.55+// Detecting whether `.pipe()` is impossible without monkey-patching it, so we use the following undocumented property.56+// This is not a critical behavior since changes of the following property would only make `verbose` more verbose.57+const isPiping = stream => stream._readableState.pipes.length > 0;58+59+// When `verbose` is `full`, print stdout|stderr60+const logOutput = (line, {verboseId}) => {61+ const lines = typeof line === 'string' ? stripFinalNewline(line) : inspect(line);62+ const escapedLines = escapeLines(lines);63+ const spacedLines = escapedLines.replaceAll('\t', ' '.repeat(TAB_SIZE));64+ verboseLog(spacedLines, verboseId, 'output');65+};66+67+// Same as `util.inspect()`68+const TAB_SIZE = 2;modified:lib/verbose/start.js+3 added-6 removed
1-import {debuglog} from 'node:util';1 import {verboseLog} from './log.js';2 3 // When `verbose` is `short|full`, print each command5-export const logCommand = (escapedCommand, {verbose = verboseDefault, piped = false}) => {6- if (!verbose) {4+export const logCommand = (escapedCommand, {verbose, verboseId}, {piped = false}) => {5+ if (verbose === 'none') {6 return;7 }8 9 const icon = piped ? 'pipedCommand' : 'command';11- verboseLog(escapedCommand, icon);10+ verboseLog(escapedCommand, verboseId, icon);11 };13-14-const verboseDefault = debuglog('execa').enabled;modified:lib/async.js+7 added-7 removed
12 unmodified lines13 import {getSpawnedResult} from './stream/resolve.js';14 import {mergePromise} from './promise.js';15 16 export const execa = (rawFile, rawArgs, rawOptions) => {17- const {file, args, command, escapedCommand, options, stdioStreamsGroups} = handleAsyncArguments(rawFile, rawArgs, rawOptions);18- const {spawned, promise} = spawnProcessAsync({file, args, options, command, escapedCommand, stdioStreamsGroups});17+ const {file, args, command, escapedCommand, options, stdioStreamsGroups, stdioState} = handleAsyncArguments(rawFile, rawArgs, rawOptions);18+ const {spawned, promise} = spawnProcessAsync({file, args, options, command, escapedCommand, stdioStreamsGroups, stdioState});19 spawned.pipe = pipeToProcess.bind(undefined, {source: spawned, sourcePromise: promise, stdioStreamsGroups, destinationOptions: {}});20 mergePromise(spawned, promise);21 PROCESS_OPTIONS.set(spawned, options);22 return spawned;23 };24 25 const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {26 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);27- const {command, escapedCommand} = handleCommand(rawFile, rawArgs, rawOptions);27+ const {command, escapedCommand, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);28 const {file, args, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);29 const options = handleAsyncOptions(normalizedOptions);30- const stdioStreamsGroups = handleInputAsync(options);31- return {file, args, command, escapedCommand, options, stdioStreamsGroups};30+ const {stdioStreamsGroups, stdioState} = handleInputAsync(options, verboseInfo);31+ return {file, args, command, escapedCommand, options, stdioStreamsGroups, stdioState};32 };33 34 // Prevent passing the `timeout` option directly to `child_process.spawn()`35 const handleAsyncOptions = ({timeout, signal, cancelSignal, ...options}) => {3 unmodified lines39 40 return {...options, timeoutDuration: timeout, signal: cancelSignal};41 };42 43-const spawnProcessAsync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {43+const spawnProcessAsync = ({file, args, options, command, escapedCommand, stdioStreamsGroups, stdioState}) => {44 let spawned;45 try {46 spawned = spawn(file, args, options);47 } catch (error) {3 unmodified lines51 const controller = new AbortController();52 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);53 54 const originalStreams = [...spawned.stdio];55- pipeOutputAsync(spawned, stdioStreamsGroups, controller);55+ pipeOutputAsync(spawned, stdioStreamsGroups, stdioState, controller);56 cleanupOnExit(spawned, options, controller);57 58 spawned.kill = spawnedKill.bind(undefined, {kill: spawned.kill.bind(spawned), spawned, options, controller});59 spawned.all = makeAllStream(spawned, options);36 unmodified linesmodified:lib/sync.js+2 added-2 removed
11 unmodified lines12 };13 14 const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {15 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);16- const {command, escapedCommand} = handleCommand(rawFile, rawArgs, rawOptions);16+ const {command, escapedCommand, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);17 const syncOptions = normalizeSyncOptions(rawOptions);18 const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);19 validateSyncOptions(options);20- const stdioStreamsGroups = handleInputSync(options);20+ const stdioStreamsGroups = handleInputSync(options, verboseInfo);21 return {file, args, command, escapedCommand, options, stdioStreamsGroups};22 };23 24 const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;35 unmodified linesadded:test/fixtures/nested-big-array.js+8 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+import {getOutputGenerator} from '../helpers/generator.js';5+6+const bigArray = Array.from({length: 100}, (_, index) => index);7+const [options, file, ...args] = process.argv.slice(2);8+await execa(file, args, {stdout: getOutputGenerator(bigArray, true), ...JSON.parse(options)});added:test/fixtures/nested-double.js+11 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [options, file, ...args] = process.argv.slice(2);6+const firstArgs = args.slice(0, -1);7+const lastArg = args.at(-1);8+await Promise.all([9+ execa(file, [...firstArgs, lastArg], JSON.parse(options)),10+ execa(file, [...firstArgs, lastArg.toUpperCase()], JSON.parse(options)),11+]);added:test/fixtures/nested-file-url.js+8 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {pathToFileURL} from 'node:url';4+import {execa} from '../../index.js';5+6+const [options, file, arg] = process.argv.slice(2);7+const parsedOptions = JSON.parse(options);8+await execa(file, [arg], {...parsedOptions, stdout: pathToFileURL(parsedOptions.stdout)});added:test/fixtures/nested-object.js+7 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+import {outputObjectGenerator} from '../helpers/generator.js';5+6+const [options, file, ...args] = process.argv.slice(2);7+await execa(file, args, {stdout: outputObjectGenerator, ...JSON.parse(options)});added:test/fixtures/nested-pipe-child-process.js+15 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [options, file, arg, unpipe] = process.argv.slice(2);6+const source = execa(file, [arg], JSON.parse(options));7+const destination = execa('stdin.js');8+const controller = new AbortController();9+const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal});10+if (unpipe === 'true') {11+ controller.abort();12+ destination.stdin.end();13+}14+15+await Promise.allSettled([source, destination, pipePromise]);added:test/fixtures/nested-pipe-stream.js+12 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [options, file, arg, unpipe] = process.argv.slice(2);6+const childProcess = execa(file, [arg], JSON.parse(options));7+childProcess.stdout.pipe(process.stdout);8+if (unpipe === 'true') {9+ childProcess.stdout.unpipe(process.stdout);10+}11+12+await childProcess;added:test/fixtures/nested-send.js+7 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [options, file, ...args] = process.argv.slice(2);6+const result = await execa(file, args, JSON.parse(options));7+process.send(result);added:test/fixtures/nested-transform.js+7 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+import {uppercaseGenerator} from '../helpers/generator.js';5+6+const [options, file, ...args] = process.argv.slice(2);7+await execa(file, args, {stdout: uppercaseGenerator, ...JSON.parse(options)});added:test/fixtures/nested-writable-web.js+6 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [options, file, arg] = process.argv.slice(2);6+await execa(file, [arg], {...JSON.parse(options), stdout: new WritableStream()});added:test/fixtures/nested-writable.js+6 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [options, file, arg] = process.argv.slice(2);6+await execa(file, [arg], {...JSON.parse(options), stdout: process.stdout});added:test/fixtures/noop-progressive.js+11 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {setTimeout} from 'node:timers/promises';4+5+for (const character of process.argv[2]) {6+ process.stdout.write(character);7+ // eslint-disable-next-line no-await-in-loop8+ await setTimeout(10);9+}10+11+process.stdout.write('\n');modified:test/fixtures/noop-repeat.js+1 added-1 removed
1 unmodified line2 import process from 'node:process';3 import {writeSync} from 'node:fs';4 5 setInterval(() => {6- writeSync(Number(process.argv[2]) || 1, '.');6+ writeSync(Number(process.argv[2]) || 1, process.argv[3] || '.');7 }, 10);modified:test/helpers/generator.js+4 added
67 unmodified lines68 for await (const value of setInterval(100, 'foo')) {69 yield value;70 }71 };72+73+export const uppercaseGenerator = function * (line) {74+ yield line.toUpperCase();75+};modified:test/helpers/verbose.js+7 added-2 removed
5 unmodified lines6 const isWindows = platform === 'win32';7 export const QUOTE = isWindows ? '"' : '\'';8 9 // eslint-disable-next-line max-params10-const nestedExeca = (fixtureName, file, args, options, parentOptions) => {10+export const nestedExeca = (fixtureName, file, args, options, parentOptions) => {11 [args, options = {}, parentOptions = {}] = Array.isArray(args) ? [args, options, parentOptions] : [[], args, options];12 return execa(fixtureName, [JSON.stringify(options), file, ...args], parentOptions);13 };14 6 unmodified lines21 return stderr;22 };23 24 export const runEarlyErrorProcess = async (t, execaMethod) => {25- const {stderr} = await t.throwsAsync(execaMethod('noop.js', [foobarString], {verbose: true, cwd: true}));25+ const {stderr} = await t.throwsAsync(execaMethod('noop.js', [foobarString], {verbose: 'short', cwd: true}));26 t.true(stderr.includes('The "cwd" option must'));27 return stderr;28 };29 30 export const getCommandLine = stderr => getCommandLines(stderr)[0];31 export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));32 const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');33+export const getOutputLine = stderr => getOutputLines(stderr)[0];34+export const getOutputLines = stderr => getNormalizedLines(stderr).filter(line => isOutputLine(line));35+const isOutputLine = line => line.includes('] ');36 export const getNormalizedLines = stderr => splitLines(normalizeStderr(stderr));37 const splitLines = stderr => stderr.split('\n');38 39 const normalizeStderr = stderr => normalizeTimestamp(stripVTControlCharacters(stderr));40 export const testTimestamp = '[00:00:00.000]';41 const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}]/gm, testTimestamp);42+43+export const getVerboseOption = (isVerbose, verbose = 'short') => ({verbose: isVerbose ? verbose : 'none'});modified:test/stdio/generator.js+1 added-5 removed
5 unmodified lines6 import {execa} from '../../index.js';7 import {setFixtureDir} from '../helpers/fixtures-dir.js';8 import {getStdio} from '../helpers/stdio.js';9 import {foobarString, foobarUint8Array, foobarBuffer, foobarObject, foobarObjectString} from '../helpers/input.js';10-import {serializeGenerator, outputObjectGenerator, addNoopGenerator} from '../helpers/generator.js';10+import {serializeGenerator, outputObjectGenerator, addNoopGenerator, uppercaseGenerator} from '../helpers/generator.js';11 12 setFixtureDir();13 14 const textEncoder = new TextEncoder();1 unmodified line16 17 const foobarUppercase = foobarString.toUpperCase();18 const foobarHex = foobarBuffer.toString('hex');19 20-const uppercaseGenerator = function * (line) {21- yield line.toUpperCase();22-};23-20 const uppercaseBufferGenerator = function * (line) {21 yield textDecoder.decode(line).toUpperCase();22 };23 322 unmodified linesmodified:test/verbose/info.js+9 added-6 removed
5 unmodified lines6 QUOTE,7 nestedExecaAsync,8 nestedExecaSync,9 getCommandLine,10+ getOutputLine,11 getNormalizedLines,12 testTimestamp,13 } from '../helpers/verbose.js';14 1 unmodified line16 17 test('Prints command, NODE_DEBUG=execa + "inherit"', async t => {18 const {all} = await execa('verbose-script.js', {env: {NODE_DEBUG: 'execa'}, all: true});19 t.deepEqual(getNormalizedLines(all), [19- `${testTimestamp} $ node -e ${QUOTE}console.error(1)${QUOTE}`,20+ `${testTimestamp} [0] $ node -e ${QUOTE}console.error(1)${QUOTE}`,21 '1',21- `${testTimestamp} $ node -e ${QUOTE}process.exit(2)${QUOTE}`,22+ `${testTimestamp} [1] $ node -e ${QUOTE}process.exit(2)${QUOTE}`,23 ]);24 });25 25-test('NODE_DEBUG=execa changes verbose default value to true', async t => {26+test('NODE_DEBUG=execa changes verbose default value to "full"', async t => {27 const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});27- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${foobarString}`);28+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);29+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);30 });31 32 const testDebugEnvPriority = async (t, execaMethod) => {31- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: false}, {env: {NODE_DEBUG: 'execa'}});32- t.is(getCommandLine(stderr), undefined);33+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'short'}, {env: {NODE_DEBUG: 'execa'}});34+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);35+ t.is(getOutputLine(stderr), undefined);36 };37 38 test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, nestedExecaAsync);39 test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, nestedExecaSync);modified:test/verbose/log.js+6 added-4 removed
8 unmodified lines9 const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});10 t.is(stdout, foobarString);11 };12 13-test('Logs on stderr not stdout, verbose false', testNoStdout, false, nestedExecaAsync);14-test('Logs on stderr not stdout, verbose true', testNoStdout, true, nestedExecaAsync);15-test('Logs on stderr not stdout, verbose false, sync', testNoStdout, false, nestedExecaSync);16-test('Logs on stderr not stdout, verbose true, sync', testNoStdout, true, nestedExecaSync);13+test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', nestedExecaAsync);14+test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', nestedExecaAsync);15+test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', nestedExecaAsync);16+test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', nestedExecaSync);17+test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', nestedExecaSync);18+test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', nestedExecaSync);added:test/verbose/output.js+234 added
1+import {once, on} from 'node:events';2+import {rm, readFile} from 'node:fs/promises';3+import {inspect} from 'node:util';4+import test from 'ava';5+import tempfile from 'tempfile';6+import {red} from 'yoctocolors';7+import {execa} from '../../index.js';8+import {setFixtureDir} from '../helpers/fixtures-dir.js';9+import {foobarString, foobarObject} from '../helpers/input.js';10+import {fullStdio} from '../helpers/stdio.js';11+import {12+ nestedExeca,13+ nestedExecaAsync,14+ nestedExecaSync,15+ runErrorProcess,16+ getOutputLine,17+ getOutputLines,18+ testTimestamp,19+ getVerboseOption,20+} from '../helpers/verbose.js';21+22+setFixtureDir();23+24+const nestedExecaDouble = nestedExeca.bind(undefined, 'nested-double.js');25+26+const testPrintOutput = async (t, fdNumber, execaMethod) => {27+ const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose: 'full'});28+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);29+};30+31+test('Prints stdout, verbose "full"', testPrintOutput, 1, nestedExecaAsync);32+test('Prints stderr, verbose "full"', testPrintOutput, 2, nestedExecaAsync);33+34+const testNoPrintOutput = async (t, verbose, fdNumber, execaMethod) => {35+ const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose, ...fullStdio});36+ t.is(getOutputLine(stderr), undefined);37+};38+39+test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, nestedExecaAsync);40+test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, nestedExecaAsync);41+test('Does not print stdout, verbose "full", sync', testNoPrintOutput, 'full', 1, nestedExecaSync);42+test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, nestedExecaSync);43+test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, nestedExecaSync);44+test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, nestedExecaAsync);45+test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, nestedExecaAsync);46+test('Does not print stderr, verbose "full", sync', testNoPrintOutput, 'full', 2, nestedExecaSync);47+test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, nestedExecaSync);48+test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, nestedExecaSync);49+test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, nestedExecaAsync);50+test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, nestedExecaAsync);51+test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, nestedExecaAsync);52+test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, nestedExecaSync);53+test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, nestedExecaSync);54+test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, nestedExecaSync);55+56+test('Prints stdout after errors', async t => {57+ const stderr = await runErrorProcess(t, 'full', nestedExecaAsync);58+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);59+});60+61+const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {62+ const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [63+ JSON.stringify(getVerboseOption(sourceVerbose, 'full')),64+ 'noop.js',65+ foobarString,66+ JSON.stringify(getVerboseOption(destinationVerbose, 'full')),67+ 'stdin.js',68+ ]);69+70+ const lines = getOutputLines(stderr);71+ const id = sourceVerbose && destinationVerbose ? 1 : 0;72+ t.deepEqual(lines, destinationVerbose73+ ? [`${testTimestamp} [${id}] ${foobarString}`]74+ : []);75+};76+77+test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'file', true, true);78+test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'script', true, true);79+test('Prints stdout if both verbose with .pipe(childProcess)', testPipeOutput, 'process', true, true);80+test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'file', false, true);81+test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'script', false, true);82+test('Prints stdout if only second verbose with .pipe(childProcess)', testPipeOutput, 'process', false, true);83+test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'file', true, false);84+test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'script', true, false);85+test('Does not print stdout if only first verbose with .pipe(childProcess)', testPipeOutput, 'process', true, false);86+test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);87+test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);88+test('Does not print stdout if neither verbose with .pipe(childProcess)', testPipeOutput, 'process', false, false);89+90+test('Does not quote spaces from stdout', async t => {91+ const {stderr} = await nestedExecaAsync('noop.js', ['foo bar'], {verbose: 'full'});92+ t.is(getOutputLine(stderr), `${testTimestamp} [0] foo bar`);93+});94+95+test('Does not quote special punctuation from stdout', async t => {96+ const {stderr} = await nestedExecaAsync('noop.js', ['%'], {verbose: 'full'});97+ t.is(getOutputLine(stderr), `${testTimestamp} [0] %`);98+});99+100+test('Does not escape internal characters from stdout', async t => {101+ const {stderr} = await nestedExecaAsync('noop.js', ['ã'], {verbose: 'full'});102+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);103+});104+105+test('Strips color sequences from stdout', async t => {106+ const {stderr} = await nestedExecaAsync('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1'}});107+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);108+});109+110+test('Escapes control characters from stdout', async t => {111+ const {stderr} = await nestedExecaAsync('noop.js', ['\u0001'], {verbose: 'full'});112+ t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);113+});114+115+const testStdioSame = async (t, fdNumber) => {116+ const childProcess = execa('nested-send.js', [JSON.stringify({verbose: true}), 'noop-fd.js', `${fdNumber}`, foobarString], {ipc: true});117+ const [[{stdio}]] = await Promise.all([once(childProcess, 'message'), childProcess]);118+ t.is(stdio[fdNumber], foobarString);119+};120+121+test('Does not change stdout', testStdioSame, 1);122+test('Does not change stderr', testStdioSame, 2);123+124+test('Prints stdout with only transforms', async t => {125+ const {stderr} = await nestedExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full'});126+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString.toUpperCase()}`);127+});128+129+test('Prints stdout with object transforms', async t => {130+ const {stderr} = await nestedExeca('nested-object.js', 'noop.js', {verbose: 'full'});131+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${inspect(foobarObject)}`);132+});133+134+test('Prints stdout with big object transforms', async t => {135+ const {stderr} = await nestedExeca('nested-big-array.js', 'noop.js', {verbose: 'full'});136+ const lines = getOutputLines(stderr);137+ t.is(lines[0], `${testTimestamp} [0] [`);138+ t.true(lines[1].startsWith(`${testTimestamp} [0] 0, 1,`));139+ t.is(lines.at(-1), `${testTimestamp} [0] ]`);140+});141+142+test('Prints stdout one line at a time', async t => {143+ const childProcess = nestedExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});144+145+ for await (const chunk of on(childProcess.stderr, 'data')) {146+ const outputLine = getOutputLine(chunk.toString().trim());147+ if (outputLine !== undefined) {148+ t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);149+ break;150+ }151+ }152+153+ await childProcess;154+});155+156+test('Prints stdout progressively, interleaved', async t => {157+ const childProcess = nestedExecaDouble('noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});158+159+ let firstProcessPrinted = false;160+ let secondProcessPrinted = false;161+ for await (const chunk of on(childProcess.stderr, 'data')) {162+ const outputLine = getOutputLine(chunk.toString().trim());163+ if (outputLine === undefined) {164+ continue;165+ }166+167+ if (outputLine.includes(foobarString)) {168+ t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);169+ firstProcessPrinted ||= true;170+ } else {171+ t.is(outputLine, `${testTimestamp} [1] ${foobarString.toUpperCase()}`);172+ secondProcessPrinted ||= true;173+ }174+175+ if (firstProcessPrinted && secondProcessPrinted) {176+ break;177+ }178+ }179+180+ childProcess.kill();181+ await t.throwsAsync(childProcess);182+});183+184+test('Prints stdout, single newline', async t => {185+ const {stderr} = await nestedExecaAsync('noop-fd.js', ['1', '\n'], {verbose: 'full'});186+ t.deepEqual(getOutputLines(stderr), [`${testTimestamp} [0] `]);187+});188+189+const testNoOutputOptions = async (t, options, fixtureName = 'nested.js') => {190+ const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});191+ t.is(getOutputLine(stderr), undefined);192+};193+194+test('Does not print stdout, encoding "buffer"', testNoOutputOptions, {encoding: 'buffer'});195+test('Does not print stdout, encoding "hex"', testNoOutputOptions, {encoding: 'hex'});196+test('Does not print stdout, encoding "base64"', testNoOutputOptions, {encoding: 'base64'});197+test('Does not print stdout, stdout "ignore"', testNoOutputOptions, {stdout: 'ignore'});198+test('Does not print stdout, stdout "inherit"', testNoOutputOptions, {stdout: 'inherit'});199+test('Does not print stdout, stdout 1', testNoOutputOptions, {stdout: 1});200+test('Does not print stdout, stdout Writable', testNoOutputOptions, {}, 'nested-writable.js');201+test('Does not print stdout, stdout WritableStream', testNoOutputOptions, {}, 'nested-writable-web.js');202+test('Does not print stdout, .pipe(stream)', testNoOutputOptions, {}, 'nested-pipe-stream.js');203+test('Does not print stdout, .pipe(childProcess)', testNoOutputOptions, {}, 'nested-pipe-child-process.js');204+205+const testStdoutFile = async (t, fixtureName, getStdout) => {206+ const file = tempfile();207+ const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', stdout: getStdout(file)});208+ t.is(getOutputLine(stderr), undefined);209+ const contents = await readFile(file, 'utf8');210+ t.is(contents.trim(), foobarString);211+ await rm(file);212+};213+214+test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));215+test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);216+217+const testPrintOutputOptions = async (t, options) => {218+ const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {verbose: 'full', ...options});219+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);220+};221+222+test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'});223+test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'});224+test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null});225+test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']});226+test('Prints stdout, buffer false', testPrintOutputOptions, {buffer: false});227+228+const testPrintOutputFixture = async (t, fixtureName, ...args) => {229+ const {stderr} = await nestedExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});230+ t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);231+};232+233+test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');234+test('Prints stdout, .pipe(childProcess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-child-process.js', 'true');modified:test/verbose/start.js+27 added-24 removed
10 unmodified lines11 runEarlyErrorProcess,12 getCommandLine,13 getCommandLines,14 testTimestamp,15+ getVerboseOption,16 } from '../helpers/verbose.js';17 18 setFixtureDir();19 19-const testPrintCommand = async (t, execaMethod) => {20- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: true});21- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${foobarString}`);20+const testPrintCommand = async (t, verbose, execaMethod) => {21+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});22+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);23 };24 24-test('Prints command', testPrintCommand, nestedExecaAsync);25-test('Prints command, sync', testPrintCommand, nestedExecaSync);25+test('Prints command, verbose "short"', testPrintCommand, 'short', nestedExecaAsync);26+test('Prints command, verbose "full"', testPrintCommand, 'full', nestedExecaAsync);27+test('Prints command, verbose "short", sync', testPrintCommand, 'short', nestedExecaSync);28+test('Prints command, verbose "full", sync', testPrintCommand, 'full', nestedExecaSync);29 30 const testNoPrintCommand = async (t, execaMethod) => {28- const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: false});31+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: 'none'});32 t.is(stderr, '');33 };34 32-test('Does not print command', testNoPrintCommand, nestedExecaAsync);33-test('Does not print command, sync', testNoPrintCommand, nestedExecaSync);35+test('Does not print command, verbose "none"', testNoPrintCommand, nestedExecaAsync);36+test('Does not print command, verbose "none", sync', testNoPrintCommand, nestedExecaSync);37 38 const testPrintCommandError = async (t, execaMethod) => {36- const stderr = await runErrorProcess(t, true, execaMethod);37- t.is(getCommandLine(stderr), `${testTimestamp} $ noop-fail.js 1 ${foobarString}`);39+ const stderr = await runErrorProcess(t, 'short', execaMethod);40+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop-fail.js 1 ${foobarString}`);41 };42 43 test('Prints command after errors', testPrintCommandError, nestedExecaAsync);44 test('Prints command after errors, sync', testPrintCommandError, nestedExecaSync);45 46 const testPrintCommandEarly = async (t, execaMethod) => {47 const stderr = await runEarlyErrorProcess(t, execaMethod);45- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${foobarString}`);48+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);49 };50 51 test('Prints command before early validation errors', testPrintCommandEarly, nestedExecaAsync);52 test('Prints command before early validation errors, sync', testPrintCommandEarly, nestedExecaSync);53 54 const testPipeCommand = async (t, fixtureName, sourceVerbose, destinationVerbose) => {55 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [53- JSON.stringify({verbose: sourceVerbose}),56+ JSON.stringify(getVerboseOption(sourceVerbose)),57 'noop.js',58 foobarString,56- JSON.stringify({verbose: destinationVerbose}),59+ JSON.stringify(getVerboseOption(destinationVerbose)),60 'stdin.js',61 ]);62 const pipeSymbol = fixtureName === 'process' ? '$' : '|';63 const lines = getCommandLines(stderr);61- t.is(lines.includes(`${testTimestamp} $ noop.js ${foobarString}`), sourceVerbose);62- t.is(lines.includes(`${testTimestamp} ${pipeSymbol} stdin.js`), destinationVerbose);64+ t.is(lines.includes(`${testTimestamp} [0] $ noop.js ${foobarString}`), sourceVerbose);65+ t.is(lines.includes(`${testTimestamp} [${sourceVerbose ? 1 : 0}] ${pipeSymbol} stdin.js`), destinationVerbose);66 };67 68 test('Prints both commands piped with .pipe("file")', testPipeCommand, 'file', true, true);69 test('Prints both commands piped with .pipe`command`', testPipeCommand, 'script', true, true);8 unmodified lines78 test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);79 test('Prints neither commands piped with .pipe(childProcess)', testPipeCommand, 'process', false, false);80 81 test('Quotes spaces from command', async t => {79- const {stderr} = await nestedExecaAsync('noop.js', ['foo bar'], {verbose: true});80- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${QUOTE}foo bar${QUOTE}`);82+ const {stderr} = await nestedExecaAsync('noop.js', ['foo bar'], {verbose: 'short'});83+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}foo bar${QUOTE}`);84 });85 86 test('Quotes special punctuation from command', async t => {84- const {stderr} = await nestedExecaAsync('noop.js', ['%'], {verbose: true});85- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${QUOTE}%${QUOTE}`);87+ const {stderr} = await nestedExecaAsync('noop.js', ['%'], {verbose: 'short'});88+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}%${QUOTE}`);89 });90 91 test('Does not escape internal characters from command', async t => {89- const {stderr} = await nestedExecaAsync('noop.js', ['ã'], {verbose: true});90- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${QUOTE}ã${QUOTE}`);92+ const {stderr} = await nestedExecaAsync('noop.js', ['ã'], {verbose: 'short'});93+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}ã${QUOTE}`);94 });95 96 test('Escapes color sequences from command', async t => {94- const {stderr} = await nestedExecaAsync('noop.js', [red(foobarString)], {verbose: true}, {env: {FORCE_COLOR: '1'}});97+ const {stderr} = await nestedExecaAsync('noop.js', [red(foobarString)], {verbose: 'short'}, {env: {FORCE_COLOR: '1'}});98 t.true(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));99 });100 101 test('Escapes control characters from command', async t => {99- const {stderr} = await nestedExecaAsync('noop.js', ['\u0001'], {verbose: true});100- t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${QUOTE}\\u0001${QUOTE}`);102+ const {stderr} = await nestedExecaAsync('noop.js', ['\u0001'], {verbose: 'short'});103+ t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}\\u0001${QUOTE}`);104 });modified:index.d.ts+13 added-8 removed
541 unmodified lines542 */543 readonly windowsHide?: boolean;544 545 /**546- Print each command on `stderr` before executing it.546+ If `verbose` is `'short'` or `'full'`, prints each command on `stderr` before executing it.547 548- This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process.548+ If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:549+ - the `stdout`/`stderr` option is `ignore` or `inherit`.550+ - the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), a file, a file descriptor, or another child process.551+ - the `encoding` option is set.552 553+ This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.554+550- @default false555+ @default 'none'556 */552- readonly verbose?: boolean;557+ readonly verbose?: 'none' | 'short' | 'full';558 559 /**560 Kill the spawned process when the parent process exits unless either:561 - the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)470 unmodified lines1032 1033 /**1034 Same as `execa()` but synchronous.1035 1031-Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1036+Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1037 1038 Returns or throws a `childProcessResult`. The `childProcess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.1039 1040 @param file - The program/script to execute, as a string or file URL92 unmodified lines1133 1134 /**1135 Same as `execaCommand()` but synchronous.1136 1132-Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1137+Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1138 1139 Returns or throws a `childProcessResult`. The `childProcess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.1140 1141 @param command - The program/script to execute and its arguments.49 unmodified lines1191 1192 /**1193 Same as $\`command\` but synchronous.1194 1190- Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1195+ Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1196 1197 Returns or throws a `childProcessResult`. The `childProcess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.1198 1199 @returns A `childProcessResult` object45 unmodified lines1245 1246 /**1247 Same as $\`command\` but synchronous.1248 1244- Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal` and `lines`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1249+ Cannot use the following options: `all`, `cleanup`, `buffer`, `detached`, `ipc`, `serialization`, `cancelSignal`, `lines` and `verbose: 'full'`. Also, the `stdin`, `stdout`, `stderr`, `stdio` and `input` options cannot be an array, an iterable, a transform or a web stream. Node.js streams must have a file descriptor unless the `input` option is used.1250 1251 Returns or throws a `childProcessResult`. The `childProcess` is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), `.pipe()` and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.1252 1253 @returns A `childProcessResult` object132 unmodified linesmodified:index.test-d.ts+6 added-2 removed
1438 unmodified lines1439 execa('unicorns', {windowsVerbatimArguments: true});1440 execaSync('unicorns', {windowsVerbatimArguments: true});1441 execa('unicorns', {windowsHide: false});1442 execaSync('unicorns', {windowsHide: false});1443-execa('unicorns', {verbose: false});1444-execaSync('unicorns', {verbose: false});1443+execa('unicorns', {verbose: 'none'});1444+execaSync('unicorns', {verbose: 'none'});1445+execa('unicorns', {verbose: 'short'});1446+execaSync('unicorns', {verbose: 'short'});1447+execa('unicorns', {verbose: 'full'});1448+execaSync('unicorns', {verbose: 'full'});1449 expectError(execa('unicorns', {verbose: 'other'}));1450 expectError(execaSync('unicorns', {verbose: 'other'}));1451 /* eslint-enable @typescript-eslint/no-floating-promises */1452 expectType<boolean>(execa('unicorns').kill());115 unmodified linesmodified:readme.md+12 added-7 removed
140 unmodified lines141 unicorns142 rainbows143 144 > NODE_DEBUG=execa node file.js145-[19:49:00.360] $ echo unicorns145+[19:49:00.360] [0] $ echo unicorns146 unicorns147-[19:49:00.383] $ echo rainbows147+[19:49:00.383] [1] $ echo rainbows148 rainbows149 ```150 151 ### Input/output162 unmodified lines314 #### $.s(options)\`command\`315 316 Same as [`execa()`](#execacommandcommand-options), [`execaCommand()`](#execacommand-command-options), [$\`command\`](#command) but synchronous.317 318-Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.318+Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`cancelSignal`](#cancelsignal), [`lines`](#lines) and [`verbose: 'full'`](#verbose). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable, a [transform](docs/transform.md) or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.319 320 Returns or throws a [`childProcessResult`](#childProcessResult). The [`childProcess`](#childprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321 322 ### Shell syntax340 unmodified lines663 Requires the [`node`](#node) option to be `true`.664 665 #### verbose666 667-Type: `boolean`\668-Default: `false`667+Type: `'none' | 'short' | 'full'`\668+Default: `'none'`669 670-[Print each command](#verbose-mode) on `stderr` before executing it.670+If `verbose` is `'short'` or `'full'`, [prints each command](#verbose-mode) on `stderr` before executing it.671 672-This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process.672+If `verbose` is `'full'`, the command's `stdout` and `stderr` are printed too, unless either:673+- the [`stdout`](#stdout-1)/[`stderr`](#stderr-1) option is `ignore` or `inherit`.674+- the `stdout`/`stderr` is redirected to [a stream](https://nodejs.org/api/stream.html#readablepipedestination-options), [a file](#stdout-1), a file descriptor, or [another child process](#pipefile-arguments-options).675+- the [`encoding`](#encoding) option is set.676 677+This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.678+679 #### buffer680 681 Type: `boolean`\682 Default: `true`365 unmodified lines