Add `result|error.durationMs` (#896)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 6a7a82c · Browse files · 20 files·+181 added−72 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
20 files+181 added−72 removed
- tests:+74 added−6 removed
- other:+107 added−66 removed
Provenance
- Commit
7088091- Tree
ea79663- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
6a7a82c
20 files changed+181 added−72 removed
modified:lib/arguments/options.js+3 added-1 removed
5 unmodified lines6789101112131424 unmodified lines394041424344454645474849505167 unmodified lines5 unmodified linesimport {normalizeForceKillAfterDelay} from '../exit/kill.js';import {validateTimeout} from '../exit/timeout.js';import {logCommand} from '../verbose/start.js';import {getVerboseInfo} from '../verbose/info.js';import {getStartTime} from '../return/duration.js';import {handleNodeOption} from './node.js';import {joinCommand} from './escape.js';import {normalizeCwd, safeNormalizeFileUrl, normalizeFileUrl} from './cwd.js';
24 unmodified lines return [filePath, normalizedArgs, options];};
export const handleCommand = (filePath, rawArgs, rawOptions) => { const startTime = getStartTime(); const {command, escapedCommand} = joinCommand(filePath, rawArgs); const verboseInfo = getVerboseInfo(rawOptions); logCommand(escapedCommand, verboseInfo, rawOptions); return {command, escapedCommand, verboseInfo}; return {command, escapedCommand, startTime, verboseInfo};};
export const handleArguments = (filePath, rawArgs, rawOptions) => { rawOptions.cwd = normalizeCwd(rawOptions.cwd);67 unmodified linesmodified:lib/pipe/abort.js+2 added-2 removed
3 unmodified lines456788910111212133 unmodified linesexport const unpipeOnAbort = (unpipeSignal, ...args) => unpipeSignal === undefined ? [] : [unpipeOnSignalAbort(unpipeSignal, ...args)];
const unpipeOnSignalAbort = async (unpipeSignal, {sourceStream, mergedStream, stdioStreamsGroups, sourceOptions}) => {const unpipeOnSignalAbort = async (unpipeSignal, {sourceStream, mergedStream, stdioStreamsGroups, sourceOptions, startTime}) => { await aborted(unpipeSignal, sourceStream); await mergedStream.remove(sourceStream); const error = new Error('Pipe cancelled by `unpipeSignal` option.'); throw createNonCommandError({error, stdioStreamsGroups, sourceOptions}); throw createNonCommandError({error, stdioStreamsGroups, sourceOptions, startTime});};modified:lib/pipe/setup.js+3 added-1 removed
28 unmodified lines2930313233343536373839404142434445464748494850515253546 unmodified lines28 unmodified lines destinationStream, destinationError, unpipeSignal, stdioStreamsGroups, startTime,}) => { const processPromises = getProcessPromises(sourcePromise, destination); handlePipeArgumentsError({ sourceStream, sourceError, destinationStream, destinationError, stdioStreamsGroups, sourceOptions, startTime, }); const maxListenersController = new AbortController(); try { const mergedStream = pipeProcessStream(sourceStream, destinationStream, maxListenersController); return await Promise.race([ waitForBothProcesses(processPromises), ...unpipeOnAbort(unpipeSignal, {sourceStream, mergedStream, sourceOptions, stdioStreamsGroups}), ...unpipeOnAbort(unpipeSignal, {sourceStream, mergedStream, sourceOptions, stdioStreamsGroups, startTime}), ]); } finally { maxListenersController.abort(); }6 unmodified linesmodified:lib/pipe/throw.js+4 added-2 removed
6 unmodified lines7 destinationStream,8 destinationError,9 stdioStreamsGroups,10 sourceOptions,11+ startTime,12 }) => {13 const error = getPipeArgumentsError({sourceStream, sourceError, destinationStream, destinationError});14 if (error !== undefined) {14- throw createNonCommandError({error, stdioStreamsGroups, sourceOptions});15+ throw createNonCommandError({error, stdioStreamsGroups, sourceOptions, startTime});16 }17 };18 19 const getPipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError}) => {11 unmodified lines31 return sourceError;32 }33 };34 34-export const createNonCommandError = ({error, stdioStreamsGroups, sourceOptions}) => makeEarlyError({35+export const createNonCommandError = ({error, stdioStreamsGroups, sourceOptions, startTime}) => makeEarlyError({36 error,37 command: PIPE_COMMAND_MESSAGE,38 escapedCommand: PIPE_COMMAND_MESSAGE,39 stdioStreamsGroups,40 options: sourceOptions,41+ startTime,42 });43 44 const PIPE_COMMAND_MESSAGE = 'source.pipe(destination)';modified:lib/pipe/validate.js+3 added
1 import {execa} from '../async.js';2 import {create$} from '../script.js';3 import {normalizeArguments} from '../arguments/options.js';4 import {STANDARD_STREAMS_ALIASES} from '../utils.js';5+import {getStartTime} from '../return/duration.js';6 7 export const normalizePipeArguments = ({source, sourcePromise, stdioStreamsGroups, destinationOptions}, ...args) => {8+ const startTime = getStartTime();9 const sourceOptions = PROCESS_OPTIONS.get(source);10 const {11 destination,12 destinationStream,10 unmodified lines23 destinationStream,24 destinationError,25 unpipeSignal,26 stdioStreamsGroups,27+ startTime,28 };29 };30 31 const getDestinationStream = (destinationOptions, ...args) => {123 unmodified linesadded:lib/return/duration.js+5 added
12345import {hrtime} from 'node:process';
export const getStartTime = () => hrtime.bigint();
export const getDurationMs = startTime => Number(hrtime.bigint() - startTime) / 1e6;modified:lib/return/early-error.js+2 added-2 removed
4 unmodified lines5 import {handleResult} from './output.js';6 7 // When the child process fails to spawn.8 // We ensure the returned error is always both a promise and a child process.9-export const handleEarlyError = ({error, command, escapedCommand, stdioStreamsGroups, options, verboseInfo}) => {9+export const handleEarlyError = ({error, command, escapedCommand, stdioStreamsGroups, options, startTime, verboseInfo}) => {10 cleanupStdioStreams(stdioStreamsGroups);11 12 const spawned = new ChildProcess();13 createDummyStreams(spawned);14 15- const earlyError = makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options});15+ const earlyError = makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options, startTime});16 const promise = handleDummyPromise(earlyError, verboseInfo, options);17 return {spawned, promise};18 };19 16 unmodified linesmodified:lib/return/error.js+7 added
1 unmodified line2 import stripFinalNewline from 'strip-final-newline';3 import {isBinary, binaryToString} from '../utils.js';4 import {fixCwdError} from '../arguments/cwd.js';5 import {escapeLines} from '../arguments/escape.js';6+import {getDurationMs} from './duration.js';7 import {getFinalError, isPreviousError} from './clone.js';8 9 export const makeSuccessResult = ({10 command,11 escapedCommand,12 stdio,13 all,14 options: {cwd},15+ startTime,16 }) => ({17 command,18 escapedCommand,19 cwd,20+ durationMs: getDurationMs(startTime),21 failed: false,22 timedOut: false,23 isCanceled: false,24 isTerminated: false,10 unmodified lines35 command,36 escapedCommand,37 stdioStreamsGroups,38 options,39+ startTime,40 }) => makeError({41 error,42 command,43 escapedCommand,44+ startTime,45 timedOut: false,46 isCanceled: false,47 stdio: Array.from({length: stdioStreamsGroups.length}),48 options,2 unmodified lines51 export const makeError = ({52 error: rawError,53 command,54 escapedCommand,55+ startTime,56 timedOut,57 isCanceled,58 exitCode: rawExitCode,59 signal: rawSignal,22 unmodified lines82 error.originalMessage = originalMessage;83 error.command = command;84 error.escapedCommand = escapedCommand;85 error.cwd = cwd;86+ error.durationMs = getDurationMs(startTime);87 88 error.failed = true;89 error.timedOut = timedOut;90 error.isCanceled = isCanceled;109 unmodified linesmodified:lib/verbose/complete.js+14 added-9 removed
1 import prettyMs from 'pretty-ms';2 import {gray} from 'yoctocolors';3 import {escapeLines} from '../arguments/escape.js';4+import {getDurationMs} from '../return/duration.js';5 import {verboseLog} from './log.js';5-import {getCommandDuration} from './info.js';6 import {logError} from './error.js';7 8 // When `verbose` is `short|full`, print each command's completion, duration and error9-export const logFinalResult = ({shortMessage, failed}, reject, verboseInfo) => {10- logResult(shortMessage, failed, reject, verboseInfo);9+export const logFinalResult = ({shortMessage, failed, durationMs}, reject, verboseInfo) => {10+ logResult({message: shortMessage, failed, reject, durationMs, verboseInfo});11 };12 13 // Same but for early validation errors14-export const logEarlyResult = (error, verboseInfo) => {15- logResult(escapeLines(String(error)), true, true, verboseInfo);14+export const logEarlyResult = (error, startTime, verboseInfo) => {15+ logResult({16+ message: escapeLines(String(error)),17+ failed: true,18+ reject: true,19+ durationMs: getDurationMs(startTime),20+ verboseInfo,21+ });22 };23 18-const logResult = (message, failed, reject, {verbose, verboseId, startTime}) => {24+const logResult = ({message, failed, reject, durationMs, verboseInfo: {verbose, verboseId}}) => {25 if (verbose === 'none') {26 return;27 }28 29 const icon = getIcon(failed, reject);30 logError({message, failed, reject, verboseId, icon});25- logDuration(startTime, verboseId, icon);31+ logDuration(durationMs, verboseId, icon);32 };33 28-const logDuration = (startTime, verboseId, icon) => {29- const durationMs = getCommandDuration(startTime);34+const logDuration = (durationMs, verboseId, icon) => {35 const durationMessage = `(done in ${prettyMs(durationMs)})`;36 verboseLog(durationMessage, verboseId, icon, gray);37 };38 7 unmodified linesmodified:lib/verbose/info.js+3 added-12 removed
1-import {hrtime} from 'node:process';1 import {debuglog} from 'node:util';2 4-export const getVerboseInfo = ({verbose = verboseDefault}) => {5- if (verbose === 'none') {6- return {verbose};7- }3+export const getVerboseInfo = ({verbose = verboseDefault}) => verbose === 'none'4+ ? {verbose}5+ : {verbose, verboseId: VERBOSE_ID++};6 9- const verboseId = VERBOSE_ID++;10- const startTime = hrtime.bigint();11- return {verbose, verboseId, startTime};12-};13-7 const verboseDefault = debuglog('execa').enabled ? 'full' : 'none';8 16-export const getCommandDuration = startTime => Number(hrtime.bigint() - startTime) / 1e6;17-9 // Prepending the `pid` is useful when multiple commands print their output at the same time.10 // However, we cannot use the real PID since this is not available with `child_process.spawnSync()`.11 // Also, we cannot use the real PID if we want to print it before `child_process.spawn()` is run.12 // As a pro, it is shorter than a normal PID and never re-uses the same id.2 unmodified linesmodified:lib/async.js+13 added-12 removed
13 unmodified lines14 import {getSpawnedResult} from './stream/resolve.js';15 import {mergePromise} from './promise.js';16 17 export const execa = (rawFile, rawArgs, rawOptions) => {18- const {file, args, command, escapedCommand, verboseInfo, options, stdioStreamsGroups, stdioState} = handleAsyncArguments(rawFile, rawArgs, rawOptions);19- const {spawned, promise} = spawnProcessAsync({file, args, options, verboseInfo, command, escapedCommand, stdioStreamsGroups, stdioState});18+ const {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups, stdioState} = handleAsyncArguments(rawFile, rawArgs, rawOptions);19+ const {spawned, promise} = spawnProcessAsync({file, args, options, startTime, verboseInfo, command, escapedCommand, stdioStreamsGroups, stdioState});20 spawned.pipe = pipeToProcess.bind(undefined, {source: spawned, sourcePromise: promise, stdioStreamsGroups, destinationOptions: {}});21 mergePromise(spawned, promise);22 PROCESS_OPTIONS.set(spawned, options);23 return spawned;24 };25 26 const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {27 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);28- const {command, escapedCommand, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);28+ const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);29 30 try {31 const {file, args, options: normalizedOptions} = handleArguments(rawFile, rawArgs, rawOptions);32 const options = handleAsyncOptions(normalizedOptions);33 const {stdioStreamsGroups, stdioState} = handleInputAsync(options, verboseInfo);34- return {file, args, command, escapedCommand, verboseInfo, options, stdioStreamsGroups, stdioState};34+ return {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups, stdioState};35 } catch (error) {36- logEarlyResult(error, verboseInfo);36+ logEarlyResult(error, startTime, verboseInfo);37 throw error;38 }39 };40 5 unmodified lines46 47 return {...options, timeoutDuration: timeout, signal: cancelSignal};48 };49 50-const spawnProcessAsync = ({file, args, options, verboseInfo, command, escapedCommand, stdioStreamsGroups, stdioState}) => {50+const spawnProcessAsync = ({file, args, options, startTime, verboseInfo, command, escapedCommand, stdioStreamsGroups, stdioState}) => {51 let spawned;52 try {53 spawned = spawn(file, args, options);54 } catch (error) {55- return handleEarlyError({error, command, escapedCommand, stdioStreamsGroups, options, verboseInfo});55+ return handleEarlyError({error, command, escapedCommand, stdioStreamsGroups, options, startTime, verboseInfo});56 }57 58 const controller = new AbortController();59 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);4 unmodified lines64 65 spawned.kill = spawnedKill.bind(undefined, {kill: spawned.kill.bind(spawned), spawned, options, controller});66 spawned.all = makeAllStream(spawned, options);67 68- const promise = handlePromise({spawned, options, verboseInfo, stdioStreamsGroups, originalStreams, command, escapedCommand, controller});68+ const promise = handlePromise({spawned, options, startTime, verboseInfo, stdioStreamsGroups, originalStreams, command, escapedCommand, controller});69 return {spawned, promise};70 };71 72-const handlePromise = async ({spawned, options, verboseInfo, stdioStreamsGroups, originalStreams, command, escapedCommand, controller}) => {72+const handlePromise = async ({spawned, options, startTime, verboseInfo, stdioStreamsGroups, originalStreams, command, escapedCommand, controller}) => {73 const context = {timedOut: false};74 75 const [76 errorInfo,4 unmodified lines81 controller.abort();82 83 const stdio = stdioResults.map(stdioResult => handleOutput(options, stdioResult));84 const all = handleOutput(options, allResult);85- const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand});85+ const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime});86 return handleResult(result, verboseInfo, options);87 };88 89-const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand}) => 'error' in errorInfo89+const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime}) => 'error' in errorInfo90 ? makeError({91 error: errorInfo.error,92 command,93 escapedCommand,3 unmodified lines97 signal,98 stdio,99 all,100 options,101+ startTime,102 })102- : makeSuccessResult({command, escapedCommand, stdio, all, options});103+ : makeSuccessResult({command, escapedCommand, stdio, all, options, startTime});modified:lib/sync.js+11 added-10 removed
5 unmodified lines6 import {logEarlyResult} from './verbose/complete.js';7 import {isFailedExit} from './exit/code.js';8 9 export const execaSync = (rawFile, rawArgs, rawOptions) => {10- const {file, args, command, escapedCommand, verboseInfo, options, stdioStreamsGroups} = handleSyncArguments(rawFile, rawArgs, rawOptions);11- const result = spawnProcessSync({file, args, options, command, escapedCommand, stdioStreamsGroups});10+ const {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups} = handleSyncArguments(rawFile, rawArgs, rawOptions);11+ const result = spawnProcessSync({file, args, options, command, escapedCommand, stdioStreamsGroups, startTime});12 return handleResult(result, verboseInfo, options);13 };14 15 const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {16 [rawFile, rawArgs, rawOptions] = normalizeArguments(rawFile, rawArgs, rawOptions);17- const {command, escapedCommand, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);17+ const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);18 19 try {20 const syncOptions = normalizeSyncOptions(rawOptions);21 const {file, args, options} = handleArguments(rawFile, rawArgs, syncOptions);22 validateSyncOptions(options);23 const stdioStreamsGroups = handleInputSync(options, verboseInfo);24- return {file, args, command, escapedCommand, verboseInfo, options, stdioStreamsGroups};24+ return {file, args, command, escapedCommand, startTime, verboseInfo, options, stdioStreamsGroups};25 } catch (error) {26- logEarlyResult(error, verboseInfo);26+ logEarlyResult(error, startTime, verboseInfo);27 throw error;28 }29 };30 4 unmodified lines35 throw new TypeError('The "ipc: true" option cannot be used with synchronous methods.');36 }37 };38 39-const spawnProcessSync = ({file, args, options, command, escapedCommand, stdioStreamsGroups}) => {39+const spawnProcessSync = ({file, args, options, command, escapedCommand, stdioStreamsGroups, startTime}) => {40 let syncResult;41 try {42 syncResult = spawnSync(file, args, options);43 } catch (error) {44- return makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options});44+ return makeEarlyError({error, command, escapedCommand, stdioStreamsGroups, options, startTime});45 }46 47 pipeOutputSync(stdioStreamsGroups, syncResult);48 49 const output = syncResult.output || Array.from({length: 3});50 const stdio = output.map(stdioOutput => handleOutput(options, stdioOutput));51- return getSyncResult(syncResult, {stdio, options, command, escapedCommand});51+ return getSyncResult(syncResult, {stdio, options, command, escapedCommand, startTime});52 };53 54-const getSyncResult = ({error, status, signal}, {stdio, options, command, escapedCommand}) => error !== undefined || isFailedExit(status, signal)54+const getSyncResult = ({error, status, signal}, {stdio, options, command, escapedCommand, startTime}) => error !== undefined || isFailedExit(status, signal)55 ? makeError({56 error,57 command,58 escapedCommand,2 unmodified lines61 exitCode: status,62 signal,63 stdio,64 options,65+ startTime,66 })66- : makeSuccessResult({command, escapedCommand, stdio, options});67+ : makeSuccessResult({command, escapedCommand, stdio, options, startTime});added:test/helpers/early-error.js+7 added
1+import {execa, execaSync} from '../../index.js';2+3+export const earlyErrorOptions = {killSignal: false};4+export const getEarlyErrorProcess = options => execa('empty.js', {...earlyErrorOptions, ...options});5+export const getEarlyErrorProcessSync = options => execaSync('empty.js', {...earlyErrorOptions, ...options});6+7+export const expectedEarlyError = {code: 'ERR_INVALID_ARG_TYPE'};modified:test/pipe/validate.js+2 added-1 removed
3 unmodified lines4 import test from 'ava';5 import {execa} from '../../index.js';6 import {setFixtureDir} from '../helpers/fixtures-dir.js';7 import {foobarString} from '../helpers/input.js';8+import {getEarlyErrorProcess} from '../helpers/early-error.js';9 10 setFixtureDir();11 12 const assertPipeError = async (t, pipePromise, message) => {188 unmodified lines201 202 test('Sets the right error message when the "all" option is incompatible - early error', async t => {203 await assertPipeError(204 t,204- execa('empty.js', {killSignal: false})205+ getEarlyErrorProcess()206 .pipe(execa('stdin.js', {all: false}))207 .pipe(execa('empty.js'), {from: 'all'}),208 '"all" option must be true',209 );1 unmodified lineadded:test/return/duration.js+62 added
1+import test from 'ava';2+import {execa, execaSync} from '../../index.js';3+import {setFixtureDir} from '../helpers/fixtures-dir.js';4+import {getEarlyErrorProcess, getEarlyErrorProcessSync} from '../helpers/early-error.js';5+6+setFixtureDir();7+8+const assertDurationMs = (t, durationMs) => {9+ t.is(typeof durationMs, 'number');10+ t.true(Number.isFinite(durationMs));11+ t.false(Number.isInteger(durationMs));12+ t.not(durationMs, 0);13+ t.true(durationMs > 0);14+};15+16+test('result.durationMs', async t => {17+ const {durationMs} = await execa('empty.js');18+ assertDurationMs(t, durationMs);19+});20+21+test('result.durationMs - sync', t => {22+ const {durationMs} = execaSync('empty.js');23+ assertDurationMs(t, durationMs);24+});25+26+test('error.durationMs', async t => {27+ const {durationMs} = await t.throwsAsync(execa('fail.js'));28+ assertDurationMs(t, durationMs);29+});30+31+test('error.durationMs - sync', t => {32+ const {durationMs} = t.throws(() => {33+ execaSync('fail.js');34+ });35+ assertDurationMs(t, durationMs);36+});37+38+test('error.durationMs - early validation', async t => {39+ const {durationMs} = await t.throwsAsync(getEarlyErrorProcess());40+ assertDurationMs(t, durationMs);41+});42+43+test('error.durationMs - early validation, sync', t => {44+ const {durationMs} = t.throws(getEarlyErrorProcessSync);45+ assertDurationMs(t, durationMs);46+});47+48+test('error.durationMs - unpipeSignal', async t => {49+ const {durationMs} = await t.throwsAsync(execa('noop.js').pipe('stdin.js', {signal: AbortSignal.abort()}));50+ assertDurationMs(t, durationMs);51+});52+53+test('error.durationMs - pipe validation', async t => {54+ const {durationMs} = await t.throwsAsync(execa('noop.js').pipe(false));55+ assertDurationMs(t, durationMs);56+});57+58+test.serial('result.durationMs is accurate', async t => {59+ const minDurationMs = 1e3;60+ const {durationMs} = await execa('delay.js', [minDurationMs]);61+ t.true(durationMs >= minDurationMs);62+});modified:test/return/early-error.js+1 added-5 removed
1 import process from 'node:process';2 import test from 'ava';3 import {execa, execaSync, $} from '../../index.js';4 import {setFixtureDir} from '../helpers/fixtures-dir.js';5+import {earlyErrorOptions, getEarlyErrorProcess, getEarlyErrorProcessSync, expectedEarlyError} from '../helpers/early-error.js';6 7 setFixtureDir();8 9 const isWindows = process.platform === 'win32';10 const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;11 11-const earlyErrorOptions = {killSignal: false};12-const getEarlyErrorProcess = options => execa('empty.js', {...earlyErrorOptions, ...options});13-const getEarlyErrorProcessSync = options => execaSync('empty.js', {...earlyErrorOptions, ...options});14-const expectedEarlyError = {code: 'ERR_INVALID_ARG_TYPE'};15-12 test('execaSync() throws error if ENOENT', t => {13 t.throws(() => {14 execaSync('foo');15 }, {message: ENOENT_REGEXP});75 unmodified linesmodified:test/return/error.js+2 added
13 unmodified lines14 t.deepEqual(Reflect.ownKeys(result), [15 'command',16 'escapedCommand',17 'cwd',18+ 'durationMs',19 'failed',20 'timedOut',21 'isCanceled',22 'isTerminated',15 unmodified lines38 'originalMessage',39 'command',40 'escapedCommand',41 'cwd',42+ 'durationMs',43 'failed',44 'timedOut',45 'isCanceled',46 'isTerminated',142 unmodified linesmodified:index.d.ts+18 added-10 removed
731 unmodified lines732 */733 cwd: string;734 735 /**736+ Duration of the child process, in milliseconds.737+ */738+ durationMs: number;739+740+ /**741 Whether the process was canceled using the `cancelSignal` option.742 */743 isCanceled: boolean;744 257 unmodified lines1002 } catch (error) {1003 console.log(error);1004 /*1005 {1001- message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',1006+ message: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',1007 errno: -2,1008 code: 'ENOENT',1009 syscall: 'spawn unknown',1010 path: 'unknown',1011 spawnargs: ['command'],1012+ shortMessage: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',1013 originalMessage: 'spawn unknown ENOENT',1008- shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',1014 command: 'unknown command',1015 escapedCommand: 'unknown command',1011- stdout: '',1012- stderr: '',1016+ cwd: '/path/to/cwd',1017+ durationMs: 28.217566,1018 failed: true,1019 timedOut: false,1020 isCanceled: false,1021 isTerminated: false,1017- cwd: '/path/to/cwd'1022+ stdout: '',1023+ stderr: '',1024+ stdio: [undefined, '', ''],1025+ pipedFrom: []1026 }1027 \*\/1028 }1029 ```49 unmodified lines1079 } catch (error) {1080 console.log(error);1081 /*1082 {1075- message: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',1083+ message: 'Command failed with ENOENT: unknown command\nspawnSync unknown ENOENT',1084 errno: -2,1085 code: 'ENOENT',1086 syscall: 'spawnSync unknown',1087 path: 'unknown',1088 spawnargs: ['command'],1089+ shortMessage: 'Command failed with ENOENT: unknown command\nspawnSync unknown ENOENT',1090 originalMessage: 'spawnSync unknown ENOENT',1082- shortMessage: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',1091 command: 'unknown command',1092 escapedCommand: 'unknown command',1085- stdout: '',1086- stderr: '',1093+ cwd: '/path/to/cwd',1094 failed: true,1095 timedOut: false,1096 isCanceled: false,1097 isTerminated: false,1091- cwd: '/path/to/cwd'1098+ stdio: [],1099+ pipedFrom: []1100 }1101 \*\/1102 }1103 ```290 unmodified linesmodified:index.test-d.ts+4 added
253 unmodified lines254 expectType<boolean>(unicornsResult.isTerminated);255 expectType<string | undefined>(unicornsResult.signal);256 expectType<string | undefined>(unicornsResult.signalDescription);257 expectType<string>(unicornsResult.cwd);258+ expectType<number>(unicornsResult.durationMs);259 expectType<ExecaReturnValue[]>(unicornsResult.pipedFrom);260 261 expectType<undefined>(unicornsResult.stdio[0]);262 expectType<string>(unicornsResult.stdout);304 unmodified lines567 expectType<boolean>(execaError.isTerminated);568 expectType<string | undefined>(execaError.signal);569 expectType<string | undefined>(execaError.signalDescription);570 expectType<string>(execaError.cwd);571+ expectType<number>(execaError.durationMs);572 expectType<string>(execaError.shortMessage);573 expectType<string | undefined>(execaError.originalMessage);574 expectType<ExecaReturnValue[]>(execaError.pipedFrom);575 140 unmodified lines716 expectType<boolean>(unicornsResult.isTerminated);717 expectType<string | undefined>(unicornsResult.signal);718 expectType<string | undefined>(unicornsResult.signalDescription);719 expectType<string>(unicornsResult.cwd);720+ expectType<number>(unicornsResult.durationMs);721 expectType<[]>(unicornsResult.pipedFrom);722 723 expectType<undefined>(unicornsResult.stdio[0]);724 expectType<string>(unicornsResult.stdout);62 unmodified lines787 expectType<boolean>(execaError.isTerminated);788 expectType<string | undefined>(execaError.signal);789 expectType<string | undefined>(execaError.signalDescription);790 expectType<string>(execaError.cwd);791+ expectType<number>(execaError.durationMs);792 expectType<string>(execaError.shortMessage);793 expectType<string | undefined>(execaError.originalMessage);794 expectType<[]>(execaError.pipedFrom);795 776 unmodified linesmodified:readme.md+15 added-5 removed
213 unmodified lines214 } catch (error) {215 console.log(error);216 /*217 {218- message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',218+ message: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',219 errno: -2,220 code: 'ENOENT',221 syscall: 'spawn unknown',222 path: 'unknown',223 spawnargs: ['command'],224+ shortMessage: 'Command failed with ENOENT: unknown command\nspawn unknown ENOENT',225 originalMessage: 'spawn unknown ENOENT',225- shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',226 command: 'unknown command',227 escapedCommand: 'unknown command',228- stdout: '',229- stderr: '',228+ cwd: '/path/to/cwd',229+ durationMs: 28.217566,230 failed: true,231 timedOut: false,232 isCanceled: false,233- isTerminated: false233+ isTerminated: false,234+ stdout: '',235+ stderr: '',236+ stdio: [undefined, '', ''],237+ pipedFrom: []238 }239 */240 }241 ```214 unmodified lines456 Type: `string`457 458 The [current directory](#cwd-1) in which the command was run.459 460+#### durationMs461+462+Type: `number`463+464+Duration of the child process, in milliseconds.465+466 #### stdout467 468 Type: `string | Uint8Array | string[] | Uint8Array[] | unknown[] | undefined`469 590 unmodified lines