Improve `verbose` option (#883)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent de32969 · Browse files · 21 files·+292 added−86 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
21 files+292 added−86 removed
- tests:+219 added−38 removed
- other:+73 added−48 removed
Provenance
- Commit
7d0943f- Tree
82a9aa3- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
de32969
21 files changed+292 added−86 removed
modified:docs/scripts.md+6 added
413 unmodified lines414 ```415 NODE_DEBUG=execa node file.js416 ```417 418+Which prints:419+420+```421+[19:49:00.360] $ echo example422+```423+424 ### Piping stdout to another command425 426 ```sh427 # Bash288 unmodified linesmodified:lib/arguments/options.js+7 added-7 removed
3 unmodified lines45678991011121322 unmodified lines363738394040414243444546474849508 unmodified lines5960616259606163646566677 unmodified lines75767778777980818211 unmodified lines9495969797989910010113 unmodified lines3 unmodified linesimport {npmRunPathEnv} from 'npm-run-path';import isPlainObject from 'is-plain-obj';import {normalizeForceKillAfterDelay} from '../exit/kill.js';import {validateTimeout} from '../exit/timeout.js';import {logCommand} from '../verbose/start.js';import {handleNodeOption} from './node.js';import {logCommand, verboseDefault} from './verbose.js';import {joinCommand} from './escape.js';import {normalizeCwd, safeNormalizeFileUrl, normalizeFileUrl} from './cwd.js';
export const normalizeArguments = (rawFile, rawArgs = [], rawOptions = {}) => {22 unmodified lines
return [filePath, normalizedArgs, options];};
export const handleArguments = (filePath, rawArgs, rawOptions) => {export const handleCommand = (filePath, rawArgs, rawOptions) => { const {command, escapedCommand} = joinCommand(filePath, rawArgs); logCommand(escapedCommand, rawOptions); return {command, escapedCommand};};
export const handleArguments = (filePath, rawArgs, rawOptions) => { rawOptions.cwd = normalizeCwd(rawOptions.cwd); const [processedFile, processedArgs, processedOptions] = handleNodeOption(filePath, rawArgs, rawOptions);
const {command: file, args, options: initialOptions} = crossSpawn._parse(processedFile, processedArgs, processedOptions);8 unmodified lines // #116 args.unshift('/q'); }
logCommand(escapedCommand, options);
return {file, args, command, escapedCommand, options}; return {file, args, options};};
const addDefaultOptions = ({ maxBuffer = DEFAULT_MAX_BUFFER,7 unmodified lines reject = true, cleanup = true, all = false, windowsHide = true, verbose = verboseDefault, killSignal = 'SIGTERM', forceKillAfterDelay = true, lines = false, ipc = false,11 unmodified lines reject, cleanup, all, windowsHide, verbose, killSignal, forceKillAfterDelay, lines, ipc,13 unmodified linesdeleted:lib/arguments/verbose.js-22 removed
12345678910111213141516171819202122import {writeFileSync} from 'node:fs';import {debuglog} from 'node:util';import process from 'node:process';
export const verboseDefault = debuglog('execa').enabled;
export const logCommand = (escapedCommand, {verbose}) => { if (!verbose) { return; }
// Write synchronously to ensure it is written before spawning the child process. // This guarantees this line is written to `stderr` before the child process prints anything. writeFileSync(process.stderr.fd, `[${getTimestamp()}] ${escapedCommand}\n`);};
const getTimestamp = () => { const date = new Date(); return `${padField(date.getHours(), 2)}:${padField(date.getMinutes(), 2)}:${padField(date.getSeconds(), 2)}.${padField(date.getMilliseconds(), 3)}`;};
const padField = (field, padding) => String(field).padStart(padding, '0');modified:lib/pipe/validate.js+4 added-2 removed
39 unmodified lines40 };41 42 const getDestination = (destinationOptions, firstArgument, ...args) => {43 if (Array.isArray(firstArgument)) {44- const destination = create$({...destinationOptions, stdin: 'pipe'})(firstArgument, ...args);44+ const destination = create$({...destinationOptions, ...PIPED_PROCESS_OPTIONS})(firstArgument, ...args);45 return {destination, pipeOptions: destinationOptions};46 }47 48 if (typeof firstArgument === 'string' || firstArgument instanceof URL) {1 unmodified line50 throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)(execa("file", ...)).');51 }52 53 const [rawFile, rawArgs, rawOptions] = normalizeArguments(firstArgument, ...args);54- const destination = execa(rawFile, rawArgs, {...rawOptions, stdin: 'pipe'});54+ const destination = execa(rawFile, rawArgs, {...rawOptions, ...PIPED_PROCESS_OPTIONS});55 return {destination, pipeOptions: rawOptions};56 }57 58 if (PROCESS_OPTIONS.has(firstArgument)) {6 unmodified lines65 66 throw new TypeError(`The first argument must be a template string, an options object, or an Execa child process: ${firstArgument}`);67 };68 69+const PIPED_PROCESS_OPTIONS = {stdin: 'pipe', piped: true};70+71 export const PROCESS_OPTIONS = new WeakMap();72 73 const getSourceStream = (source, stdioStreamsGroups, from, sourceOptions) => {74 try {77 unmodified linesadded:lib/verbose/log.js+20 added
1234567891011121314151617181920import {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`);};
// 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)}`;};
const padField = (field, padding) => String(field).padStart(padding, '0');
const ICONS = { command: '$', pipedCommand: '|',};added:lib/verbose/start.js+14 added
1234567891011121314import {debuglog} from 'node:util';import {verboseLog} from './log.js';
// When `verbose` is `short|full`, print each commandexport const logCommand = (escapedCommand, {verbose = verboseDefault, piped = false}) => { if (!verbose) { return; }
const icon = piped ? 'pipedCommand' : 'command'; verboseLog(escapedCommand, icon);};
const verboseDefault = debuglog('execa').enabled;modified:lib/async.js+8 added-7 removed
1 import {setMaxListeners} from 'node:events';2 import {spawn} from 'node:child_process';3-import {normalizeArguments, handleArguments} from './arguments/options.js';3+import {normalizeArguments, handleCommand, handleArguments} from './arguments/options.js';4 import {makeError, makeSuccessResult} from './return/error.js';5 import {handleOutput, handleResult} from './return/output.js';6 import {handleEarlyError} from './return/early-error.js';7 import {handleInputAsync, pipeOutputAsync} from './stdio/async.js';5 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} = handleAsyncArguments(rawFile, rawArgs, rawOptions);18- const stdioStreamsGroups = handleInputAsync(options);19- const {spawned, promise} = runExeca({file, args, options, command, escapedCommand, stdioStreamsGroups});17+ const {file, args, command, escapedCommand, options, stdioStreamsGroups} = handleAsyncArguments(rawFile, rawArgs, rawOptions);18+ const {spawned, promise} = spawnProcessAsync({file, args, options, command, escapedCommand, stdioStreamsGroups});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);28- const {file, args, command, escapedCommand, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);27+ const {command, escapedCommand} = handleCommand(rawFile, rawArgs, rawOptions);28+ const {file, args, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);29 const options = handleAsyncOptions(normalizedOptions);30+ const stdioStreamsGroups = handleInputAsync(options);30- return {file, args, command, escapedCommand, options};31+ return {file, args, command, escapedCommand, options, stdioStreamsGroups};32 };33 34 // Prevent passing the `timeout` option directly to `child_process.spawn()`35 const handleAsyncOptions = ({timeout, ...options}) => ({...options, timeoutDuration: timeout});36 36-const runExeca = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {37+const spawnProcessAsync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {38 let spawned;39 try {40 spawned = spawn(file, args, options);41 } catch (error) {48 unmodified linesmodified:lib/sync.js+8 added-7 removed
1 import {spawnSync} from 'node:child_process';2-import {normalizeArguments, handleArguments} from './arguments/options.js';2+import {normalizeArguments, handleCommand, handleArguments} from './arguments/options.js';3 import {makeError, makeEarlyError, makeSuccessResult} from './return/error.js';4 import {handleOutput, handleResult} from './return/output.js';5 import {handleInputSync, pipeOutputSync} from './stdio/sync.js';6 import {isFailedExit} from './exit/code.js';7 8 export const execaSync = (rawFile, rawArgs, rawOptions) => {9- const {file, args, command, escapedCommand, options} = handleSyncArguments(rawFile, rawArgs, rawOptions);10- const stdioStreamsGroups = handleInputSync(options);11- const result = runExecaSync({file, args, options, command, escapedCommand, stdioStreamsGroups});9+ const {file, args, command, escapedCommand, options, stdioStreamsGroups} = handleSyncArguments(rawFile, rawArgs, rawOptions);10+ const result = spawnProcessSync({file, args, options, command, escapedCommand, stdioStreamsGroups});11 return handleResult(result, options);12 };13 14 const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {15 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);16+ const {command, escapedCommand} = handleCommand(rawFile, rawArgs, rawOptions);17 const syncOptions = normalizeSyncOptions(rawOptions);18- const {file, args, command, escapedCommand, options} = handleArguments(rawFile, rawArgs, syncOptions);18+ const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);19 validateSyncOptions(options);20+ const stdioStreamsGroups = handleInputSync(options);20- return {file, args, command, escapedCommand, options};21+ return {file, args, command, escapedCommand, options, stdioStreamsGroups};22 };23 24 const normalizeSyncOptions = options => options.node && !options.ipc ? {...options, ipc: false} : options;25 2 unmodified lines28 throw new TypeError('The "ipc: true" option cannot be used with synchronous methods.');29 }30 };31 31-const runExecaSync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {32+const spawnProcessSync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {33 let syncResult;34 try {35 syncResult = spawnSync(file, args, options);36 } catch (error) {23 unmodified linesdeleted:test/arguments/verbose.js-37 removed
1-import {platform} from 'node:process';2-import test from 'ava';3-import {execa} from '../../index.js';4-import {setFixtureDir} from '../helpers/fixtures-dir.js';5-6-setFixtureDir();7-8-const isWindows = platform === 'win32';9-10-const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}]/gm, testTimestamp);11-const testTimestamp = '[00:00:00.000]';12-13-test('Prints command when "verbose" is true', async t => {14- const {stdout, stderr} = await execa('nested.js', [JSON.stringify({verbose: true, stdio: 'inherit'}), 'noop.js', 'test'], {all: true});15- t.is(stdout, 'test');16- t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);17-});18-19-test('Prints command with NODE_DEBUG=execa', async t => {20- const {stdout, stderr} = await execa('nested.js', [JSON.stringify({stdio: 'inherit'}), 'noop.js', 'test'], {all: true, env: {NODE_DEBUG: 'execa'}});21- t.is(stdout, 'test');22- t.is(normalizeTimestamp(stderr), `${testTimestamp} noop.js test`);23-});24-25-test('Escape verbose command', async t => {26- const {stderr} = await execa('nested.js', [JSON.stringify({verbose: true, stdio: 'inherit'}), 'noop.js', 'one two', '"'], {all: true});27- t.true(stderr.endsWith(isWindows ? '"one two" """"' : '\'one two\' \'"\''));28-});29-30-test('Verbose option works with inherit', async t => {31- const {all} = await execa('verbose-script.js', {all: true, env: {NODE_DEBUG: 'execa'}});32- const quote = isWindows ? '"' : '\'';33- t.is(normalizeTimestamp(all), `${testTimestamp} node -e ${quote}console.error(1)${quote}34-135-${testTimestamp} node -e ${quote}console.error(2)${quote}36-2`);37-});added:test/fixtures/nested-pipe-file.js+7 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [sourceOptions, sourceFile, sourceArg, destinationOptions, destinationFile, destinationArg] = process.argv.slice(2);6+await execa(sourceFile, [sourceArg], JSON.parse(sourceOptions))7+ .pipe(destinationFile, destinationArg === undefined ? [] : [destinationArg], JSON.parse(destinationOptions));added:test/fixtures/nested-pipe-process.js+7 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execa} from '../../index.js';4+5+const [sourceOptions, sourceFile, sourceArg, destinationOptions, destinationFile, destinationArg] = process.argv.slice(2);6+await execa(sourceFile, [sourceArg], JSON.parse(sourceOptions))7+ .pipe(execa(destinationFile, destinationArg === undefined ? [] : [destinationArg], JSON.parse(destinationOptions)));added:test/fixtures/nested-pipe-script.js+7 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {$} from '../../index.js';4+5+const [sourceOptions, sourceFile, sourceArg, destinationOptions, destinationFile, destinationArg] = process.argv.slice(2);6+await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArg}`7+ .pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArg === undefined ? [] : [destinationArg]}`;added:test/fixtures/nested-sync.js+6 added
1+#!/usr/bin/env node2+import process from 'node:process';3+import {execaSync} from '../../index.js';4+5+const [options, file, ...args] = process.argv.slice(2);6+execaSync(file, args, JSON.parse(options));modified:test/fixtures/verbose-script.js+1 added-1 removed
1 unmodified line2 import {$} from '../../index.js';3 4 const $$ = $({stdio: 'inherit'});5 await $$`node -e console.error(1)`;6-await $$`node -e console.error(2)`;6+await $$({reject: false})`node -e process.exit(2)`;added:test/helpers/verbose.js+38 added
1+import {platform} from 'node:process';2+import {stripVTControlCharacters} from 'node:util';3+import {execa} from '../../index.js';4+import {foobarString} from './input.js';5+6+const isWindows = platform === 'win32';7+export const QUOTE = isWindows ? '"' : '\'';8+9+// eslint-disable-next-line max-params10+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+15+export const nestedExecaAsync = nestedExeca.bind(undefined, 'nested.js');16+export const nestedExecaSync = nestedExeca.bind(undefined, 'nested-sync.js');17+18+export const runErrorProcess = async (t, verbose, execaMethod) => {19+ const {stderr} = await t.throwsAsync(execaMethod('noop-fail.js', ['1', foobarString], {verbose}));20+ t.true(stderr.includes('exit code 2'));21+ 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}));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 getNormalizedLines = stderr => splitLines(normalizeStderr(stderr));34+const splitLines = stderr => stderr.split('\n');35+36+const normalizeStderr = stderr => normalizeTimestamp(stripVTControlCharacters(stderr));37+export const testTimestamp = '[00:00:00.000]';38+const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}]/gm, testTimestamp);added:test/verbose/info.js+36 added
1+import test from 'ava';2+import {setFixtureDir} from '../helpers/fixtures-dir.js';3+import {execa} from '../../index.js';4+import {foobarString} from '../helpers/input.js';5+import {6+ QUOTE,7+ nestedExecaAsync,8+ nestedExecaSync,9+ getCommandLine,10+ getNormalizedLines,11+ testTimestamp,12+} from '../helpers/verbose.js';13+14+setFixtureDir();15+16+test('Prints command, NODE_DEBUG=execa + "inherit"', async t => {17+ const {all} = await execa('verbose-script.js', {env: {NODE_DEBUG: 'execa'}, all: true});18+ t.deepEqual(getNormalizedLines(all), [19+ `${testTimestamp} $ node -e ${QUOTE}console.error(1)${QUOTE}`,20+ '1',21+ `${testTimestamp} $ node -e ${QUOTE}process.exit(2)${QUOTE}`,22+ ]);23+});24+25+test('NODE_DEBUG=execa changes verbose default value to true', async t => {26+ const {stderr} = await nestedExecaAsync('noop.js', [foobarString], {}, {env: {NODE_DEBUG: 'execa'}});27+ t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${foobarString}`);28+});29+30+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+};34+35+test('NODE_DEBUG=execa has lower priority', testDebugEnvPriority, nestedExecaAsync);36+test('NODE_DEBUG=execa has lower priority, sync', testDebugEnvPriority, nestedExecaSync);added:test/verbose/log.js+16 added
1+import test from 'ava';2+import {setFixtureDir} from '../helpers/fixtures-dir.js';3+import {foobarString} from '../helpers/input.js';4+import {nestedExecaAsync, nestedExecaSync} from '../helpers/verbose.js';5+6+setFixtureDir();7+8+const testNoStdout = async (t, verbose, execaMethod) => {9+ 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);added:test/verbose/start.js+101 added
1+import test from 'ava';2+import {red} from 'yoctocolors';3+import {execa} from '../../index.js';4+import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {foobarString} from '../helpers/input.js';6+import {7+ QUOTE,8+ nestedExecaAsync,9+ nestedExecaSync,10+ runErrorProcess,11+ runEarlyErrorProcess,12+ getCommandLine,13+ getCommandLines,14+ testTimestamp,15+} from '../helpers/verbose.js';16+17+setFixtureDir();18+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}`);22+};23+24+test('Prints command', testPrintCommand, nestedExecaAsync);25+test('Prints command, sync', testPrintCommand, nestedExecaSync);26+27+const testNoPrintCommand = async (t, execaMethod) => {28+ const {stderr} = await execaMethod('noop.js', [foobarString], {verbose: false});29+ t.is(stderr, '');30+};31+32+test('Does not print command', testNoPrintCommand, nestedExecaAsync);33+test('Does not print command, sync', testNoPrintCommand, nestedExecaSync);34+35+const testPrintCommandError = async (t, execaMethod) => {36+ const stderr = await runErrorProcess(t, true, execaMethod);37+ t.is(getCommandLine(stderr), `${testTimestamp} $ noop-fail.js 1 ${foobarString}`);38+};39+40+test('Prints command after errors', testPrintCommandError, nestedExecaAsync);41+test('Prints command after errors, sync', testPrintCommandError, nestedExecaSync);42+43+const testPrintCommandEarly = async (t, execaMethod) => {44+ const stderr = await runEarlyErrorProcess(t, execaMethod);45+ t.is(getCommandLine(stderr), `${testTimestamp} $ noop.js ${foobarString}`);46+};47+48+test('Prints command before early validation errors', testPrintCommandEarly, nestedExecaAsync);49+test('Prints command before early validation errors, sync', testPrintCommandEarly, nestedExecaSync);50+51+const testPipeCommand = async (t, fixtureName, sourceVerbose, destinationVerbose) => {52+ const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [53+ JSON.stringify({verbose: sourceVerbose}),54+ 'noop.js',55+ foobarString,56+ JSON.stringify({verbose: destinationVerbose}),57+ 'stdin.js',58+ ]);59+ const pipeSymbol = fixtureName === 'process' ? '$' : '|';60+ const lines = getCommandLines(stderr);61+ t.is(lines.includes(`${testTimestamp} $ noop.js ${foobarString}`), sourceVerbose);62+ t.is(lines.includes(`${testTimestamp} ${pipeSymbol} stdin.js`), destinationVerbose);63+};64+65+test('Prints both commands piped with .pipe("file")', testPipeCommand, 'file', true, true);66+test('Prints both commands piped with .pipe`command`', testPipeCommand, 'script', true, true);67+test('Prints both commands piped with .pipe(childProcess)', testPipeCommand, 'process', true, true);68+test('Prints first command piped with .pipe("file")', testPipeCommand, 'file', true, false);69+test('Prints first command piped with .pipe`command`', testPipeCommand, 'script', true, false);70+test('Prints first command piped with .pipe(childProcess)', testPipeCommand, 'process', true, false);71+test('Prints second command piped with .pipe("file")', testPipeCommand, 'file', false, true);72+test('Prints second command piped with .pipe`command`', testPipeCommand, 'script', false, true);73+test('Prints second command piped with .pipe(childProcess)', testPipeCommand, 'process', false, true);74+test('Prints neither commands piped with .pipe("file")', testPipeCommand, 'file', false, false);75+test('Prints neither commands piped with .pipe`command`', testPipeCommand, 'script', false, false);76+test('Prints neither commands piped with .pipe(childProcess)', testPipeCommand, 'process', false, false);77+78+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}`);81+});82+83+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}`);86+});87+88+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}`);91+});92+93+test('Escapes color sequences from command', async t => {94+ const {stderr} = await nestedExecaAsync('noop.js', [red(foobarString)], {verbose: true}, {env: {FORCE_COLOR: '1'}});95+ t.true(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));96+});97+98+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}`);101+});modified:index.test-d.ts+2 added
1440 unmodified lines1441 execa('unicorns', {windowsHide: false});1442 execaSync('unicorns', {windowsHide: false});1443 execa('unicorns', {verbose: false});1444 execaSync('unicorns', {verbose: false});1445+expectError(execa('unicorns', {verbose: 'other'}));1446+expectError(execaSync('unicorns', {verbose: 'other'}));1447 /* eslint-enable @typescript-eslint/no-floating-promises */1448 expectType<boolean>(execa('unicorns').kill());1449 execa('unicorns').kill('SIGKILL');1450 execa('unicorns').kill(undefined);113 unmodified linesmodified:package.json+2 added-1 removed
64 unmodified lines65 "path-key": "^4.0.0",66 "tempfile": "^5.0.0",67 "tsd": "^0.29.0",68 "which": "^4.0.0",69- "xo": "^0.56.0"69+ "xo": "^0.56.0",70+ "yoctocolors": "^2.0.0"71 },72 "c8": {73 "reporter": [74 "text",20 unmodified linesmodified:readme.md+2 added-2 removed
140 unmodified lines141 unicorns142 rainbows143 144 > NODE_DEBUG=execa node file.js145-[16:50:03.305] echo unicorns145+[19:49:00.360] $ echo unicorns146 unicorns147-[16:50:03.308] echo rainbows147+[19:49:00.383] $ echo rainbows148 rainbows149 ```150 151 ### Input/output891 unmodified lines