Skip to content
Myr

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

34 files+554 added−87 removed

modified:docs/scripts.md+4 added-2 removed
402 unmodified lines
403```js404// Execa405import {$ as $_} from 'execa';406407// `verbose: 'short'` is also available407const $ = $_({verbose: true});408const $ = $_({verbose: 'full'});409410await $`echo example`;411```412
5 unmodified lines
418419Which prints:420421```421[19:49:00.360] $ echo example422[19:49:00.360] [0] $ echo example423example424```425426### Piping stdout to another command427
290 unmodified lines
modified:lib/arguments/options.js+4 added-2 removed
modified:lib/stdio/async.js+3 added-2 removed
6 unmodified lines
7import {TYPE_TO_MESSAGE} from './type.js';8import {generatorToDuplexStream, pipeGenerator} from './generator.js';910// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode11export const handleInputAsync = options => handleInput(addPropertiesAsync, options, false);11export const handleInputAsync = (options, verboseInfo) => handleInput(addPropertiesAsync, options, verboseInfo, false);1213const forbiddenIfAsync = ({type, optionName}) => {14 throw new TypeError(`The \`${optionName}\` option cannot be ${TYPE_TO_MESSAGE[type]}.`);15};
19 unmodified lines
35};3637// 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 ended39export const pipeOutputAsync = (spawned, stdioStreamsGroups, controller) => {39export const pipeOutputAsync = (spawned, stdioStreamsGroups, stdioState, controller) => {40 stdioState.spawned = spawned;41 const inputStreamsGroups = {};4243 for (const stdioStreams of stdioStreamsGroups) {44 for (const generatorStream of stdioStreams.filter(({type}) => type === 'generator')) {
51 unmodified lines
modified:lib/stdio/forward.js+1 added-1 removed
modified:lib/stdio/handle.js+5 added-2 removed
1import {handleStreamsVerbose} from '../verbose/output.js';2import {getStdioOptionType, isRegularUrl, isUnknownStdioString} from './type.js';3import {addStreamDirection} from './direction.js';4import {normalizeStdio} from './option.js';5import {handleNativeStream} from './native.js';
3 unmodified lines
9import {normalizeGenerators} from './generator.js';10import {forwardStdio} from './forward.js';1112// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode12export const handleInput = (addProperties, options, isSync) => {13export 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};2829// 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 lines
modified:lib/stdio/sync.js+2 added-2 removed
2 unmodified lines
3import {handleInput} from './handle.js';4import {TYPE_TO_MESSAGE} from './type.js';56// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in sync mode7export const handleInputSync = options => {8 const stdioStreamsGroups = handleInput(addPropertiesSync, options, true);7export const handleInputSync = (options, verboseInfo) => {8 const {stdioStreamsGroups} = handleInput(addPropertiesSync, options, verboseInfo, true);9 addInputOptionSync(stdioStreamsGroups, options);10 return stdioStreamsGroups;11};12
58 unmodified lines
added:lib/verbose/info.js+19 added
modified:lib/verbose/log.js+18 added-2 removed
added:lib/verbose/output.js+68 added
1import {inspect} from 'node:util';2import stripFinalNewline from 'strip-final-newline';3import {escapeLines} from '../arguments/escape.js';4import {PIPED_STDIO_VALUES} from '../stdio/forward.js';5import {verboseLog} from './log.js';67export const handleStreamsVerbose = ({stdioStreams, options, isSync, stdioState, verboseInfo}) => {8 if (!shouldLogOutput(stdioStreams, options, isSync, verboseInfo)) {9 return stdioStreams;10 }1112 const [{fdNumber}] = stdioStreams;13 return [...stdioStreams, {14 ...stdioStreams[0],15 type: 'generator',16 value: verboseGenerator.bind(undefined, {stdioState, fdNumber, verboseInfo}),17 }];18};1920// `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`.25const 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'));3132// Only print text output, not binary33// eslint-disable-next-line unicorn/text-encoding-identifier-case34const ALLOWED_ENCODINGS = new Set(['utf8', 'utf-8']);3536// 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.40const fdUsesVerbose = ([{fdNumber}]) => fdNumber === 1 || fdNumber === 2;4142const verboseGenerator = function * ({stdioState: {spawned: {stdio}}, fdNumber, verboseInfo}, line) {43 if (!isPiping(stdio[fdNumber])) {44 logOutput(line, verboseInfo);45 }4647 yield line;48};4950// 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.57const isPiping = stream => stream._readableState.pipes.length > 0;5859// When `verbose` is `full`, print stdout|stderr60const 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};6667// Same as `util.inspect()`68const TAB_SIZE = 2;
modified:lib/verbose/start.js+3 added-6 removed
1import {debuglog} from 'node:util';1import {verboseLog} from './log.js';23// When `verbose` is `short|full`, print each command5export const logCommand = (escapedCommand, {verbose = verboseDefault, piped = false}) => {6 if (!verbose) {4export const logCommand = (escapedCommand, {verbose, verboseId}, {piped = false}) => {5 if (verbose === 'none') {6 return;7 }89 const icon = piped ? 'pipedCommand' : 'command';11 verboseLog(escapedCommand, icon);10 verboseLog(escapedCommand, verboseId, icon);11};1314const verboseDefault = debuglog('execa').enabled;
modified:lib/async.js+7 added-7 removed
12 unmodified lines
13import {getSpawnedResult} from './stream/resolve.js';14import {mergePromise} from './promise.js';1516export 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};2425const 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};3334// Prevent passing the `timeout` option directly to `child_process.spawn()`35const handleAsyncOptions = ({timeout, signal, cancelSignal, ...options}) => {
3 unmodified lines
3940 return {...options, timeoutDuration: timeout, signal: cancelSignal};41};4243const spawnProcessAsync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {43const spawnProcessAsync = ({file, args, options, command, escapedCommand, stdioStreamsGroups, stdioState}) => {44 let spawned;45 try {46 spawned = spawn(file, args, options);47 } catch (error) {
3 unmodified lines
51 const controller = new AbortController();52 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);5354 const originalStreams = [...spawned.stdio];55 pipeOutputAsync(spawned, stdioStreamsGroups, controller);55 pipeOutputAsync(spawned, stdioStreamsGroups, stdioState, controller);56 cleanupOnExit(spawned, options, controller);5758 spawned.kill = spawnedKill.bind(undefined, {kill: spawned.kill.bind(spawned), spawned, options, controller});59 spawned.all = makeAllStream(spawned, options);
36 unmodified lines
modified:lib/sync.js+2 added-2 removed
11 unmodified lines
12};1314const 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};2324const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;
35 unmodified lines
added:test/fixtures/nested-big-array.js+8 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';4import {getOutputGenerator} from '../helpers/generator.js';56const bigArray = Array.from({length: 100}, (_, index) => index);7const [options, file, ...args] = process.argv.slice(2);8await execa(file, args, {stdout: getOutputGenerator(bigArray, true), ...JSON.parse(options)});
added:test/fixtures/nested-double.js+11 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, ...args] = process.argv.slice(2);6const firstArgs = args.slice(0, -1);7const lastArg = args.at(-1);8await 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 node2import process from 'node:process';3import {pathToFileURL} from 'node:url';4import {execa} from '../../index.js';56const [options, file, arg] = process.argv.slice(2);7const parsedOptions = JSON.parse(options);8await execa(file, [arg], {...parsedOptions, stdout: pathToFileURL(parsedOptions.stdout)});
added:test/fixtures/nested-object.js+7 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';4import {outputObjectGenerator} from '../helpers/generator.js';56const [options, file, ...args] = process.argv.slice(2);7await execa(file, args, {stdout: outputObjectGenerator, ...JSON.parse(options)});
added:test/fixtures/nested-pipe-child-process.js+15 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg, unpipe] = process.argv.slice(2);6const source = execa(file, [arg], JSON.parse(options));7const destination = execa('stdin.js');8const controller = new AbortController();9const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal});10if (unpipe === 'true') {11 controller.abort();12 destination.stdin.end();13}1415await Promise.allSettled([source, destination, pipePromise]);
added:test/fixtures/nested-pipe-stream.js+12 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg, unpipe] = process.argv.slice(2);6const childProcess = execa(file, [arg], JSON.parse(options));7childProcess.stdout.pipe(process.stdout);8if (unpipe === 'true') {9 childProcess.stdout.unpipe(process.stdout);10}1112await childProcess;
added:test/fixtures/nested-send.js+7 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, ...args] = process.argv.slice(2);6const result = await execa(file, args, JSON.parse(options));7process.send(result);
added:test/fixtures/nested-transform.js+7 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';4import {uppercaseGenerator} from '../helpers/generator.js';56const [options, file, ...args] = process.argv.slice(2);7await execa(file, args, {stdout: uppercaseGenerator, ...JSON.parse(options)});
added:test/fixtures/nested-writable-web.js+6 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg] = process.argv.slice(2);6await execa(file, [arg], {...JSON.parse(options), stdout: new WritableStream()});
added:test/fixtures/nested-writable.js+6 added
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg] = process.argv.slice(2);6await execa(file, [arg], {...JSON.parse(options), stdout: process.stdout});
added:test/fixtures/noop-progressive.js+11 added
1#!/usr/bin/env node2import process from 'node:process';3import {setTimeout} from 'node:timers/promises';45for (const character of process.argv[2]) {6 process.stdout.write(character);7 // eslint-disable-next-line no-await-in-loop8 await setTimeout(10);9}1011process.stdout.write('\n');
modified:test/fixtures/noop-repeat.js+1 added-1 removed
1 unmodified line
2import process from 'node:process';3import {writeSync} from 'node:fs';45setInterval(() => {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 lines
68 for await (const value of setInterval(100, 'foo')) {69 yield value;70 }71};7273export const uppercaseGenerator = function * (line) {74 yield line.toUpperCase();75};
modified:test/helpers/verbose.js+7 added-2 removed
5 unmodified lines
6const isWindows = platform === 'win32';7export const QUOTE = isWindows ? '"' : '\'';89// eslint-disable-next-line max-params10const nestedExeca = (fixtureName, file, args, options, parentOptions) => {10export 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 lines
21 return stderr;22};2324export 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};2930export const getCommandLine = stderr => getCommandLines(stderr)[0];31export const getCommandLines = stderr => getNormalizedLines(stderr).filter(line => isCommandLine(line));32const isCommandLine = line => line.includes(' $ ') || line.includes(' | ');33export const getOutputLine = stderr => getOutputLines(stderr)[0];34export const getOutputLines = stderr => getNormalizedLines(stderr).filter(line => isOutputLine(line));35const isOutputLine = line => line.includes('] ');36export const getNormalizedLines = stderr => splitLines(normalizeStderr(stderr));37const splitLines = stderr => stderr.split('\n');3839const normalizeStderr = stderr => normalizeTimestamp(stripVTControlCharacters(stderr));40export const testTimestamp = '[00:00:00.000]';41const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}]/gm, testTimestamp);4243export const getVerboseOption = (isVerbose, verbose = 'short') => ({verbose: isVerbose ? verbose : 'none'});
modified:test/stdio/generator.js+1 added-5 removed
5 unmodified lines
6import {execa} from '../../index.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {getStdio} from '../helpers/stdio.js';9import {foobarString, foobarUint8Array, foobarBuffer, foobarObject, foobarObjectString} from '../helpers/input.js';10import {serializeGenerator, outputObjectGenerator, addNoopGenerator} from '../helpers/generator.js';10import {serializeGenerator, outputObjectGenerator, addNoopGenerator, uppercaseGenerator} from '../helpers/generator.js';1112setFixtureDir();1314const textEncoder = new TextEncoder();
1 unmodified line
1617const foobarUppercase = foobarString.toUpperCase();18const foobarHex = foobarBuffer.toString('hex');1920const uppercaseGenerator = function * (line) {21 yield line.toUpperCase();22};2320const uppercaseBufferGenerator = function * (line) {21 yield textDecoder.decode(line).toUpperCase();22};23
322 unmodified lines
modified:test/verbose/info.js+9 added-6 removed
5 unmodified lines
6 QUOTE,7 nestedExecaAsync,8 nestedExecaSync,9 getCommandLine,10 getOutputLine,11 getNormalizedLines,12 testTimestamp,13} from '../helpers/verbose.js';14
1 unmodified line
1617test('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});2525test('NODE_DEBUG=execa changes verbose default value to true', async t => {26test('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});3132const 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};3738test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, nestedExecaAsync);39test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, nestedExecaSync);
modified:test/verbose/log.js+6 added-4 removed
8 unmodified lines
9 const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});10 t.is(stdout, foobarString);11};1213test('Logs on stderr not stdout, verbose false', testNoStdout, false, nestedExecaAsync);14test('Logs on stderr not stdout, verbose true', testNoStdout, true, nestedExecaAsync);15test('Logs on stderr not stdout, verbose false, sync', testNoStdout, false, nestedExecaSync);16test('Logs on stderr not stdout, verbose true, sync', testNoStdout, true, nestedExecaSync);13test('Logs on stderr not stdout, verbose "none"', testNoStdout, 'none', nestedExecaAsync);14test('Logs on stderr not stdout, verbose "short"', testNoStdout, 'short', nestedExecaAsync);15test('Logs on stderr not stdout, verbose "full"', testNoStdout, 'full', nestedExecaAsync);16test('Logs on stderr not stdout, verbose "none", sync', testNoStdout, 'none', nestedExecaSync);17test('Logs on stderr not stdout, verbose "short", sync', testNoStdout, 'short', nestedExecaSync);18test('Logs on stderr not stdout, verbose "full", sync', testNoStdout, 'full', nestedExecaSync);
added:test/verbose/output.js+234 added
1import {once, on} from 'node:events';2import {rm, readFile} from 'node:fs/promises';3import {inspect} from 'node:util';4import test from 'ava';5import tempfile from 'tempfile';6import {red} from 'yoctocolors';7import {execa} from '../../index.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {foobarString, foobarObject} from '../helpers/input.js';10import {fullStdio} from '../helpers/stdio.js';11import {12 nestedExeca,13 nestedExecaAsync,14 nestedExecaSync,15 runErrorProcess,16 getOutputLine,17 getOutputLines,18 testTimestamp,19 getVerboseOption,20} from '../helpers/verbose.js';2122setFixtureDir();2324const nestedExecaDouble = nestedExeca.bind(undefined, 'nested-double.js');2526const 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};3031test('Prints stdout, verbose "full"', testPrintOutput, 1, nestedExecaAsync);32test('Prints stderr, verbose "full"', testPrintOutput, 2, nestedExecaAsync);3334const 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};3839test('Does not print stdout, verbose "none"', testNoPrintOutput, 'none', 1, nestedExecaAsync);40test('Does not print stdout, verbose "short"', testNoPrintOutput, 'short', 1, nestedExecaAsync);41test('Does not print stdout, verbose "full", sync', testNoPrintOutput, 'full', 1, nestedExecaSync);42test('Does not print stdout, verbose "none", sync', testNoPrintOutput, 'none', 1, nestedExecaSync);43test('Does not print stdout, verbose "short", sync', testNoPrintOutput, 'short', 1, nestedExecaSync);44test('Does not print stderr, verbose "none"', testNoPrintOutput, 'none', 2, nestedExecaAsync);45test('Does not print stderr, verbose "short"', testNoPrintOutput, 'short', 2, nestedExecaAsync);46test('Does not print stderr, verbose "full", sync', testNoPrintOutput, 'full', 2, nestedExecaSync);47test('Does not print stderr, verbose "none", sync', testNoPrintOutput, 'none', 2, nestedExecaSync);48test('Does not print stderr, verbose "short", sync', testNoPrintOutput, 'short', 2, nestedExecaSync);49test('Does not print stdio[*], verbose "none"', testNoPrintOutput, 'none', 3, nestedExecaAsync);50test('Does not print stdio[*], verbose "short"', testNoPrintOutput, 'short', 3, nestedExecaAsync);51test('Does not print stdio[*], verbose "full"', testNoPrintOutput, 'full', 3, nestedExecaAsync);52test('Does not print stdio[*], verbose "none", sync', testNoPrintOutput, 'none', 3, nestedExecaSync);53test('Does not print stdio[*], verbose "short", sync', testNoPrintOutput, 'short', 3, nestedExecaSync);54test('Does not print stdio[*], verbose "full", sync', testNoPrintOutput, 'full', 3, nestedExecaSync);5556test('Prints stdout after errors', async t => {57 const stderr = await runErrorProcess(t, 'full', nestedExecaAsync);58 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);59});6061const 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 ]);6970 const lines = getOutputLines(stderr);71 const id = sourceVerbose && destinationVerbose ? 1 : 0;72 t.deepEqual(lines, destinationVerbose73 ? [`${testTimestamp} [${id}] ${foobarString}`]74 : []);75};7677test('Prints stdout if both verbose with .pipe("file")', testPipeOutput, 'file', true, true);78test('Prints stdout if both verbose with .pipe`command`', testPipeOutput, 'script', true, true);79test('Prints stdout if both verbose with .pipe(childProcess)', testPipeOutput, 'process', true, true);80test('Prints stdout if only second verbose with .pipe("file")', testPipeOutput, 'file', false, true);81test('Prints stdout if only second verbose with .pipe`command`', testPipeOutput, 'script', false, true);82test('Prints stdout if only second verbose with .pipe(childProcess)', testPipeOutput, 'process', false, true);83test('Does not print stdout if only first verbose with .pipe("file")', testPipeOutput, 'file', true, false);84test('Does not print stdout if only first verbose with .pipe`command`', testPipeOutput, 'script', true, false);85test('Does not print stdout if only first verbose with .pipe(childProcess)', testPipeOutput, 'process', true, false);86test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);87test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);88test('Does not print stdout if neither verbose with .pipe(childProcess)', testPipeOutput, 'process', false, false);8990test('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});9495test('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});99100test('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});104105test('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});109110test('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});114115const 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};120121test('Does not change stdout', testStdioSame, 1);122test('Does not change stderr', testStdioSame, 2);123124test('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});128129test('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});133134test('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});141142test('Prints stdout one line at a time', async t => {143 const childProcess = nestedExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});144145 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 }152153 await childProcess;154});155156test('Prints stdout progressively, interleaved', async t => {157 const childProcess = nestedExecaDouble('noop-repeat.js', ['1', `${foobarString}\n`], {verbose: 'full'});158159 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 }166167 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 }174175 if (firstProcessPrinted && secondProcessPrinted) {176 break;177 }178 }179180 childProcess.kill();181 await t.throwsAsync(childProcess);182});183184test('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});188189const 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};193194test('Does not print stdout, encoding "buffer"', testNoOutputOptions, {encoding: 'buffer'});195test('Does not print stdout, encoding "hex"', testNoOutputOptions, {encoding: 'hex'});196test('Does not print stdout, encoding "base64"', testNoOutputOptions, {encoding: 'base64'});197test('Does not print stdout, stdout "ignore"', testNoOutputOptions, {stdout: 'ignore'});198test('Does not print stdout, stdout "inherit"', testNoOutputOptions, {stdout: 'inherit'});199test('Does not print stdout, stdout 1', testNoOutputOptions, {stdout: 1});200test('Does not print stdout, stdout Writable', testNoOutputOptions, {}, 'nested-writable.js');201test('Does not print stdout, stdout WritableStream', testNoOutputOptions, {}, 'nested-writable-web.js');202test('Does not print stdout, .pipe(stream)', testNoOutputOptions, {}, 'nested-pipe-stream.js');203test('Does not print stdout, .pipe(childProcess)', testNoOutputOptions, {}, 'nested-pipe-child-process.js');204205const 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};213214test('Does not print stdout, stdout { file }', testStdoutFile, 'nested.js', file => ({file}));215test('Does not print stdout, stdout fileUrl', testStdoutFile, 'nested-file-url.js', file => file);216217const testPrintOutputOptions = async (t, options) => {218 const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {verbose: 'full', ...options});219 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);220};221222test('Prints stdout, stdout "pipe"', testPrintOutputOptions, {stdout: 'pipe'});223test('Prints stdout, stdout "overlapped"', testPrintOutputOptions, {stdout: 'overlapped'});224test('Prints stdout, stdout null', testPrintOutputOptions, {stdout: null});225test('Prints stdout, stdout ["pipe"]', testPrintOutputOptions, {stdout: ['pipe']});226test('Prints stdout, buffer false', testPrintOutputOptions, {buffer: false});227228const 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};232233test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');234test('Prints stdout, .pipe(childProcess) + .unpipe()', testPrintOutputFixture, 'nested-pipe-child-process.js', 'true');
modified:test/verbose/start.js+27 added-24 removed
10 unmodified lines
11 runEarlyErrorProcess,12 getCommandLine,13 getCommandLines,14 testTimestamp,15 getVerboseOption,16} from '../helpers/verbose.js';1718setFixtureDir();1919const testPrintCommand = async (t, execaMethod) => {20 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: true});21 t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${foobarString}`);20const 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};2424test('Prints command', testPrintCommand, nestedExecaAsync);25test('Prints command, sync', testPrintCommand, nestedExecaSync);25test('Prints command, verbose "short"', testPrintCommand, 'short', nestedExecaAsync);26test('Prints command, verbose "full"', testPrintCommand, 'full', nestedExecaAsync);27test('Prints command, verbose "short", sync', testPrintCommand, 'short', nestedExecaSync);28test('Prints command, verbose "full", sync', testPrintCommand, 'full', nestedExecaSync);2930const 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};3432test('Does not print command', testNoPrintCommand, nestedExecaAsync);33test('Does not print command, sync', testNoPrintCommand, nestedExecaSync);35test('Does not print command, verbose "none"', testNoPrintCommand, nestedExecaAsync);36test('Does not print command, verbose "none", sync', testNoPrintCommand, nestedExecaSync);3738const 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};4243test('Prints command after errors', testPrintCommandError, nestedExecaAsync);44test('Prints command after errors, sync', testPrintCommandError, nestedExecaSync);4546const 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};5051test('Prints command before early validation errors', testPrintCommandEarly, nestedExecaAsync);52test('Prints command before early validation errors, sync', testPrintCommandEarly, nestedExecaSync);5354const 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};6768test('Prints both commands piped with .pipe("file")', testPipeCommand, 'file', true, true);69test('Prints both commands piped with .pipe`command`', testPipeCommand, 'script', true, true);
8 unmodified lines
78test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);79test('Prints neither commands piped with .pipe(childProcess)', testPipeCommand, 'process', false, false);8081test('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});8586test('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});9091test('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});9596test('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});100101test('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 lines
542 */543 readonly windowsHide?: boolean;544545 /**546 Print each command on `stderr` before executing it.546 If `verbose` is `'short'` or `'full'`, prints each command on `stderr` before executing it.547548 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.552553 This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.554550 @default false555 @default 'none'556 */552 readonly verbose?: boolean;557 readonly verbose?: 'none' | 'short' | 'full';558559 /**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 lines
10321033/**1034Same as `execa()` but synchronous.10351031Cannot 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.1036Cannot 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.10371038Returns 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.10391040@param file - The program/script to execute, as a string or file URL
92 unmodified lines
11331134/**1135Same as `execaCommand()` but synchronous.11361132Cannot 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.1137Cannot 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.11381139Returns 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.11401141@param command - The program/script to execute and its arguments.
49 unmodified lines
11911192 /**1193 Same as $\`command\` but synchronous.11941190 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.11961197 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.11981199 @returns A `childProcessResult` object
45 unmodified lines
12451246 /**1247 Same as $\`command\` but synchronous.12481244 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.12501251 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.12521253 @returns A `childProcessResult` object
132 unmodified lines
modified:index.test-d.ts+6 added-2 removed
1438 unmodified lines
1439execa('unicorns', {windowsVerbatimArguments: true});1440execaSync('unicorns', {windowsVerbatimArguments: true});1441execa('unicorns', {windowsHide: false});1442execaSync('unicorns', {windowsHide: false});1443execa('unicorns', {verbose: false});1444execaSync('unicorns', {verbose: false});1443execa('unicorns', {verbose: 'none'});1444execaSync('unicorns', {verbose: 'none'});1445execa('unicorns', {verbose: 'short'});1446execaSync('unicorns', {verbose: 'short'});1447execa('unicorns', {verbose: 'full'});1448execaSync('unicorns', {verbose: 'full'});1449expectError(execa('unicorns', {verbose: 'other'}));1450expectError(execaSync('unicorns', {verbose: 'other'}));1451/* eslint-enable @typescript-eslint/no-floating-promises */1452expectType<boolean>(execa('unicorns').kill());
115 unmodified lines
modified:readme.md+12 added-7 removed
140 unmodified lines
141unicorns142rainbows143144> NODE_DEBUG=execa node file.js145[19:49:00.360] $ echo unicorns145[19:49:00.360] [0] $ echo unicorns146unicorns147[19:49:00.383] $ echo rainbows147[19:49:00.383] [1] $ echo rainbows148rainbows149```150151### Input/output
162 unmodified lines
314#### $.s(options)\`command\`315316Same as [`execa()`](#execacommandcommand-options), [`execaCommand()`](#execacommand-command-options), [$\`command\`](#command) but synchronous.317318Cannot 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.318Cannot 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.319320Returns 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.321322### Shell syntax
340 unmodified lines
663Requires the [`node`](#node) option to be `true`.664665#### verbose666667Type: `boolean`\668Default: `false`667Type: `'none' | 'short' | 'full'`\668Default: `'none'`669670[Print each command](#verbose-mode) on `stderr` before executing it.670If `verbose` is `'short'` or `'full'`, [prints each command](#verbose-mode) on `stderr` before executing it.671672This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process.672If `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.676677This can also be set to `'full'` by setting the `NODE_DEBUG=execa` environment variable in the current process.678679#### buffer680681Type: `boolean`\682Default: `true`
365 unmodified lines