Skip to content
Myr

Require Node.js 22 (#1243)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Sindre Sorhus · committed by GitHub · parent b886883 · Browse files · 90 files+454 added−428 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

90 files+454 added−428 removed

  • tests:+135 added−151 removed
  • other:+319 added−277 removed

90 files+454 added−428 removed

modified:.github/workflows/main.yml+7 added-6 removed
modified:docs/api.md+1 added-1 removed
943 unmodified lines
944If the subprocess outputs text, specifies its character encoding, either [`'utf8'`](https://en.wikipedia.org/wiki/UTF-8) or [`'utf16le'`](https://en.wikipedia.org/wiki/UTF-16).945946If it outputs binary data instead, this should be either:947- `'buffer'`: returns the binary output as an [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).948- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.948- [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#RFC_4648), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.949950The output is available with [`result.stdout`](#resultstdout), [`result.stderr`](#resultstderr) and [`result.stdio`](#resultstdio).951952[More info.](binary.md)
355 unmodified lines
modified:docs/binary.md+1 added-1 removed
modified:docs/termination.md+1 added-1 removed
116 unmodified lines
117 process.exitCode = 1;118});119```120121However, if any operation is still ongoing, the subprocess will keep running. It can be forcefully ended using [`process.exit(exitCode)`](https://nodejs.org/api/process.html#processexitcode) instead of [`process.exitCode`](https://nodejs.org/api/process.html#processexitcode_1).121However, if any operation is still ongoing, the subprocess will keep running. It can be forcefully ended using [`process.exit(exitCode)`](https://nodejs.org/api/process.html#processexitcode) instead of [`process.exitCode`](https://nodejs.org/api/process.html#processexitcode-1).122123If the subprocess is still alive after 5 seconds, it is forcefully terminated with [`SIGKILL`](#sigkill). This can be [configured or disabled](#forceful-termination) using the [`forceKillAfterDelay`](api.md#optionsforcekillafterdelay) option.124125## Timeout
233 unmodified lines
modified:lib/arguments/escape.js+2 added-2 removed
47 unmodified lines
48 // Similar to the above RegExp, but works even when Node.js has been built without ICU support.49 // Unlike the above RegExp, it only covers whitespaces and C0/C1 control characters.50 // It does not cover some edge cases, such as Unicode reserved characters.51 // See https://github.com/sindresorhus/execa/issues/114352 // eslint-disable-next-line no-control-regex52 // eslint-disable-next-line no-control-regex, regexp/no-control-character, unicorn/prefer-unicode-code-point-escapes53 return /[\s\u0000-\u001F\u007F-\u009F\u00AD]/g;54 }55};56
27 unmodified lines
84 ? `"${escapedArgument.replaceAll('"', '""')}"`85 : `'${escapedArgument.replaceAll('\'', '\'\\\'\'')}'`;86};8788const NO_ESCAPE_REGEXP = /^[\w./-]+$/;88const NO_ESCAPE_REGEXP = /^[\w\-./]+$/;
modified:lib/arguments/specific.js+2 added-2 removed
80 unmodified lines
81 }8283 const regexpResult = FD_REGEXP.exec(fdName);84 if (regexpResult !== null) {85 return Number(regexpResult[1]);85 return Number(regexpResult.groups.fdNumber);86 }87};8889const FD_REGEXP = /^fd(\d+)$/;89const FD_REGEXP = /^fd(?<fdNumber>\d+)$/;9091const addDefaultValue = (optionArray, optionName) => optionArray.map(optionValue => optionValue === undefined92 ? DEFAULT_OPTIONS[optionName]93 : optionValue);
19 unmodified lines
modified:lib/convert/readable.js+5 added-3 removed
100 unmodified lines
101};102103// When `readable` aborts/errors, do the same on `subprocess.stdout`104export const onReadableDestroy = async ({subprocessStdout, subprocess, waitReadableDestroy}, error) => {105 if (await waitForConcurrentStreams(waitReadableDestroy, subprocess)) {106 destroyOtherReadable(subprocessStdout, error);107 await waitForSubprocess(subprocess, error);105 if (!await waitForConcurrentStreams(waitReadableDestroy, subprocess)) {106 return;107 }108109 destroyOtherReadable(subprocessStdout, error);110 await waitForSubprocess(subprocess, error);111};112113const destroyOtherReadable = (stream, error) => {114 destroyOtherStream(stream, stream.readable, error);
1 unmodified line
modified:lib/convert/writable.js+7 added-5 removed
52 unmodified lines
53// Like this, any subprocess failure is propagated as a stream `error` event, instead of being lost.54// The user does not need to `await` the subprocess anymore, but now needs to await the stream completion or error.55// When multiple writables are targeting the same stream, they wait for each other, unless the subprocess ends first.56const onWritableFinal = async (subprocessStdin, subprocess, waitWritableFinal) => {57 if (await waitForConcurrentStreams(waitWritableFinal, subprocess)) {58 if (subprocessStdin.writable) {59 subprocessStdin.end();60 }57 if (!await waitForConcurrentStreams(waitWritableFinal, subprocess)) {58 return;59 }6062 await subprocess;61 if (subprocessStdin.writable) {62 subprocessStdin.end();63 }6465 await subprocess;66};6768// When `subprocess.stdin` ends/aborts/errors, do the same on `writable`.69export const onStdinFinished = async (subprocessStdin, writable, subprocessStdout) => {
23 unmodified lines
modified:lib/io/output-async.js+5 added-3 removed
8 unmodified lines
9export const pipeOutputAsync = (subprocess, fileDescriptors, controller) => {10 const pipeGroups = new Map();1112 for (const [fdNumber, {stdioItems, direction}] of Object.entries(fileDescriptors)) {13 for (const {stream} of stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type))) {13 const transformItems = stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type));14 for (const {stream} of transformItems) {15 pipeTransform(subprocess, stream, direction, fdNumber);16 }1717 for (const {stream} of stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type))) {18 const nonTransformItems = stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type));19 for (const {stream} of nonTransformItems) {20 pipeStdioItem({21 subprocess,22 stream,23 direction,
3 unmodified lines
27 });28 }29 }3029 for (const [outputStream, inputStreams] of pipeGroups.entries()) {31 for (const [outputStream, inputStreams] of pipeGroups) {32 const inputStream = inputStreams.length === 1 ? inputStreams[0] : mergeStreams(inputStreams);33 pipeStreams(inputStream, outputStream);34 }35};
47 unmodified lines
modified:lib/io/output-sync.js+3 added-2 removed
11 unmodified lines
12 return {output: Array.from({length: 3})};13 }1415 const state = {};16 const outputFiles = new Set([]);16 const outputFiles = new Set();17 const transformedOutput = output.map((result, fdNumber) =>18 transformOutputResultSync({19 result,20 fileDescriptors,
101 unmodified lines
122};123124// When the `std*` target is a file path/URL or a file descriptor125const writeToFiles = (serializedResult, stdioItems, outputFiles) => {126 for (const {path, append} of stdioItems.filter(({type}) => FILE_TYPES.has(type))) {126 const fileItems = stdioItems.filter(({type}) => FILE_TYPES.has(type));127 for (const {path, append} of fileItems) {128 const pathString = typeof path === 'string' ? path : path.toString();129 if (append || outputFiles.has(pathString)) {130 appendFileSync(path, serializedResult);131 } else {
5 unmodified lines
modified:lib/ipc/reference.js+10 added-6 removed
27 unmodified lines
28// To proxy events, we setup some global listeners on the `message` and `disconnect` events.29// Those should not keep the subprocess alive, so we remove the automatic counting that Node.js is doing.30// See https://github.com/nodejs/node/blob/1b965270a9c273d4cf70e8808e9d28b9ada7844f/lib/child_process.js#L18031export const undoAddedReferences = (channel, isSubprocess) => {32 if (isSubprocess) {33 removeReferenceCount(channel);34 removeReferenceCount(channel);32 if (!isSubprocess) {33 return;34 }3536 removeReferenceCount(channel);37 removeReferenceCount(channel);38};3940// Reverse it during `disconnect`41export const redoAddedReferences = (channel, isSubprocess) => {40 if (isSubprocess) {41 addReferenceCount(channel);42 addReferenceCount(channel);42 if (!isSubprocess) {43 return;44 }4546 addReferenceCount(channel);47 addReferenceCount(channel);48};
modified:lib/methods/bind.js+4 added-6 removed
3 unmodified lines
4// Deep merge specific options like `env`. Shallow merge the other ones.5// Use spread (which only copies own properties) to safely read from boundOptions without prototype pollution6export const mergeOptions = (boundOptions, options) => {7 const safeBoundOptions = {__proto__: null, ...boundOptions};8 const mergedOptions = Object.fromEntries(9 Object.entries(options).map(([optionName, optionValue]) => [10 optionName,11 mergeOption(optionName, safeBoundOptions[optionName], optionValue),12 ]),8 const mergedOptions = Object.fromEntries(Object.entries(options).map(([optionName, optionValue]) => [9 optionName,10 mergeOption(optionName, safeBoundOptions[optionName], optionValue),11 ]));13 );12 return {...safeBoundOptions, ...mergedOptions};13};1415const mergeOption = (optionName, boundOptionValue, optionValue) => {
8 unmodified lines
modified:lib/methods/main-async.js+1 added-1 removed
88 unmodified lines
89 });90 }9192 const controller = new AbortController();93 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);93 setMaxListeners(Infinity, controller.signal);9495 const originalStreams = [...subprocess.stdio];96 pipeOutputAsync(subprocess, fileDescriptors, controller);97 cleanupOnExit(subprocess, options, controller);
97 unmodified lines
modified:lib/resolve/wait-stream.js+2 added-1 removed
29 unmodified lines
30// For example, `stdin: 'pipe'` is implemented as a TCP socket, and its `.destroy()` method waits for TCP disconnection.31// Therefore `.destroy()` might end before or after subprocess exit, based on OS speed and load.32// The only way to detect this is to spy on `subprocess.stdin._destroy()` by wrapping it.33// If `subprocess.exitCode` or `subprocess.signalCode` is set, it means `.destroy()` is being called by Node.js itself.34const handleStdinDestroy = (stream, {originalStreams: [originalStdin], subprocess}) => {34const handleStdinDestroy = (stream, {originalStreams, subprocess}) => {35 const [originalStdin] = originalStreams;36 const state = {stdinCleanedUp: false};37 if (stream === originalStdin) {38 spyOnStdinDestroy(stream, subprocess, state);39 }
58 unmodified lines
modified:lib/return/final-error.js+15 added-11 removed
9 unmodified lines
10export class DiscardedError extends Error {}1112// Proper way to set `error.name`: it should be inherited and non-enumerable13const setErrorName = (ErrorClass, value) => {14 Object.defineProperties(ErrorClass.prototype, {14 Object.defineProperty(ErrorClass.prototype, 'name', {15 value,16 writable: true,17 enumerable: false,18 configurable: true,15 name: {16 value,17 writable: true,18 enumerable: false,19 configurable: true,20 },21 [execaErrorSymbol]: {22 value: true,23 writable: false,24 enumerable: false,25 configurable: false,26 },27 });20 Object.defineProperty(ErrorClass.prototype, execaErrorSymbol, {21 value: true,22 writable: false,23 enumerable: false,24 configurable: false,25 });28};2930// Unlike `instanceof`, this works across realms31export const isExecaError = error => isErrorInstance(error) && execaErrorSymbol in error;
3 unmodified lines
35export const isErrorInstance = value => Object.prototype.toString.call(value) === '[object Error]';3637// We use two different Error classes for async/sync methods since they have slightly different shape and types38export class ExecaError extends Error {}39// eslint-disable-next-line unicorn/no-top-level-side-effects -- `error.name` must be set as soon as the class is defined40setErrorName(ExecaError, ExecaError.name);4142export class ExecaSyncError extends Error {}43// eslint-disable-next-line unicorn/no-top-level-side-effects -- `error.name` must be set as soon as the class is defined44setErrorName(ExecaSyncError, ExecaSyncError.name);
modified:lib/stdio/input-option.js+13 added-9 removed
8 unmodified lines
9 ...handleInputFileOption(inputFile),10 ]11 : [];1213const handleInputOption = input => input === undefined14 ? []13const handleInputOption = input => input === undefined ? [] : [{14 type: getInputType(input),15 value: input,16 optionName: 'input',17}];15 : [{16 type: getInputType(input),17 value: input,18 optionName: 'input',19 }];2021const getInputType = input => {22 if (isReadableStream(input, {checkOpen: false})) {23 return 'nodeStream';
9 unmodified lines
3334 throw new Error('The `input` option must be a string, a Uint8Array or a Node.js Readable stream.');35};3637const handleInputFileOption = inputFile => inputFile === undefined38 ? []35const handleInputFileOption = inputFile => inputFile === undefined ? [] : [{36 ...getInputFileType(inputFile),37 optionName: 'inputFile',38}];39 : [{40 ...getInputFileType(inputFile),41 optionName: 'inputFile',42 }];4344const getInputFileType = inputFile => {45 if (isUrl(inputFile)) {46 return {type: 'fileUrl', value: inputFile};
8 unmodified lines
modified:lib/transform/normalize.js+6 added-11 removed
49 unmodified lines
50 encoding,51 });52};5354const normalizeDuplex = ({55 stdioItem,56 stdioItem: {57 value: {58 transform,59 transform: {writableObjectMode, readableObjectMode},60 objectMode = readableObjectMode,61 },62 },63 optionName,64}) => {54const normalizeDuplex = ({stdioItem, optionName}) => {55 const {value} = stdioItem;56 const {transform} = value;57 const {writableObjectMode, readableObjectMode} = transform;58 const {objectMode = readableObjectMode} = value;5960 if (objectMode && !readableObjectMode) {61 throw new TypeError(`The \`${optionName}.objectMode\` option can only be \`true\` if \`new Duplex({objectMode: true})\` is used.`);62 }63
43 unmodified lines
modified:lib/utils/max-listeners.js+1 added-1 removed
1 unmodified line
23// Temporarily increase the maximum number of listeners on an eventEmitter4export const incrementMaxListeners = (eventEmitter, maxListenersIncrement, signal) => {5 const maxListeners = eventEmitter.getMaxListeners();6 if (maxListeners === 0 || maxListeners === Number.POSITIVE_INFINITY) {6 if (maxListeners === 0 || maxListeners === Infinity) {7 return;8 }910 eventEmitter.setMaxListeners(maxListeners + maxListenersIncrement);
4 unmodified lines
modified:lib/verbose/log.js+14 added-14 removed
18 unmodified lines
19 console.warn(finalLines.slice(0, -1));20 }21};2223const getVerboseObject = ({24 type,25 result,26 verboseInfo: {escapedCommand, commandId, rawOptions: {piped = false, ...options}},27}) => ({28 type,29 escapedCommand,30 commandId: `${commandId}`,31 timestamp: new Date(),32 piped,33 result,34 options,35});23const getVerboseObject = ({type, result, verboseInfo}) => {24 const {escapedCommand, commandId, rawOptions} = verboseInfo;25 const {piped = false, ...options} = rawOptions;26 return {27 type,28 escapedCommand,29 commandId: `${commandId}`,30 timestamp: new Date(),31 piped,32 result,33 options,34 };35};3637const getPrintedLines = (verboseMessage, verboseObject) => verboseMessage38 .split('\n')39 .map(message => getPrintedLine({...verboseObject, message}));
6 unmodified lines
46// Serialize any type to a line string, for logging47export const serializeVerboseMessage = message => {48 const messageString = typeof message === 'string' ? message : inspect(message);49 const escapedMessage = escapeLines(messageString);50 return escapedMessage.replaceAll('\t', ' '.repeat(TAB_SIZE));50 return escapedMessage.replaceAll('\t', () => ' '.repeat(TAB_SIZE));51};5253// Same as `util.inspect()`54const TAB_SIZE = 2;
modified:lib/verbose/output.js+1 added-1 removed
11 unmodified lines
12 && isFullVerbose(verboseInfo, fdNumber)13 && !BINARY_ENCODINGS.has(encoding)14 && fdUsesVerbose(fdNumber)15 && (stdioItems.some(({type, value}) => type === 'native' && PIPED_STDIO_VALUES.has(value))16 || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));16 || stdioItems.every(({type}) => TRANSFORM_TYPES.has(type)));1718// Printing input streams would be confusing.19// Files and streams can produce big outputs, which we don't want to print.20// We could print `stdio[3+]` but it often is redirected to files and streams, with the same issue.
40 unmodified lines
modified:test/arguments/encoding-option.js+1 added-1 removed
19 unmodified lines
20test('cannot pass encoding: false', testInvalidEncoding, false, UNKNOWN_ENCODING_MESSAGE, execa);21test('cannot pass encoding: Symbol', testInvalidEncoding, Symbol('test'), UNKNOWN_ENCODING_MESSAGE, execa);22test('cannot pass encoding: null', testInvalidEncoding, null, getCorrectEncodingMessage('buffer'), execa);23test('cannot pass encoding: null, sync', testInvalidEncoding, null, getCorrectEncodingMessage('buffer'), execaSync);24/* eslint-disable unicorn/text-encoding-identifier-case */24/* eslint-disable unicorn/text-encoding-identifier-case -- intentionally testing invalid encoding casing */25test('cannot pass encoding: utf-8', testInvalidEncoding, 'utf-8', getCorrectEncodingMessage('utf8'), execa);26test('cannot pass encoding: utf-8, sync', testInvalidEncoding, 'utf-8', getCorrectEncodingMessage('utf8'), execaSync);27test('cannot pass encoding: UTF-8', testInvalidEncoding, 'UTF-8', getCorrectEncodingMessage('utf8'), execa);28test('cannot pass encoding: UTF-8, sync', testInvalidEncoding, 'UTF-8', getCorrectEncodingMessage('utf8'), execaSync);
11 unmodified lines
modified:test/arguments/escape-no-icu.js+3 added-2 removed
1// Mimics Node.js when built without ICU support2// See https://github.com/sindresorhus/execa/issues/11433// eslint-disable-next-line unicorn/no-global-object-property-assignment -- intentionally mocking the global `RegExp`4globalThis.RegExp = class extends RegExp {5 static isMocked = true;67 constructor(regExpString, flags) {8 if (flags?.includes('u') && regExpString.includes('\\p{')) {9 throw new Error('Invalid property name');10 }1112 super(regExpString, flags);13 }1112 static isMocked = true;14};1516// Execa computes the RegExp when first loaded, so we must delay this import17await import('./escape.js');
modified:test/arguments/escape.js+13 added-12 removed
21 unmodified lines
22test(testResultCommand, '');2324// eslint-disable-next-line max-params25const testEscapedCommand = async (t, commandArguments, expectedUnix, expectedWindows, expectedUnixNoIcu = expectedUnix, expectedWindowsNoIcu = expectedWindows) => {26 // eslint-disable-next-line no-use-extend-native/no-use-extend-native -- `RegExp.isMocked` is a static property added by `escape-no-icu.js`, not a native extension27 const expected = RegExp.isMocked28 ? (isWindows ? expectedWindowsNoIcu : expectedUnixNoIcu)29 : (isWindows ? expectedWindows : expectedUnix);30
49 unmodified lines
80test('result.escapedCommand - {}', testEscapedCommand, ['{}'], '\'{}\'', '"{}"');81test('result.escapedCommand - []', testEscapedCommand, ['[]'], '\'[]\'', '"[]"');82test('result.escapedCommand - <>', testEscapedCommand, ['<>'], '\'<>\'', '"<>"');83test('result.escapedCommand - ã', testEscapedCommand, ['ã'], '\'ã\'', '"ã"');83test('result.escapedCommand - \\a', testEscapedCommand, ['\u0007'], '\'\\u0007\'', '"\\u0007"');84test('result.escapedCommand - \\a', testEscapedCommand, ['\u{7}'], '\'\\u0007\'', '"\\u0007"');85test('result.escapedCommand - \\b', testEscapedCommand, ['\b'], '\'\\b\'', '"\\b"');85test('result.escapedCommand - \\e', testEscapedCommand, ['\u001B'], '\'\\u001b\'', '"\\u001b"');86test('result.escapedCommand - \\e', testEscapedCommand, ['\u{1B}'], '\'\\u001b\'', '"\\u001b"');87test('result.escapedCommand - \\f', testEscapedCommand, ['\f'], '\'\\f\'', '"\\f"');88test('result.escapedCommand - \\n', testEscapedCommand, ['\n'], '\'\\n\'', '"\\n"');89test('result.escapedCommand - \\r\\n', testEscapedCommand, ['\r\n'], '\'\\r\\n\'', '"\\r\\n"');90test('result.escapedCommand - \\t', testEscapedCommand, ['\t'], '\'\\t\'', '"\\t"');91test('result.escapedCommand - \\v', testEscapedCommand, ['\v'], '\'\\u000b\'', '"\\u000b"');91test('result.escapedCommand - \\x01', testEscapedCommand, ['\u0001'], '\'\\u0001\'', '"\\u0001"');92test('result.escapedCommand - \\x7f', testEscapedCommand, ['\u007F'], '\'\\u007f\'', '"\\u007f"');93test('result.escapedCommand - \\u0085', testEscapedCommand, ['\u0085'], '\'\\u0085\'', '"\\u0085"');94test('result.escapedCommand - \\u2000', testEscapedCommand, ['\u2000'], '\'\\u2000\'', '"\\u2000"');95test('result.escapedCommand - \\u200E', testEscapedCommand, ['\u200E'], '\'\\u200e\'', '"\\u200e"', '\'\u200E\'', '"\u200E"');96test('result.escapedCommand - \\u2028', testEscapedCommand, ['\u2028'], '\'\\u2028\'', '"\\u2028"');97test('result.escapedCommand - \\u2029', testEscapedCommand, ['\u2029'], '\'\\u2029\'', '"\\u2029"');98test('result.escapedCommand - \\u5555', testEscapedCommand, ['\u5555'], '\'\u5555\'', '"\u5555"');99test('result.escapedCommand - \\uD800', testEscapedCommand, ['\uD800'], '\'\\ud800\'', '"\\ud800"', '\'\uD800\'', '"\uD800"');100test('result.escapedCommand - \\uE000', testEscapedCommand, ['\uE000'], '\'\\ue000\'', '"\\ue000"', '\'\uE000\'', '"\uE000"');92test('result.escapedCommand - \\x01', testEscapedCommand, ['\u{1}'], '\'\\u0001\'', '"\\u0001"');93test('result.escapedCommand - \\x7f', testEscapedCommand, ['\u{7F}'], '\'\\u007f\'', '"\\u007f"');94test('result.escapedCommand - \\u0085', testEscapedCommand, ['\u{85}'], '\'\\u0085\'', '"\\u0085"');95test('result.escapedCommand - \\u2000', testEscapedCommand, ['\u{2000}'], '\'\\u2000\'', '"\\u2000"');96test('result.escapedCommand - \\u200E', testEscapedCommand, ['\u{200E}'], '\'\\u200e\'', '"\\u200e"', '\'\u{200E}\'', '"\u{200E}"');97test('result.escapedCommand - \\u2028', testEscapedCommand, ['\u{2028}'], '\'\\u2028\'', '"\\u2028"');98test('result.escapedCommand - \\u2029', testEscapedCommand, ['\u{2029}'], '\'\\u2029\'', '"\\u2029"');99test('result.escapedCommand - \\u5555', testEscapedCommand, ['\u{5555}'], '\'\u{5555}\'', '"\u{5555}"');100test('result.escapedCommand - \\uD800', testEscapedCommand, ['\u{D800}'], '\'\\ud800\'', '"\\ud800"', '\'\u{D800}\'', '"\u{D800}"');101test('result.escapedCommand - \\uE000', testEscapedCommand, ['\u{E000}'], '\'\\ue000\'', '"\\ue000"', '\'\u{E000}\'', '"\u{E000}"');102test('result.escapedCommand - \\U1D172', testEscapedCommand, ['\u{1D172}'], '\'\u{1D172}\'', '"\u{1D172}"');103test('result.escapedCommand - \\U1D173', testEscapedCommand, ['\u{1D173}'], '\'\\U1d173\'', '"\\U1d173"', '\'\u{1D173}\'', '"\u{1D173}"');104test('result.escapedCommand - \\U10FFFD', testEscapedCommand, ['\u{10FFFD}'], '\'\\U10fffd\'', '"\\U10fffd"', '\'\u{10FFFD}\'', '"\u{10FFFD}"');
modified:test/fixtures/graceful-disconnect.js+1 added-1 removed
1#!/usr/bin/env node2import process from 'node:process';3import {once} from 'node:events';4import {getCancelSignal, sendMessage} from 'execa';4import {onAbortedSignal} from '../helpers/graceful.js';5import {getCancelSignal, sendMessage} from 'execa';67const cancelSignal = await getCancelSignal();8await onAbortedSignal(cancelSignal);9await Promise.all([
3 unmodified lines
modified:test/fixtures/graceful-print.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal} from 'execa';45const cancelSignal = await getCancelSignal();6await onAbortedSignal(cancelSignal);7console.log(cancelSignal.reason);
modified:test/fixtures/graceful-send-echo.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal, getOneMessage, sendMessage} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal, getOneMessage, sendMessage} from 'execa';45const message = await getOneMessage();6const cancelSignal = await getCancelSignal();7await sendMessage(message);
2 unmodified lines
modified:test/fixtures/graceful-send-print.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal, sendMessage} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal, sendMessage} from 'execa';45const cancelSignal = await getCancelSignal();6await sendMessage(cancelSignal.aborted);7await onAbortedSignal(cancelSignal);
1 unmodified line
modified:test/fixtures/graceful-send-string.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal, sendMessage} from 'execa';2import {foobarString} from '../helpers/input.js';3import {getCancelSignal, sendMessage} from 'execa';45await getCancelSignal();6await sendMessage(foobarString);
modified:test/fixtures/graceful-send-twice.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal, sendMessage} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal, sendMessage} from 'execa';45const cancelSignal = await getCancelSignal();6await sendMessage(cancelSignal.aborted);7await onAbortedSignal(cancelSignal);
1 unmodified line
modified:test/fixtures/graceful-send.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal, sendMessage} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal, sendMessage} from 'execa';45const cancelSignal = await getCancelSignal();6await onAbortedSignal(cancelSignal);7await sendMessage(cancelSignal.reason);
modified:test/fixtures/graceful-twice.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal, sendMessage} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal, sendMessage} from 'execa';45await getCancelSignal();6const cancelSignal = await getCancelSignal();7await onAbortedSignal(cancelSignal);
1 unmodified line
modified:test/fixtures/graceful-wait.js+1 added-1 removed
1#!/usr/bin/env node2import {getCancelSignal} from 'execa';2import {onAbortedSignal} from '../helpers/graceful.js';3import {getCancelSignal} from 'execa';45const cancelSignal = await getCancelSignal();6await onAbortedSignal(cancelSignal);
modified:test/fixtures/ipc-iterate-error.js+1 added-1 removed
12 unmodified lines
13 }14};1516process.on('error', () => {});17// eslint-disable-next-line unicorn/prefer-top-level-await1718const promise = echoMessages();19process.emit('error', new Error(foobarString));20await promise;
modified:test/fixtures/ipc-iterate-twice.js+1 added
6 unmodified lines
7 sendMessage(foobarString);8 // eslint-disable-next-line no-await-in-loop9 for await (const message of getEachMessage()) {10 if (message === foobarString) {11 // eslint-disable-next-line unicorn/no-break-in-nested-loop -- breaks only the inner loop, the outer loop must continue12 break;13 }1415 await sendMessage(`${index}${message}`);
2 unmodified lines
modified:test/fixtures/ipc-print-many-each.js+1 added
6 unmodified lines
7for (let index = 0; index < count; index += 1) {8 // eslint-disable-next-line no-await-in-loop, no-unreachable-loop9 for await (const message of getEachMessage()) {10 console.log(message);11 // eslint-disable-next-line unicorn/no-break-in-nested-loop -- breaks only the inner loop, the outer loop must continue12 break;13 }14}
modified:test/helpers/convert.js+1 added-1 removed
1 unmodified line
2import {finished} from 'node:stream/promises';3import getStream from 'get-stream';4import isPlainObj from 'is-plain-obj';5import {execa} from '../../index.js';6import {foobarString} from '../helpers/input.js';6import {foobarString} from './input.js';78export const arrayFromAsync = async (asyncIterable, lines = []) => {9 for await (const line of asyncIterable) {10 lines.push(line);
68 unmodified lines
modified:test/helpers/encoding.js+1 added-1 removed
2 unmodified lines
3export const multibyteChar = '\u{1F984}';4export const multibyteString = `${multibyteChar}${multibyteChar}`;5export const multibyteUint8Array = textEncoder.encode(multibyteString);6export const breakingLength = multibyteUint8Array.length * 0.75;7export const brokenSymbol = '\uFFFD';7export const brokenSymbol = '\u{FFFD}';
modified:test/helpers/fixtures-directory.js+1 added
3 unmodified lines
4import logProcessErrors from 'log-process-errors';5import pathKey from 'path-key';67// Make tests fail if any warning (such as a deprecation warning) is emitted8// eslint-disable-next-line unicorn/no-top-level-side-effects -- must run as soon as this helper is imported9logProcessErrors({10 onError(error, event) {11 if (event === 'warning') {12 throw error;
15 unmodified lines
modified:test/helpers/input.js+1 added-1 removed
2 unmodified lines
34const textEncoder = new TextEncoder();56export const foobarString = 'foobar';7export const foobarRed = `\u001B[31m${foobarString}\u001B[39m`;7export const foobarRed = `\u{1B}[31m${foobarString}\u{1B}[39m`;8export const foobarArray = ['foo', 'bar'];9export const foobarUint8Array = textEncoder.encode(foobarString);10export const foobarArrayBuffer = foobarUint8Array.buffer;11export const foobarUint16Array = new Uint16Array(foobarArrayBuffer);
11 unmodified lines
modified:test/helpers/node-version.js+1 added-1 removed
1import {version} from 'node:process';23export const majorNodeVersion = Number(version.split('.')[0].slice(1));3export const majorNodeVersion = Number(version.split('.', 1)[0].slice(1));
modified:test/helpers/override-promise.js+2 added
1// Can't use `test.before`, because `ava` needs `Promise`.2const nativePromise = Promise;3// eslint-disable-next-line unicorn/no-global-object-property-assignment -- intentionally mocking the global `Promise`4globalThis.Promise = class BrokenPromise {5 then() { // eslint-disable-line unicorn/no-thenable6 throw new Error('error');7 }8};910export function restorePromise() {11 // eslint-disable-next-line unicorn/no-global-object-property-assignment -- restoring the mocked global `Promise`12 globalThis.Promise = nativePromise;13}
modified:test/helpers/verbose.js+1 added-1 removed
83 unmodified lines
84const splitLines = stderr => stderr.split('\n');8586const normalizeStderr = stderr => replaceSymbols(normalizeDuration(normalizeTimestamp(stripVTControlCharacters(stderr))), {useFallback: true});87export const testTimestamp = '[00:00:00.000]';88const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}]/gm, testTimestamp);88const normalizeTimestamp = stderr => stderr.replaceAll(/^\[\d{2}:\d{2}:\d{2}.\d{3}\]/gm, () => testTimestamp);89const normalizeDuration = stderr => stderr.replaceAll(/\(done in [^)]+\)/g, '(done in 0ms)');9091export const getVerboseOption = (isVerbose, verbose = 'short') => ({verbose: isVerbose ? verbose : 'none'});92
12 unmodified lines
modified:test/helpers/wait.js+2 added-2 removed
1import {getStdio} from '../helpers/stdio.js';2import {noopGenerator} from '../helpers/generator.js';1import {getStdio} from './stdio.js';2import {noopGenerator} from './generator.js';34export const endOptionStream = ({stream}) => {5 stream.end();6};
11 unmodified lines
modified:test/io/output-async.js+4 added-8 removed
39 unmodified lines
40test.serial('process.std* listeners are cleaned up on success with a single input', testListenersCleanup, false);41test.serial('process.std* listeners are cleaned up on success with multiple inputs', testListenersCleanup, true);4243test.serial('Can spawn many subprocesses in parallel', async t => {44 const results = await Promise.all(45 Array.from({length: PARALLEL_COUNT}, () => execa('noop.js', [foobarString])),46 );44 const results = await Promise.all(Array.from({length: PARALLEL_COUNT}, () => execa('noop.js', [foobarString])));45 t.true(results.every(({stdout}) => stdout === foobarString));46});4748const testMaxListeners = async (t, isMultiple, maxListenersCount) => {
3 unmodified lines
52 standardStream.setMaxListeners(maxListenersCount);53 }5455 try {58 const results = await Promise.all(59 Array.from({length: PARALLEL_COUNT}, () => execa('empty.js', getComplexStdio(isMultiple))),60 );56 const results = await Promise.all(Array.from({length: PARALLEL_COUNT}, () => execa('empty.js', getComplexStdio(isMultiple))));57 t.true(results.every(({exitCode}) => exitCode === 0));58 } finally {59 await setImmediate();60 await setImmediate();
8 unmodified lines
6970test.serial('No warning with maxListeners 1 and ["pipe", "inherit"]', testMaxListeners, false, 1);71test.serial('No warning with maxListeners default and ["pipe", "inherit"]', testMaxListeners, false, defaultMaxListeners);72test.serial('No warning with maxListeners 100 and ["pipe", "inherit"]', testMaxListeners, false, 100);77test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"]', testMaxListeners, false, Number.POSITIVE_INFINITY);73test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"]', testMaxListeners, false, Infinity);74test.serial('No warning with maxListeners 0 and ["pipe", "inherit"]', testMaxListeners, false, 0);75test.serial('No warning with maxListeners 1 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 1);76test.serial('No warning with maxListeners default and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, defaultMaxListeners);77test.serial('No warning with maxListeners 100 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 100);82test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, Number.POSITIVE_INFINITY);78test.serial('No warning with maxListeners Infinity and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, Infinity);79test.serial('No warning with maxListeners 0 and ["pipe", "inherit"], multiple inputs', testMaxListeners, true, 0);
modified:test/ipc/buffer-messages.js+4 added-6 removed
77 unmodified lines
78 t.deepEqual(ipcOutput, []);79});8081test.serial('Can retrieve initial IPC messages under heavy load', async t => {82 await Promise.all(83 Array.from({length: PARALLEL_COUNT}, async (_, index) => {84 const {ipcOutput} = await execa('ipc-send-argv.js', [`${index}`], {ipc: true});85 t.deepEqual(ipcOutput, [`${index}`]);86 }),82 await Promise.all(Array.from({length: PARALLEL_COUNT}, async (_, index) => {83 const {ipcOutput} = await execa('ipc-send-argv.js', [`${index}`], {ipc: true});84 t.deepEqual(ipcOutput, [`${index}`]);85 }));87 );86});
modified:test/ipc/get-one.js+5 added-7 removed
53 unmodified lines
54 t.deepEqual(ipcOutput, []);55});5657test.serial('Can retrieve initial IPC messages under heavy load', async t => {58 await Promise.all(59 Array.from({length: PARALLEL_COUNT}, async (_, index) => {60 const subprocess = execa('ipc-send-argv.js', [`${index}`], {ipc: true, buffer: false});61 t.is(await subprocess.getOneMessage(), `${index}`);62 await subprocess;63 }),58 await Promise.all(Array.from({length: PARALLEL_COUNT}, async (_, index) => {59 const subprocess = execa('ipc-send-argv.js', [`${index}`], {ipc: true, buffer: false});60 t.is(await subprocess.getOneMessage(), `${index}`);61 await subprocess;62 }));64 );63});6465const testTwice = async (t, buffer, filter) => {66 const subprocess = execa('ipc-send.js', {ipc: true, buffer});
65 unmodified lines
modified:test/ipc/send.js+7 added-10 removed
13 unmodified lines
14 await subprocess;15});1617test.serial('Can exchange IPC messages under heavy load', async t => {18 await Promise.all(19 Array.from({length: PARALLEL_COUNT}, async (_, index) => {20 const subprocess = execa('ipc-echo.js', {ipc: true});21 await subprocess.sendMessage(index);22 t.is(await subprocess.getOneMessage(), index);23 await subprocess;24 }),18 await Promise.all(Array.from({length: PARALLEL_COUNT}, async (_, index) => {19 const subprocess = execa('ipc-echo.js', {ipc: true});20 await subprocess.sendMessage(index);21 t.is(await subprocess.getOneMessage(), index);22 await subprocess;23 }));25 );24});2526test('The "serialization" option defaults to "advanced"', async t => {27 const subprocess = execa('ipc-echo.js', {ipc: true});
56 unmodified lines
84});8586// EPIPE happens based on timing conditions, so we must repeat it until it happens87const findEpipeError = async t => {90 // eslint-disable-next-line no-constant-condition88 while (true) {89 // eslint-disable-next-line no-await-in-loop90 const error = await t.throwsAsync(getEpipeError());91 if (error.cause?.code === 'EPIPE') {
3 unmodified lines
95};9697const getEpipeError = async () => {98 const subprocess = execa('delay.js', ['0'], {ipc: true});102 // eslint-disable-next-line no-constant-condition99100 while (true) {101 // eslint-disable-next-line no-await-in-loop102 await subprocess.sendMessage('.');103 }
40 unmodified lines
modified:test/methods/command.js+1 added
193 unmodified lines
194 t.deepEqual(parseCommandString(''), []);195});196197test('parseCommandString() can get only whitespaces', t => {198 // eslint-disable-next-line unicorn/prefer-string-repeat199 t.deepEqual(parseCommandString(' '), []);200});
modified:test/methods/parameters-options.js+10 added-10 removed
19 unmodified lines
20};2122test('execa()\'s arguments can be numbers', testSerializeArgument, 1, execa);23test('execa()\'s arguments can be booleans', testSerializeArgument, true, execa);24test('execa()\'s arguments can be NaN', testSerializeArgument, Number.NaN, execa);25test('execa()\'s arguments can be Infinity', testSerializeArgument, Number.POSITIVE_INFINITY, execa);24test('execa()\'s arguments can be NaN', testSerializeArgument, NaN, execa);25test('execa()\'s arguments can be Infinity', testSerializeArgument, Infinity, execa);26test('execa()\'s arguments can be null', testSerializeArgument, null, execa);27test('execa()\'s arguments can be undefined', testSerializeArgument, undefined, execa);28test('execa()\'s arguments can be bigints', testSerializeArgument, 1n, execa);29test('execa()\'s arguments can be symbols', testSerializeArgument, Symbol('test'), execa);30test('execaSync()\'s arguments can be numbers', testSerializeArgument, 1, execaSync);31test('execaSync()\'s arguments can be booleans', testSerializeArgument, true, execaSync);32test('execaSync()\'s arguments can be NaN', testSerializeArgument, Number.NaN, execaSync);33test('execaSync()\'s arguments can be Infinity', testSerializeArgument, Number.POSITIVE_INFINITY, execaSync);32test('execaSync()\'s arguments can be NaN', testSerializeArgument, NaN, execaSync);33test('execaSync()\'s arguments can be Infinity', testSerializeArgument, Infinity, execaSync);34test('execaSync()\'s arguments can be null', testSerializeArgument, null, execaSync);35test('execaSync()\'s arguments can be undefined', testSerializeArgument, undefined, execaSync);36test('execaSync()\'s arguments can be bigints', testSerializeArgument, 1n, execaSync);37test('execaSync()\'s arguments can be symbols', testSerializeArgument, Symbol('test'), execaSync);38test('execaNode()\'s arguments can be numbers', testSerializeArgument, 1, execaNode);39test('execaNode()\'s arguments can be booleans', testSerializeArgument, true, execaNode);40test('execaNode()\'s arguments can be NaN', testSerializeArgument, Number.NaN, execaNode);41test('execaNode()\'s arguments can be Infinity', testSerializeArgument, Number.POSITIVE_INFINITY, execaNode);40test('execaNode()\'s arguments can be NaN', testSerializeArgument, NaN, execaNode);41test('execaNode()\'s arguments can be Infinity', testSerializeArgument, Infinity, execaNode);42test('execaNode()\'s arguments can be null', testSerializeArgument, null, execaNode);43test('execaNode()\'s arguments can be undefined', testSerializeArgument, undefined, execaNode);44test('execaNode()\'s arguments can be bigints', testSerializeArgument, 1n, execaNode);45test('execaNode()\'s arguments can be symbols', testSerializeArgument, Symbol('test'), execaNode);46test('$\'s arguments can be numbers', testSerializeArgument, 1, $);47test('$\'s arguments can be booleans', testSerializeArgument, true, $);48test('$\'s arguments can be NaN', testSerializeArgument, Number.NaN, $);49test('$\'s arguments can be Infinity', testSerializeArgument, Number.POSITIVE_INFINITY, $);48test('$\'s arguments can be NaN', testSerializeArgument, NaN, $);49test('$\'s arguments can be Infinity', testSerializeArgument, Infinity, $);50test('$\'s arguments can be null', testSerializeArgument, null, $);51test('$\'s arguments can be undefined', testSerializeArgument, undefined, $);52test('$\'s arguments can be bigints', testSerializeArgument, 1n, $);53test('$\'s arguments can be symbols', testSerializeArgument, Symbol('test'), $);54test('$.sync\'s arguments can be numbers', testSerializeArgument, 1, $.sync);55test('$.sync\'s arguments can be booleans', testSerializeArgument, true, $.sync);56test('$.sync\'s arguments can be NaN', testSerializeArgument, Number.NaN, $.sync);57test('$.sync\'s arguments can be Infinity', testSerializeArgument, Number.POSITIVE_INFINITY, $.sync);56test('$.sync\'s arguments can be NaN', testSerializeArgument, NaN, $.sync);57test('$.sync\'s arguments can be Infinity', testSerializeArgument, Infinity, $.sync);58test('$.sync\'s arguments can be null', testSerializeArgument, null, $.sync);59test('$.sync\'s arguments can be undefined', testSerializeArgument, undefined, $.sync);60test('$.sync\'s arguments can be bigints', testSerializeArgument, 1n, $.sync);61test('$.sync\'s arguments can be symbols', testSerializeArgument, Symbol('test'), $.sync);
14 unmodified lines
modified:test/methods/promise.js+2 added-2 removed
14 unmodified lines
15 let isCalled = false;16 const {stdout} = await execa('noop.js', ['foo']).finally(() => {17 isCalled = true;18 });19 t.is(isCalled, true);19 t.true(isCalled);20 t.is(stdout, 'foo');21});2223test('finally function is executed on failure', async t => {24 let isError = false;25 const {stdout, stderr} = await t.throwsAsync(execa('exit.js', ['2']).finally(() => {26 isError = true;27 }));28 t.is(isError, true);28 t.true(isError);29 t.is(typeof stdout, 'string');30 t.is(typeof stderr, 'string');31});32
21 unmodified lines
modified:test/methods/template.js+20 added-20 removed
73 unmodified lines
74test('$ splits expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');75test('$ concatenates tokens - " " (2 spaces)', testScriptStdout, () => $`echo.js a `, 'a');76test('$ concatenates expressions - " " (2 spaces)', testScriptStdout, () => $`echo.js ${'a'} `, 'a');77test('$ handles tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js `, '');78// eslint-disable-next-line unicorn/prefer-string-repeat79test('$ handles expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${' '}`, ' ');80test('$ splits tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a b`, 'a\nb');81test('$ splits expressions - " " (3 spaces)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\nb');82test('$ concatenates tokens - " " (3 spaces)', testScriptStdout, () => $`echo.js a `, 'a');
31 unmodified lines
114test('$ concatenates tokens - \\n (escape)', testScriptStdout, () => $`echo.js \na\n b`, '\na\n\nb');115test('$ concatenates expressions - \\n (escape)', testScriptStdout, () => $`echo.js \n${'a'}\n b`, '\na\n\nb');116test('$ handles tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \r '), '');117test('$ splits tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js a\rb'), 'a\nb');117test('$ splits expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r${'b'}`), 'a\nb');118test('$ splits expressions - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js a\rb'), 'a\nb');119test('$ concatenates tokens - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \ra\r b'), 'a\nb');119test('$ concatenates expressions - \\r (no escape)', testScriptStdout, () => escapedCall(`echo.js \r${'a'}\r b`), 'a\nb');120test('$ concatenates expressions - \\r (no escape)', testScriptStdout, () => escapedCall('echo.js \ra\r b'), 'a\nb');121test('$ splits tokens - \\r (escape)', testScriptStdout, () => $`echo.js a\r b`, 'a\r\nb');122test('$ splits expressions - \\r (escape)', testScriptStdout, () => $`echo.js ${'a'}\r ${'b'}`, 'a\r\nb');123test('$ concatenates tokens - \\r (escape)', testScriptStdout, () => $`echo.js \ra\r b`, '\ra\r\nb');124test('$ concatenates expressions - \\r (escape)', testScriptStdout, () => $`echo.js \r${'a'}\r b`, '\ra\r\nb');125test('$ handles tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\n '), '');126test('$ splits tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js a\r\nb'), 'a\nb');126test('$ splits expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js ${'a'}\r\n${'b'}`), 'a\nb');127test('$ splits expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js a\r\nb'), 'a\nb');128test('$ concatenates tokens - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\na\r\n b'), 'a\nb');128test('$ concatenates expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall(`echo.js \r\n${'a'}\r\n b`), 'a\nb');129test('$ concatenates expressions - \\r\\n (no escape)', testScriptStdout, () => escapedCall('echo.js \r\na\r\n b'), 'a\nb');130test('$ handles tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n `, '\r\n');131test('$ handles expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'\r\n'} `, '\r\n');132test('$ splits tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js a\r\n b`, 'a\r\n\nb');133test('$ splits expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js ${'a'}\r\n ${'b'}`, 'a\r\n\nb');134test('$ concatenates tokens - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\na\r\n b`, '\r\na\r\n\nb');135test('$ concatenates expressions - \\r\\n (escape)', testScriptStdout, () => $`echo.js \r\n${'a'}\r\n b`, '\r\na\r\n\nb');135/* eslint-disable no-irregular-whitespace */136/* eslint-disable no-irregular-whitespace -- intentionally testing a literal form feed character */137test('$ handles expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${' '}`, '\f');138test('$ splits tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, 'a\fb');139test('$ splits expressions - \\f (no escape)', testScriptStdout, () => $`echo.js ${'a'} ${'b'}`, 'a\fb');140test('$ concatenates tokens - \\f (no escape)', testScriptStdout, () => $`echo.js a b`, '\fa\f\nb');
28 unmodified lines
169test('$ splits tokens - \\v', testScriptStdout, () => $`echo.js a\vb`, 'a\vb');170test('$ splits expressions - \\v', testScriptStdout, () => $`echo.js ${'a'}\v${'b'}`, 'a\vb');171test('$ concatenates tokens - \\v', testScriptStdout, () => $`echo.js \va\v b`, '\va\v\nb');172test('$ concatenates expressions - \\v', testScriptStdout, () => $`echo.js \v${'a'}\v b`, '\va\v\nb');172test('$ handles tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028`, '\u2028');173test('$ handles expressions - \\u2028', testScriptStdout, () => $`echo.js ${'\u2028'}`, '\u2028');174test('$ splits tokens - \\u2028', testScriptStdout, () => $`echo.js a\u2028b`, 'a\u2028b');175test('$ splits expressions - \\u2028', testScriptStdout, () => $`echo.js ${'a'}\u2028${'b'}`, 'a\u2028b');176test('$ concatenates tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028a\u2028 b`, '\u2028a\u2028\nb');177test('$ concatenates expressions - \\u2028', testScriptStdout, () => $`echo.js \u2028${'a'}\u2028 b`, '\u2028a\u2028\nb');173test('$ handles tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028`, '\u{2028}');174test('$ handles expressions - \\u2028', testScriptStdout, () => $`echo.js ${'\u{2028}'}`, '\u{2028}');175test('$ splits tokens - \\u2028', testScriptStdout, () => $`echo.js a\u2028b`, 'a\u{2028}b');176test('$ splits expressions - \\u2028', testScriptStdout, () => $`echo.js ${'a'}\u2028${'b'}`, 'a\u{2028}b');177test('$ concatenates tokens - \\u2028', testScriptStdout, () => $`echo.js \u2028a\u2028 b`, '\u{2028}a\u{2028}\nb');178test('$ concatenates expressions - \\u2028', testScriptStdout, () => $`echo.js \u2028${'a'}\u2028 b`, '\u{2028}a\u{2028}\nb');179test('$ handles tokens - \\a', testScriptStdout, () => $`echo.js \a`, 'a');180test('$ splits tokens - \\a', testScriptStdout, () => $`echo.js a\ab`, 'aab');181test('$ splits expressions - \\a', testScriptStdout, () => $`echo.js ${'a'}\a${'b'}`, 'aab');182test('$ concatenates tokens - \\a', testScriptStdout, () => $`echo.js \aa\a b`, 'aaa\nb');
7 unmodified lines
190test('$ splits tokens - \\.', testScriptStdout, () => $`echo.js a\.b`, 'a.b');191test('$ splits expressions - \\.', testScriptStdout, () => $`echo.js ${'a'}\.${'b'}`, 'a.b');192test('$ concatenates tokens - \\.', testScriptStdout, () => $`echo.js \.a\. b`, '.a.\nb');193test('$ concatenates expressions - \\.', testScriptStdout, () => $`echo.js \.${'a'}\. b`, '.a.\nb');193/* eslint-disable unicorn/no-hex-escape */194195test('$ handles tokens - \\x63', testScriptStdout, () => $`echo.js \x63`, 'c');196test('$ splits tokens - \\x63', testScriptStdout, () => $`echo.js a\x63b`, 'acb');197test('$ splits expressions - \\x63', testScriptStdout, () => $`echo.js ${'a'}\x63${'b'}`, 'acb');198test('$ concatenates tokens - \\x63', testScriptStdout, () => $`echo.js \x63a\x63 b`, 'cac\nb');199test('$ concatenates expressions - \\x63', testScriptStdout, () => $`echo.js \x63${'a'}\x63 b`, 'cac\nb');199/* eslint-enable unicorn/no-hex-escape */200201test('$ handles tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063`, 'c');202test('$ splits tokens - \\u0063', testScriptStdout, () => $`echo.js a\u0063b`, 'acb');203test('$ splits expressions - \\u0063', testScriptStdout, () => $`echo.js ${'a'}\u0063${'b'}`, 'acb');204test('$ concatenates tokens - \\u0063', testScriptStdout, () => $`echo.js \u0063a\u0063 b`, 'cac\nb');205test('$ concatenates expressions - \\u0063', testScriptStdout, () => $`echo.js \u0063${'a'}\u0063 b`, 'cac\nb');205test('$ handles tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}`, '\u0001');206test('$ splits tokens - \\u{1}', testScriptStdout, () => $`echo.js a\u{1}b`, 'a\u0001b');207test('$ splits expressions - \\u{1}', testScriptStdout, () => $`echo.js ${'a'}\u{1}${'b'}`, 'a\u0001b');208test('$ concatenates tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}a\u{1} b`, '\u0001a\u0001\nb');209test('$ concatenates expressions - \\u{1}', testScriptStdout, () => $`echo.js \u{1}${'a'}\u{1} b`, '\u0001a\u0001\nb');206test('$ handles tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}`, '\u{1}');207test('$ splits tokens - \\u{1}', testScriptStdout, () => $`echo.js a\u{1}b`, 'a\u{1}b');208test('$ splits expressions - \\u{1}', testScriptStdout, () => $`echo.js ${'a'}\u{1}${'b'}`, 'a\u{1}b');209test('$ concatenates tokens - \\u{1}', testScriptStdout, () => $`echo.js \u{1}a\u{1} b`, '\u{1}a\u{1}\nb');210test('$ concatenates expressions - \\u{1}', testScriptStdout, () => $`echo.js \u{1}${'a'}\u{1} b`, '\u{1}a\u{1}\nb');211test('$ handles tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}`, 'c');212test('$ splits tokens - \\u{63}', testScriptStdout, () => $`echo.js a\u{63}b`, 'acb');213test('$ splits expressions - \\u{63}', testScriptStdout, () => $`echo.js ${'a'}\u{63}${'b'}`, 'acb');214test('$ concatenates tokens - \\u{63}', testScriptStdout, () => $`echo.js \u{63}a\u{63} b`, 'cac\nb');
73 unmodified lines
288test('$ handles invalid escape sequence - \\ug', testInvalidSequence, () => $`echo.js \ug`);289test('$ handles invalid escape sequence - \\u{', testInvalidSequence, () => $`echo.js \u{`);290test('$ handles invalid escape sequence - \\u{0000', testInvalidSequence, () => $`echo.js \u{0000`);291test('$ handles invalid escape sequence - \\u{g}', testInvalidSequence, () => $`echo.js \u{g}`);291/* eslint-disable unicorn/no-hex-escape */292293test('$ handles invalid escape sequence - \\x', testInvalidSequence, () => $`echo.js \x`);294test('$ handles invalid escape sequence - \\x0', testInvalidSequence, () => $`echo.js \x0`);295test('$ handles invalid escape sequence - \\xgg', testInvalidSequence, () => $`echo.js \xgg`);295/* eslint-enable unicorn/no-hex-escape */296297const testEmptyScript = (t, getSubprocess) => {298 t.throws(getSubprocess, {message: /Template script must not be empty/});299};
53 unmodified lines
modified:test/resolve/exit.js+1 added-3 removed
11 unmodified lines
12 t.is(exitCode, 0);13});1415const testExitCode = async (t, expectedExitCode) => {16 const {exitCode, originalMessage, shortMessage, message} = await t.throwsAsync(17 execa('exit.js', [`${expectedExitCode}`]),18 );16 const {exitCode, originalMessage, shortMessage, message} = await t.throwsAsync(execa('exit.js', [`${expectedExitCode}`]));17 t.is(exitCode, expectedExitCode);18 t.is(originalMessage, undefined);19 t.is(shortMessage, `Command failed with exit code ${expectedExitCode}: exit.js ${expectedExitCode}`);20 t.is(message, shortMessage);
63 unmodified lines
modified:test/return/early-error.js+5 added-3 removed
24 unmodified lines
2526const testEarlyErrorShape = async (t, reject) => {27 const subprocess = getEarlyErrorSubprocess({reject});28 t.notThrows(() => {29 // eslint-disable-next-line promise/prefer-await-to-then29 subprocess.catch(() => {});30 subprocess.unref();31 subprocess.on('error', () => {});32 });
30 unmodified lines
63 });6465 if (arch() === 'x64') {66 test('write to fast-exit subprocess', async t => {67 t.plan(1);6868 // Try-catch here is necessary, because this test is not 100% accurate69 // Sometimes subprocess can manage to accept input before exiting69 // Try-catch here is necessary, because this test is not 100% accurate70 // Sometimes subprocess can manage to accept input before exiting71 try {72 await execa(`fast-exit-${process.platform}`, [], {input: 'data'});73 t.pass();74 } catch (error) {75 // eslint-disable-next-line ava/no-conditional-assertion -- either outcome is acceptable, see comment above76 t.is(error.code, 'EPIPE');77 }78 });79 }
41 unmodified lines
modified:test/return/message.js+2 added-1 removed
71 unmodified lines
72test('error.message does not contain stdout if it is an object', testPartialIgnoreMessage, 1, outputObjectGenerator(), 'stderr');73test('error.message does not contain stderr if it is an object', testPartialIgnoreMessage, 2, outputObjectGenerator(), 'stdout');7475const testFullIgnoreMessage = async (t, options, resultProperty) => {76 const {[resultProperty]: message} = await t.throwsAsync(execa('echo-fail.js', options));76 const result = await t.throwsAsync(execa('echo-fail.js', options));77 const message = result[resultProperty];78 t.false(message.includes('stderr'));79 t.false(message.includes('stdout'));80 t.false(message.includes('fd3'));81};
38 unmodified lines
modified:test/return/result.js+2 added-2 removed
95 unmodified lines
9697 // `subprocess.kill()` is emulated by Node.js on Windows98 if (isWindows) {99 const {isTerminated, signal} = await t.throwsAsync(subprocess, {message: /failed with exit code 1/});100 t.is(isTerminated, false);100 t.false(isTerminated);101 t.is(signal, undefined);102 } else {103 const {isTerminated, signal} = await t.throwsAsync(subprocess, {message: /was killed with SIGINT/});104 t.is(isTerminated, true);104 t.true(isTerminated);105 t.is(signal, 'SIGINT');106 }107});108
39 unmodified lines
modified:test/terminate/kill-force.js+1 added-1 removed
43 unmodified lines
44 execa('empty.js', {forceKillAfterDelay});45 }, {instanceOf: TypeError, message: /non-negative integer/});46};4748test('`forceKillAfterDelay` should not be NaN', testInvalidForceKill, Number.NaN);48test('`forceKillAfterDelay` should not be NaN', testInvalidForceKill, NaN);49test('`forceKillAfterDelay` should not be negative', testInvalidForceKill, -1);5051// `SIGTERM` cannot be caught on Windows, and it always aborts the subprocess (like `SIGKILL` on Unix).52// Therefore, this feature and those tests must be different on Windows.
166 unmodified lines
modified:test/terminate/kill-signal.js+4 added-18 removed
1import {once} from 'node:events';2import {platform} from 'node:process';2import {constants} from 'node:os';3import {setImmediate} from 'node:timers/promises';4import test from 'ava';5import {execa, execaSync} from '../../index.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {majorNodeVersion} from '../helpers/node-version.js';78setFixtureDirectory();912const isWindows = platform === 'win32';1310const testKillSignal = async (t, killSignal) => {11 const {isTerminated, signal} = await t.throwsAsync(execa('forever.js', {killSignal, timeout: 1}));12 t.true(isTerminated);13 t.is(signal, 'SIGINT');
42 unmodified lines
56 subprocess.kill();57 subprocess.kill();5859 const {exitCode, isTerminated, signal, code} = await t.throwsAsync(subprocess);64 // On Windows, calling `subprocess.kill()` twice emits an `error` event on the subprocess.65 // This does not happen when passing an `error` argument, nor when passing a non-terminating signal.66 // There is no easy way to make this cross-platform, so we document the difference here.67 if (isWindows && majorNodeVersion === 22) {68 t.is(exitCode, undefined);69 t.false(isTerminated);70 t.is(signal, undefined);71 t.is(code, 'EPERM');72 } else {73 t.is(exitCode, undefined);74 t.true(isTerminated);75 t.is(signal, 'SIGTERM');76 t.is(code, undefined);60 t.is(exitCode, undefined);61 t.true(isTerminated);62 t.is(signal, 'SIGTERM');63 t.is(code, undefined);77 }64});6566test('execa() returns a promise with kill()', async t => {67 const subprocess = execa('noop.js', ['foo']);
73 unmodified lines
modified:test/terminate/signal.js+6 added-6 removed
34 unmodified lines
35test('Cannot use killSignal: -1', testInvalidKillSignal, -1, 'integer', execa);36test('Cannot use killSignal: 200', testInvalidKillSignal, 200, 'integer', execa);37test('Cannot use killSignal: 1n', testInvalidKillSignal, 1n, 'other', execa);38test('Cannot use killSignal: 1.5', testInvalidKillSignal, 1.5, 'other', execa);39test('Cannot use killSignal: Infinity', testInvalidKillSignal, Number.POSITIVE_INFINITY, 'other', execa);40test('Cannot use killSignal: NaN', testInvalidKillSignal, Number.NaN, 'other', execa);39test('Cannot use killSignal: Infinity', testInvalidKillSignal, Infinity, 'other', execa);40test('Cannot use killSignal: NaN', testInvalidKillSignal, NaN, 'other', execa);41test('Cannot use killSignal: false', testInvalidKillSignal, false, 'other', execa);42test('Cannot use killSignal: null', testInvalidKillSignal, null, 'other', execa);43test('Cannot use killSignal: symbol', testInvalidKillSignal, Symbol('test'), 'other', execa);44test('Cannot use killSignal: {}', testInvalidKillSignal, {}, 'other', execa);
3 unmodified lines
48test('Cannot use killSignal: "sigterm", sync', testInvalidKillSignal, 'sigterm', 'rename', execaSync);49test('Cannot use killSignal: -1, sync', testInvalidKillSignal, -1, 'integer', execaSync);50test('Cannot use killSignal: 200, sync', testInvalidKillSignal, 200, 'integer', execaSync);51test('Cannot use killSignal: 1.5, sync', testInvalidKillSignal, 1.5, 'other', execaSync);52test('Cannot use killSignal: Infinity, sync', testInvalidKillSignal, Number.POSITIVE_INFINITY, 'other', execaSync);53test('Cannot use killSignal: NaN, sync', testInvalidKillSignal, Number.NaN, 'other', execaSync);52test('Cannot use killSignal: Infinity, sync', testInvalidKillSignal, Infinity, 'other', execaSync);53test('Cannot use killSignal: NaN, sync', testInvalidKillSignal, NaN, 'other', execaSync);54test('Cannot use killSignal: null, sync', testInvalidKillSignal, null, 'other', execaSync);55test('Cannot use killSignal: symbol, sync', testInvalidKillSignal, Symbol('test'), 'other', execaSync);56test('Cannot use killSignal: {}, sync', testInvalidKillSignal, {}, 'other', execaSync);57test('Cannot use killSignal: 0, sync', testInvalidKillSignal, 0, 'zero', execaSync);
20 unmodified lines
78test('Cannot use subprocess.kill(-1)', testInvalidSignalArgument, -1, 'integer');79test('Cannot use subprocess.kill(200)', testInvalidSignalArgument, 200, 'integer');80test('Cannot use subprocess.kill(1n)', testInvalidSignalArgument, 1n, 'other');81test('Cannot use subprocess.kill(1.5)', testInvalidSignalArgument, 1.5, 'other');82test('Cannot use subprocess.kill(Infinity)', testInvalidSignalArgument, Number.POSITIVE_INFINITY, 'other');83test('Cannot use subprocess.kill(NaN)', testInvalidSignalArgument, Number.NaN, 'other');82test('Cannot use subprocess.kill(Infinity)', testInvalidSignalArgument, Infinity, 'other');83test('Cannot use subprocess.kill(NaN)', testInvalidSignalArgument, NaN, 'other');84test('Cannot use subprocess.kill(false)', testInvalidSignalArgument, false, 'other');85test('Cannot use subprocess.kill(null)', testInvalidSignalArgument, null, 'other');86test('Cannot use subprocess.kill(symbol)', testInvalidSignalArgument, Symbol('test'), 'other');87test('Cannot use subprocess.kill({})', testInvalidSignalArgument, {}, 'other');
modified:test/transform/encoding-final.js+1 added-1 removed
39 unmodified lines
40 }41};4243// This string gives different outputs with each encoding type44const STRING_TO_ENCODE = '\u1000.';44const STRING_TO_ENCODE = '\u{1000}.';45const BUFFER_TO_ENCODE = Buffer.from(STRING_TO_ENCODE);4647test('can pass encoding "buffer" to stdout', checkEncoding, 'buffer', 1, execa);48test('can pass encoding "utf8" to stdout', checkEncoding, 'utf8', 1, execa);
81 unmodified lines
modified:test/transform/encoding-multibyte.js+1 added
20 unmodified lines
21 });22 if (objectMode) {23 t.deepEqual(stdout, foobarArray);24 } else {25 // eslint-disable-next-line n/prefer-global/buffer, unicorn/prefer-uint8array-base64 -- `Uint8Array#toBase64()` is not available on the minimum supported Node.js version26 t.is(stdout, Buffer.from(foobarArray.join('')).toString('base64'));27 }28};29
51 unmodified lines
modified:test/transform/split-lines.js+1 added-1 removed
29 unmodified lines
30const emptyChunks = [emptyFull];31const manyEmptyChunks = [emptyFull, emptyFull, emptyFull];32const newlineFull = '\n';33const newlineChunks = [newlineFull];34const newlinesFull = '\n\n\n';34const newlinesFull = '\n'.repeat(3);35const newlinesChunks = [newlinesFull];36const newlinesLines = ['\n', '\n', '\n'];37const windowsNewlinesFull = '\r\n\r\n\r\n';38const windowsNewlinesChunks = [windowsNewlinesFull];
136 unmodified lines
modified:test/verbose/error.js+3 added-5 removed
1import test from 'ava';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {foobarString} from '../helpers/input.js';3import {foobarString, foobarRed} from '../helpers/input.js';4import {nestedSubprocess} from '../helpers/nested.js';5import {6 QUOTE,7 runErrorSubprocess,
18 unmodified lines
26} from '../helpers/verbose.js';2728setFixtureDirectory();2930const redFoobarString = `\u001B[31m${foobarString}\u001B[39m`;3130const testPrintError = async (t, verbose, isSync) => {31 const stderr = await runErrorSubprocess(t, verbose, isSync, getStdioForFd3Option(verbose));32 t.is(getErrorLine(stderr), `${testTimestamp} [0] × Command failed with exit code 2: noop-fail.js 1 ${foobarString}`);33};
115 unmodified lines
149 ]);150});151152test('Escapes and strips color sequences from error', async t => {155 const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', [redFoobarString], {parentFixture: 'nested-fail.js', verbose: 'short'}));153 const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', [foobarRed], {parentFixture: 'nested-fail.js', verbose: 'short'}));154 t.deepEqual(getErrorLines(stderr), [155 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`,156 `${testTimestamp} [0] × ${foobarString}`,157 ]);158});159160test('Escapes control characters from error', async t => {163 const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', ['\u0001'], {parentFixture: 'nested-fail.js', verbose: 'short'}));161 const {stderr} = await t.throwsAsync(nestedSubprocess('noop-forever.js', ['\u{1}'], {parentFixture: 'nested-fail.js', verbose: 'short'}));162 t.deepEqual(getErrorLines(stderr), [163 `${testTimestamp} [0] × Command was killed with SIGTERM (Termination): noop-forever.js ${QUOTE}\\u0001${QUOTE}`,164 `${testTimestamp} [0] × \\u0001`,165 ]);
1 unmodified line
modified:test/verbose/ipc.js+6 added-4 removed
1import {on} from 'node:events';2import {inspect} from 'node:util';3import test from 'ava';4import {red} from 'yoctocolors';4import {execa} from '../../index.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {foobarString, foobarObject} from '../helpers/input.js';6import {foobarString, foobarRed, foobarObject} from '../helpers/input.js';7import {nestedSubprocess, nestedInstance} from '../helpers/nested.js';8import {fullStdio} from '../helpers/stdio.js';9import {10 getIpcLine,
86 unmodified lines
97 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ã`);98});99100test('Strips color sequences from IPC', async t => {102 const {stderr} = await nestedSubprocess('ipc-send.js', [red(foobarString)], {ipc: true, verbose: 'full'}, {env: {FORCE_COLOR: '1', NO_COLOR: undefined}});101 const {stderr} = await nestedSubprocess('ipc-send.js', [foobarRed], {ipc: true, verbose: 'full'});102 t.is(getIpcLine(stderr), `${testTimestamp} [0] * ${foobarString}`);103});104105test('Escapes control characters from IPC', async t => {107 const {stderr} = await nestedSubprocess('ipc-send.js', ['\u0001'], {ipc: true, verbose: 'full'});106 const {stderr} = await nestedSubprocess('ipc-send.js', ['\u{1}'], {ipc: true, verbose: 'full'});107 t.is(getIpcLine(stderr), `${testTimestamp} [0] * \\u0001`);108});109110test('Prints IPC progressively', async t => {111 t.plan(2);112113 const subprocess = nestedInstance('ipc-send-forever.js', {ipc: true, verbose: 'full'});114 for await (const chunk of on(subprocess.stderr, 'data')) {115 const ipcLine = getIpcLine(chunk.toString());116 if (ipcLine !== undefined) {117 // eslint-disable-next-line ava/no-conditional-assertion -- `t.plan()` ensures this always executes118 t.is(ipcLine, `${testTimestamp} [0] * ${foobarString}`);119 break;120 }121 }
4 unmodified lines
modified:test/verbose/log.js+1 added-2 removed
28 unmodified lines
29test('Prints without colors if not supported', testColor, false, '0');3031test.serial('Prints lines in order when interleaved with subprocess stderr', async t => {32 const results = await Promise.all(Array.from({length: PARALLEL_COUNT}, () =>33 nestedSubprocess('noop-fd.js', ['2', `${foobarString}\n`], {verbose: 'full', stderr: 'inherit'}, {all: true}),34 ));33 nestedSubprocess('noop-fd.js', ['2', `${foobarString}\n`], {verbose: 'full', stderr: 'inherit'}, {all: true})));34 for (const {all} of results) {35 t.deepEqual(36 getNormalizedLines(all),37 [getCommandLine(all), foobarString, getCompletionLine(all)],
3 unmodified lines
modified:test/verbose/output-enable.js+3 added-4 removed
1import test from 'ava';2import {red} from 'yoctocolors';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString, foobarUtf16Uint8Array} from '../helpers/input.js';3import {foobarString, foobarRed, foobarUtf16Uint8Array} from '../helpers/input.js';4import {fullStdio} from '../helpers/stdio.js';5import {nestedSubprocess} from '../helpers/nested.js';6import {7 runErrorSubprocess,
96 unmodified lines
104 t.is(getOutputLine(stderr), `${testTimestamp} [0] ã`);105});106107test('Strips color sequences from stdout', async t => {109 const {stderr} = await nestedSubprocess('noop.js', [red(foobarString)], {verbose: 'full'}, {env: {FORCE_COLOR: '1', NO_COLOR: undefined}});108 const {stderr} = await nestedSubprocess('noop.js', [foobarRed], {verbose: 'full'});109 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);110});111112test('Escapes control characters from stdout', async t => {114 const {stderr} = await nestedSubprocess('noop.js', ['\u0001'], {verbose: 'full'});113 const {stderr} = await nestedSubprocess('noop.js', ['\u{1}'], {verbose: 'full'});114 t.is(getOutputLine(stderr), `${testTimestamp} [0] \\u0001`);115});116117const testStdioSame = async (t, fdNumber) => {
27 unmodified lines
modified:test/verbose/output-progressive.js+3 added
6 unmodified lines
78setFixtureDirectory();910test('Prints stdout one line at a time', async t => {11 t.plan(1);1213 const subprocess = nestedInstance('noop-progressive.js', [foobarString], {verbose: 'full'});1415 for await (const chunk of on(subprocess.stderr, 'data')) {16 const outputLine = getOutputLine(chunk.toString().trim());17 if (outputLine !== undefined) {18 // eslint-disable-next-line ava/no-conditional-assertion -- `t.plan()` ensures this always executes19 t.is(outputLine, `${testTimestamp} [0] ${foobarString}`);20 break;21 }22 }
39 unmodified lines
modified:test/verbose/start.js+3 added-5 removed
1import test from 'ava';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {foobarString} from '../helpers/input.js';3import {foobarString, foobarRed} from '../helpers/input.js';4import {nestedSubprocess} from '../helpers/nested.js';5import {6 QUOTE,7 runErrorSubprocess,
18 unmodified lines
26} from '../helpers/verbose.js';2728setFixtureDirectory();2930const redFoobarString = `\u001B[31m${foobarString}\u001B[39m`;3130const testPrintCommand = async (t, verbose, worker, isSync) => {31 const {stderr} = await nestedSubprocess('noop.js', [foobarString], {32 verbose,33 ...getStdioForFd3Option(verbose),
122 unmodified lines
156 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}ã${QUOTE}`);157});158159test('Escapes color sequences from command', async t => {162 const {stderr} = await nestedSubprocess('noop.js', [redFoobarString], {verbose: 'short'});160 const {stderr} = await nestedSubprocess('noop.js', [foobarRed], {verbose: 'short'});161 t.true(getCommandLine(stderr).includes(`${QUOTE}\\u001b[31m${foobarString}\\u001b[39m${QUOTE}`));162});163164test('Escapes control characters from command', async t => {167 const {stderr} = await nestedSubprocess('noop.js', ['\u0001'], {verbose: 'short'});165 const {stderr} = await nestedSubprocess('noop.js', ['\u{1}'], {verbose: 'short'});166 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${QUOTE}\\u0001${QUOTE}`);167});
modified:test-d/arguments/encoding-option.test-d.ts+1 added-1 removed
1 unmodified line
2import {execa, execaSync} from '../../index.js';34await execa('unicorns', {encoding: 'utf8'});5execaSync('unicorns', {encoding: 'utf8'});6/* eslint-disable unicorn/text-encoding-identifier-case */6/* eslint-disable unicorn/text-encoding-identifier-case -- intentionally testing invalid encoding casing */7expectError(await execa('unicorns', {encoding: 'utf-8'}));8expectError(execaSync('unicorns', {encoding: 'utf-8'}));9expectError(await execa('unicorns', {encoding: 'UTF8'}));10expectError(execaSync('unicorns', {encoding: 'UTF8'}));
38 unmodified lines
modified:test-d/arguments/options.test-d.ts+25 added-25 removed
23 unmodified lines
24expectError(execaSync('unicorns', {preferLocal: 'false'}));2526await execa('unicorns', {localDir: '.'});27execaSync('unicorns', {localDir: '.'});28await execa('unicorns', {localDir: '.' as string});29execaSync('unicorns', {localDir: '.' as string});28await execa('unicorns', {localDir: '.'});29execaSync('unicorns', {localDir: '.'});30await execa('unicorns', {localDir: fileUrl});31execaSync('unicorns', {localDir: fileUrl});32expectError(await execa('unicorns', {localDir: false}));33expectError(execaSync('unicorns', {localDir: false}));
6 unmodified lines
40expectError(execaSync('unicorns', {node: 'true'}));4142await execa('unicorns', {nodePath: './node'});43execaSync('unicorns', {nodePath: './node'});44await execa('unicorns', {nodePath: './node' as string});45execaSync('unicorns', {nodePath: './node' as string});44await execa('unicorns', {nodePath: './node'});45execaSync('unicorns', {nodePath: './node'});46await execa('unicorns', {nodePath: fileUrl});47execaSync('unicorns', {nodePath: fileUrl});48expectError(await execa('unicorns', {nodePath: false}));49expectError(execaSync('unicorns', {nodePath: false}));
6 unmodified lines
56expectError(execaSync('unicorns', {nodeOptions: [false] as const}));5758await execa('unicorns', {input: ''});59execaSync('unicorns', {input: ''});60await execa('unicorns', {input: '' as string});61execaSync('unicorns', {input: '' as string});60await execa('unicorns', {input: ''});61execaSync('unicorns', {input: ''});62await execa('unicorns', {input: new Uint8Array()});63execaSync('unicorns', {input: new Uint8Array()});64await execa('unicorns', {input: process.stdin});65execaSync('unicorns', {input: process.stdin});
1 unmodified line
67expectError(execaSync('unicorns', {input: false}));6869await execa('unicorns', {inputFile: ''});70execaSync('unicorns', {inputFile: ''});71await execa('unicorns', {inputFile: '' as string});72execaSync('unicorns', {inputFile: '' as string});71await execa('unicorns', {inputFile: ''});72execaSync('unicorns', {inputFile: ''});73await execa('unicorns', {inputFile: fileUrl});74execaSync('unicorns', {inputFile: fileUrl});75expectError(await execa('unicorns', {inputFile: false}));76expectError(execaSync('unicorns', {inputFile: false}));
27 unmodified lines
104expectError(execaSync('unicorns', {extendEnv: 'false'}));105106await execa('unicorns', {cwd: '.'});107execaSync('unicorns', {cwd: '.'});108await execa('unicorns', {cwd: '.' as string});109execaSync('unicorns', {cwd: '.' as string});108await execa('unicorns', {cwd: '.'});109execaSync('unicorns', {cwd: '.'});110await execa('unicorns', {cwd: fileUrl});111execaSync('unicorns', {cwd: fileUrl});112expectError(await execa('unicorns', {cwd: false}));113expectError(execaSync('unicorns', {cwd: false}));114115/* eslint-disable @typescript-eslint/naming-convention */115/* eslint-disable @typescript-eslint/naming-convention -- `PATH` is a real environment variable name */116await execa('unicorns', {env: {PATH: ''}});117execaSync('unicorns', {env: {PATH: ''}});118const env: Record<string, string> = {PATH: ''};119await execa('unicorns', {env});
3 unmodified lines
123expectError(execaSync('unicorns', {env: false}));124125await execa('unicorns', {argv0: ''});126execaSync('unicorns', {argv0: ''});127await execa('unicorns', {argv0: '' as string});128execaSync('unicorns', {argv0: '' as string});127await execa('unicorns', {argv0: ''});128execaSync('unicorns', {argv0: ''});129expectError(await execa('unicorns', {argv0: false}));130expectError(execaSync('unicorns', {argv0: false}));131132await execa('unicorns', {uid: 0});133execaSync('unicorns', {uid: 0});134await execa('unicorns', {uid: 0 as number});135execaSync('unicorns', {uid: 0 as number});134await execa('unicorns', {uid: 0});135execaSync('unicorns', {uid: 0});136expectError(await execa('unicorns', {uid: '0'}));137expectError(execaSync('unicorns', {uid: '0'}));138139await execa('unicorns', {gid: 0});140execaSync('unicorns', {gid: 0});141await execa('unicorns', {gid: 0 as number});142execaSync('unicorns', {gid: 0 as number});141await execa('unicorns', {gid: 0});142execaSync('unicorns', {gid: 0});143expectError(await execa('unicorns', {gid: '0'}));144expectError(execaSync('unicorns', {gid: '0'}));145146await execa('unicorns', {shell: true});
1 unmodified line
148await execa('unicorns', {shell: true as boolean});149execaSync('unicorns', {shell: true as boolean});150await execa('unicorns', {shell: '/bin/sh'});151execaSync('unicorns', {shell: '/bin/sh'});152await execa('unicorns', {shell: '/bin/sh' as string});153execaSync('unicorns', {shell: '/bin/sh' as string});152await execa('unicorns', {shell: '/bin/sh'});153execaSync('unicorns', {shell: '/bin/sh'});154await execa('unicorns', {shell: fileUrl});155execaSync('unicorns', {shell: fileUrl});156expectError(await execa('unicorns', {shell: {}}));157expectError(execaSync('unicorns', {shell: {}}));158159await execa('unicorns', {timeout: 1000});160execaSync('unicorns', {timeout: 1000});161await execa('unicorns', {timeout: 1000 as number});162execaSync('unicorns', {timeout: 1000 as number});161await execa('unicorns', {timeout: 1000});162execaSync('unicorns', {timeout: 1000});163expectError(await execa('unicorns', {timeout: '1000'}));164expectError(execaSync('unicorns', {timeout: '1000'}));165166await execa('unicorns', {maxBuffer: 1000});167execaSync('unicorns', {maxBuffer: 1000});168await execa('unicorns', {maxBuffer: 1000 as number});169execaSync('unicorns', {maxBuffer: 1000 as number});168await execa('unicorns', {maxBuffer: 1000});169execaSync('unicorns', {maxBuffer: 1000});170expectError(await execa('unicorns', {maxBuffer: '1000'}));171expectError(execaSync('unicorns', {maxBuffer: '1000'}));172173await execa('unicorns', {killSignal: 'SIGTERM'});
1 unmodified line
175expectError(await execa('unicorns', {killSignal: 'SIGTERM' as string}));176expectError(execaSync('unicorns', {killSignal: 'SIGTERM' as string}));177await execa('unicorns', {killSignal: 9});178execaSync('unicorns', {killSignal: 9});179await execa('unicorns', {killSignal: 9 as number});180execaSync('unicorns', {killSignal: 9 as number});179await execa('unicorns', {killSignal: 9});180execaSync('unicorns', {killSignal: 9});181expectError(await execa('unicorns', {killSignal: false}));182expectError(execaSync('unicorns', {killSignal: false}));183expectError(await execa('unicorns', {killSignal: 'Sigterm'}));184expectError(execaSync('unicorns', {killSignal: 'Sigterm'}));
104 unmodified lines
modified:test-d/arguments/specific.test-d.ts+10 added
7 unmodified lines
8await execa('unicorns', {maxBuffer: {stdout: 0, stderr: 0} as const});9await execa('unicorns', {maxBuffer: {all: 0}});10await execa('unicorns', {maxBuffer: {fd1: 0}});11await execa('unicorns', {maxBuffer: {fd2: 0}});12await execa('unicorns', {maxBuffer: {fd3: 0}});13await execa('unicorns', {maxBuffer: {fd3: 0}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});14await execa('unicorns', {maxBuffer: {ipc: 0}});15expectError(await execa('unicorns', {maxBuffer: {stdout: '0'}}));16
4 unmodified lines
21execaSync('unicorns', {maxBuffer: {stdout: 0, stderr: 0} as const});22execaSync('unicorns', {maxBuffer: {all: 0}});23execaSync('unicorns', {maxBuffer: {fd1: 0}});24execaSync('unicorns', {maxBuffer: {fd2: 0}});25execaSync('unicorns', {maxBuffer: {fd3: 0}});26execaSync('unicorns', {maxBuffer: {fd3: 0}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});27execaSync('unicorns', {maxBuffer: {ipc: 0}});28expectError(execaSync('unicorns', {maxBuffer: {stdout: '0'}}));29
4 unmodified lines
34await execa('unicorns', {verbose: {stdout: 'none', stderr: 'none'} as const});35await execa('unicorns', {verbose: {all: 'none'}});36await execa('unicorns', {verbose: {fd1: 'none'}});37await execa('unicorns', {verbose: {fd2: 'none'}});38await execa('unicorns', {verbose: {fd3: 'none'}});39await execa('unicorns', {verbose: {fd3: 'none'}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});40await execa('unicorns', {verbose: {ipc: 'none'}});41expectError(await execa('unicorns', {verbose: {stdout: 'other'}}));42
4 unmodified lines
47execaSync('unicorns', {verbose: {stdout: 'none', stderr: 'none'} as const});48execaSync('unicorns', {verbose: {all: 'none'}});49execaSync('unicorns', {verbose: {fd1: 'none'}});50execaSync('unicorns', {verbose: {fd2: 'none'}});51execaSync('unicorns', {verbose: {fd3: 'none'}});52execaSync('unicorns', {verbose: {fd3: 'none'}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});53execaSync('unicorns', {verbose: {ipc: 'none'}});54expectError(execaSync('unicorns', {verbose: {stdout: 'other'}}));55
4 unmodified lines
60await execa('unicorns', {stripFinalNewline: {stdout: true, stderr: true} as const});61await execa('unicorns', {stripFinalNewline: {all: true}});62await execa('unicorns', {stripFinalNewline: {fd1: true}});63await execa('unicorns', {stripFinalNewline: {fd2: true}});64await execa('unicorns', {stripFinalNewline: {fd3: true}});65await execa('unicorns', {stripFinalNewline: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});66await execa('unicorns', {stripFinalNewline: {ipc: true}});67expectError(await execa('unicorns', {stripFinalNewline: {stdout: 'true'}}));68
4 unmodified lines
73execaSync('unicorns', {stripFinalNewline: {stdout: true, stderr: true} as const});74execaSync('unicorns', {stripFinalNewline: {all: true}});75execaSync('unicorns', {stripFinalNewline: {fd1: true}});76execaSync('unicorns', {stripFinalNewline: {fd2: true}});77execaSync('unicorns', {stripFinalNewline: {fd3: true}});78execaSync('unicorns', {stripFinalNewline: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});79execaSync('unicorns', {stripFinalNewline: {ipc: true}});80expectError(execaSync('unicorns', {stripFinalNewline: {stdout: 'true'}}));81
4 unmodified lines
86await execa('unicorns', {lines: {stdout: true, stderr: true} as const});87await execa('unicorns', {lines: {all: true}});88await execa('unicorns', {lines: {fd1: true}});89await execa('unicorns', {lines: {fd2: true}});90await execa('unicorns', {lines: {fd3: true}});91await execa('unicorns', {lines: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});92await execa('unicorns', {lines: {ipc: true}});93expectError(await execa('unicorns', {lines: {stdout: 'true'}}));94
4 unmodified lines
99execaSync('unicorns', {lines: {stdout: true, stderr: true} as const});100execaSync('unicorns', {lines: {all: true}});101execaSync('unicorns', {lines: {fd1: true}});102execaSync('unicorns', {lines: {fd2: true}});103execaSync('unicorns', {lines: {fd3: true}});104execaSync('unicorns', {lines: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});105execaSync('unicorns', {lines: {ipc: true}});106expectError(execaSync('unicorns', {lines: {stdout: 'true'}}));107
4 unmodified lines
112await execa('unicorns', {buffer: {stdout: true, stderr: true} as const});113await execa('unicorns', {buffer: {all: true}});114await execa('unicorns', {buffer: {fd1: true}});115await execa('unicorns', {buffer: {fd2: true}});116await execa('unicorns', {buffer: {fd3: true}});117await execa('unicorns', {buffer: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});118await execa('unicorns', {buffer: {ipc: true}});119expectError(await execa('unicorns', {buffer: {stdout: 'true'}}));120
4 unmodified lines
125execaSync('unicorns', {buffer: {stdout: true, stderr: true} as const});126execaSync('unicorns', {buffer: {all: true}});127execaSync('unicorns', {buffer: {fd1: true}});128execaSync('unicorns', {buffer: {fd2: true}});129execaSync('unicorns', {buffer: {fd3: true}});130execaSync('unicorns', {buffer: {fd3: true}, stdio: ['pipe', 'pipe', 'pipe', 'pipe']});131execaSync('unicorns', {buffer: {ipc: true}});132expectError(execaSync('unicorns', {buffer: {stdout: 'true'}}));133
36 unmodified lines
modified:test-d/ipc/message.test-d.ts+8 added-8 removed
60 unmodified lines
61expectAssignable<Message>(null);62expectAssignable<Message<'advanced'>>(null);63expectAssignable<Message<'json'>>(null);6465await sendMessage(Number.NaN);66expectAssignable<Message>(Number.NaN);67expectAssignable<Message<'advanced'>>(Number.NaN);68expectAssignable<Message<'json'>>(Number.NaN);65await sendMessage(NaN);66expectAssignable<Message>(NaN);67expectAssignable<Message<'advanced'>>(NaN);68expectAssignable<Message<'json'>>(NaN);6970await sendMessage(Number.POSITIVE_INFINITY);71expectAssignable<Message>(Number.POSITIVE_INFINITY);72expectAssignable<Message<'advanced'>>(Number.POSITIVE_INFINITY);73expectAssignable<Message<'json'>>(Number.POSITIVE_INFINITY);70await sendMessage(Infinity);71expectAssignable<Message>(Infinity);72expectAssignable<Message<'advanced'>>(Infinity);73expectAssignable<Message<'json'>>(Infinity);7475await sendMessage(new Map());76expectAssignable<Message>(new Map());77expectAssignable<Message<'advanced'>>(new Map());
56 unmodified lines
modified:test-d/stdio/option/fd-integer-0.test-d.ts+4 added-4 removed
36 unmodified lines
37expectAssignable<StdinSyncOption>([0]);3839expectNotAssignable<StdinOption>(0.5);40expectNotAssignable<StdinSyncOption>(-1);41expectNotAssignable<StdinOption>(Number.POSITIVE_INFINITY);42expectNotAssignable<StdinSyncOption>(Number.NaN);41expectNotAssignable<StdinOption>(Infinity);42expectNotAssignable<StdinSyncOption>(NaN);4344expectNotAssignable<StdoutStderrOption>(0);45expectNotAssignable<StdoutStderrSyncOption>(0);46expectNotAssignable<StdoutStderrOption>([0]);47expectNotAssignable<StdoutStderrSyncOption>([0]);4849expectNotAssignable<StdoutStderrOption>(0.5);50expectNotAssignable<StdoutStderrSyncOption>(-1);51expectNotAssignable<StdoutStderrOption>(Number.POSITIVE_INFINITY);52expectNotAssignable<StdoutStderrSyncOption>(Number.NaN);51expectNotAssignable<StdoutStderrOption>(Infinity);52expectNotAssignable<StdoutStderrSyncOption>(NaN);
modified:types/arguments/encoding-option.d.ts+8 added-8 removed
1type DefaultEncodingOption = 'utf8';2type TextEncodingOption =3 | DefaultEncodingOption4 | 'utf16le';3 | DefaultEncodingOption4 | 'utf16le';56export type BufferEncodingOption = 'buffer';7export type BinaryEncodingOption =8 | BufferEncodingOption9 | 'hex'10 | 'base64'11 | 'base64url'12 | 'latin1'13 | 'ascii';8 | BufferEncodingOption9 | 'hex'10 | 'base64'11 | 'base64url'12 | 'latin1'13 | 'ascii';1415// `options.encoding`16export type EncodingOption =17 | TextEncodingOption
4 unmodified lines
modified:types/arguments/options.d.ts+1 added-1 removed
148 unmodified lines
149 If the subprocess outputs text, specifies its character encoding, either [`'utf8'`](https://en.wikipedia.org/wiki/UTF-8) or [`'utf16le'`](https://en.wikipedia.org/wiki/UTF-16).150151 If it outputs binary data instead, this should be either:152 - `'buffer'`: returns the binary output as an `Uint8Array`.153 - [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#URL_applications), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.153 - [`'hex'`](https://en.wikipedia.org/wiki/Hexadecimal), [`'base64'`](https://en.wikipedia.org/wiki/Base64), [`'base64url'`](https://en.wikipedia.org/wiki/Base64#RFC_4648), [`'latin1'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings) or [`'ascii'`](https://nodejs.org/api/buffer.html#buffers-and-character-encodings): encodes the binary output as a string.154155 The output is available with `result.stdout`, `result.stderr` and `result.stdio`.156157 @default 'utf8'
245 unmodified lines
modified:types/arguments/specific.d.ts+1 added-3 removed
1 unmodified line
23// Options which can be fd-specific like `{verbose: {stdout: 'none', stderr: 'full'}}`4export type FdGenericOption<OptionType> = OptionType | GenericOptionObject<OptionType>;56type GenericOptionObject<OptionType> = {7 readonly [FdName in GenericFromOption]?: OptionType8};6type GenericOptionObject<OptionType> = Readonly<Partial<Record<GenericFromOption, OptionType>>>;78type GenericFromOption = FromOption | 'ipc';910// Retrieve fd-specific option's value
44 unmodified lines
modified:types/return/final-error.d.ts+7 added-7 removed
18 unmodified lines
19> = NonNullable<CommonResult<IsSync, OptionsType>[PropertyName]>;2021// `result.*` defined only on failure, i.e. on `error.*`22export type ErrorProperties =23 | 'name'24 | 'message'25 | 'stack'26 | 'cause'27 | 'shortMessage'28 | 'originalMessage'29 | 'code';23 | 'name'24 | 'message'25 | 'stack'26 | 'cause'27 | 'shortMessage'28 | 'originalMessage'29 | 'code';3031/**32Result of a subprocess failed execution.33
20 unmodified lines
modified:types/return/result-all.d.ts+4 added-4 removed
11 unmodified lines
12 AllOption extends CommonOptions['all'],13 OptionsType extends CommonOptions,14> = AllOption extends true15 ? ResultStdio<16 AllMainFd<OptionsType>,17 AllObjectFd<OptionsType>,18 AllLinesFd<OptionsType>,19 OptionsType16 AllMainFd<OptionsType>,17 AllObjectFd<OptionsType>,18 AllLinesFd<OptionsType>,19 OptionsType20 >21 : undefined;2223type AllMainFd<OptionsType extends CommonOptions> =
9 unmodified lines
modified:types/return/result-ipc.d.ts+3 added-3 removed
9 unmodified lines
10 OptionsType extends CommonOptions,11> = IsSync extends true12 ? []13 : ResultIpcAsync<14 FdSpecificOption<OptionsType['buffer'], 'ipc'>,15 HasIpc<StricterOptions<OptionsType, Options>>,16 OptionsType['serialization']14 FdSpecificOption<OptionsType['buffer'], 'ipc'>,15 HasIpc<StricterOptions<OptionsType, Options>>,16 OptionsType['serialization']17 >;1819type ResultIpcAsync<20 BufferOption extends boolean | undefined,
9 unmodified lines
modified:types/return/result-stdio.d.ts+2 added-2 removed
9 unmodified lines
10 StdioOptionsArrayType,11 OptionsType extends CommonOptions,12> = {13 -readonly [FdNumber in keyof StdioOptionsArrayType]: ResultStdioNotAll<14 FdNumber extends string ? FdNumber : string,15 OptionsType14 FdNumber extends string ? FdNumber : string,15 OptionsType16 >17};1819export {};
modified:types/return/result-stdout.d.ts+7 added-7 removed
15 unmodified lines
16 ObjectFdNumber extends string,17 LinesFdNumber extends string,18 OptionsType extends CommonOptions,19> = ResultStdioProperty<20ObjectFdNumber,21LinesFdNumber,22IgnoresResultOutput<MainFdNumber, OptionsType>,23OptionsType20 ObjectFdNumber,21 LinesFdNumber,22 IgnoresResultOutput<MainFdNumber, OptionsType>,23 OptionsType24>;2526type ResultStdioProperty<27 ObjectFdNumber extends string,
2 unmodified lines
30 OptionsType extends CommonOptions,31> = StreamOutputIgnored extends true32 ? undefined33 : ResultStdioItem<34 IsObjectFd<ObjectFdNumber, OptionsType>,35 FdSpecificOption<OptionsType['lines'], LinesFdNumber>,36 OptionsType['encoding']34 IsObjectFd<ObjectFdNumber, OptionsType>,35 FdSpecificOption<OptionsType['lines'], LinesFdNumber>,36 OptionsType['encoding']37 >;3839type ResultStdioItem<40 IsObjectResult,
12 unmodified lines
modified:types/return/result.d.ts+1 added-3 removed
182 unmodified lines
183 IsSync extends boolean = boolean,184 OptionsType extends CommonOptions = CommonOptions,185> = InstanceType<typeof CommonResult<IsSync, OptionsType>> & OmitErrorIfReject<OptionsType['reject']>;186187type OmitErrorIfReject<RejectOption extends CommonOptions['reject']> = {188 [ErrorProperty in ErrorProperties]: RejectOption extends false ? unknown : never189};187type OmitErrorIfReject<RejectOption extends CommonOptions['reject']> = Record<ErrorProperties, RejectOption extends false ? unknown : never>;188189/**190Result of a subprocess successful execution.191
12 unmodified lines
modified:types/stdio/type.d.ts+6 added-13 removed
45 unmodified lines
46 IsSync extends boolean,47 IsExtra extends boolean,48 IsArray extends boolean,49> =50 | SimpleStdioOption<IsSync, IsExtra, IsArray>51 | URL52 | {readonly file: string; readonly append?: boolean}53 | GeneratorTransform<IsSync>54 | GeneratorTransformFull<IsSync>55 | Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9>56 | Unless<Or<IsSync, IsArray>, 'ipc'>57 | Unless<IsSync, DuplexTransform | WebTransform | TransformStream>;50 SimpleStdioOption<IsSync, IsExtra, IsArray> | URL | GeneratorTransform<IsSync> | GeneratorTransformFull<IsSync> | Unless<And<Not<IsSync>, IsArray>, 3 | 4 | 5 | 6 | 7 | 8 | 9> | Unless<Or<IsSync, IsArray>, 'ipc'> | Unless<IsSync, DuplexTransform | WebTransform | TransformStream> | {readonly file: string; readonly append?: boolean};5152// Synchronous iterables excluding strings, Uint8Arrays and Arrays53type IterableObject<IsArray extends boolean> = Iterable<unknown>61& object62& {readonly BYTES_PER_ELEMENT?: never}63& AndUnless<IsArray, {readonly lastIndexOf?: never}>;54 & object55 & AndUnless<IsArray, {readonly lastIndexOf?: never}>56 & {readonly BYTES_PER_ELEMENT?: never};5758// `process.stdin|stdout|stderr` are `Duplex` with a `fd` property.59// This ensures they can only be passed to `stdin`/`stdout`/`stderr`, based on their direction.60type ProcessStdinFd = {readonly fd?: 0};
47 unmodified lines
108 IsSync extends boolean,109 IsExtra extends boolean,110 IsArray extends boolean,111> =119 | CommonStdioOption<IsSync, IsExtra, IsArray>120 | OutputStdioOption<IsSync, IsArray>;112 | CommonStdioOption<IsSync, IsExtra, IsArray>113 | OutputStdioOption<IsSync, IsArray>;114115// `options.stdout|stderr`116export type StdoutStderrOptionCommon<117 IsSync extends boolean = boolean,
48 unmodified lines
modified:types/subprocess/subprocess.d.ts+64 added-63 removed
13 unmodified lines
14import type {SubprocessStdioStream} from './stdout.js';15import type {SubprocessStdioArray} from './stdio.js';16import type {SubprocessAll} from './all.js';1718type ExecaCustomSubprocess<OptionsType extends Options> = {19 /**20 Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).18type ExecaCustomSubprocess<OptionsType extends Options> =19 & IpcMethods<HasIpc<OptionsType>, OptionsType['serialization']>20 & PipableSubprocess21 & {22 /**23 Process identifier ([PID](https://en.wikipedia.org/wiki/Process_identifier)).2422 This is `undefined` if the subprocess failed to spawn.23 */24 pid?: number;25 This is `undefined` if the subprocess failed to spawn.26 */27 pid?: number;2826 /**27 The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.29 /**30 The subprocess [`stdin`](https://en.wikipedia.org/wiki/Standard_streams#Standard_input_(stdin)) as a stream.3129 This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.30 */31 stdin: SubprocessStdioStream<'0', OptionsType>;32 This is `null` if the `stdin` option is set to `'inherit'`, `'ignore'`, `Readable` or `integer`.33 */34 stdin: SubprocessStdioStream<'0', OptionsType>;3533 /**34 The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.36 /**37 The subprocess [`stdout`](https://en.wikipedia.org/wiki/Standard_streams#Standard_output_(stdout)) as a stream.3836 This is `null` if the `stdout` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.37 */38 stdout: SubprocessStdioStream<'1', OptionsType>;39 This is `null` if the `stdout` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.40 */41 stdout: SubprocessStdioStream<'1', OptionsType>;4240 /**41 The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.43 /**44 The subprocess [`stderr`](https://en.wikipedia.org/wiki/Standard_streams#Standard_error_(stderr)) as a stream.4543 This is `null` if the `stderr` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.44 */45 stderr: SubprocessStdioStream<'2', OptionsType>;46 This is `null` if the `stderr` option is set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.47 */48 stderr: SubprocessStdioStream<'2', OptionsType>;4947 /**48 Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.50 /**51 Stream combining/interleaving `subprocess.stdout` and `subprocess.stderr`.5250 This requires the `all` option to be `true`.53 This requires the `all` option to be `true`.5452 This is `undefined` if `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.53 */54 all: SubprocessAll<OptionsType>;55 This is `undefined` if `stdout` and `stderr` options are set to `'inherit'`, `'ignore'`, `Writable` or `integer`, or if the `buffer` option is `false`.56 */57 all: SubprocessAll<OptionsType>;5856 /**57 The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.59 /**60 The subprocess `stdin`, `stdout`, `stderr` and other files descriptors as an array of streams.6159 Each array item is `null` if the corresponding `stdin`, `stdout`, `stderr` or `stdio` option is set to `'inherit'`, `'ignore'`, `Stream` or `integer`, or if the `buffer` option is `false`.60 */61 stdio: SubprocessStdioArray<OptionsType>;62 Each array item is `null` if the corresponding `stdin`, `stdout`, `stderr` or `stdio` option is set to `'inherit'`, `'ignore'`, `Stream` or `integer`, or if the `buffer` option is `false`.63 */64 stdio: SubprocessStdioArray<OptionsType>;6563 /**64 Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the `killSignal` option. `killSignal` defaults to `SIGTERM`, which terminates the subprocess.66 /**67 Sends a [signal](https://nodejs.org/api/os.html#signal-constants) to the subprocess. The default signal is the `killSignal` option. `killSignal` defaults to `SIGTERM`, which terminates the subprocess.6866 This returns `false` when the signal could not be sent, for example when the subprocess has already exited.69 This returns `false` when the signal could not be sent, for example when the subprocess has already exited.7068 When an error is passed as argument, it is set to the subprocess' `error.cause`. The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).71 When an error is passed as argument, it is set to the subprocess' `error.cause`. The subprocess is then terminated with the default signal. This does not emit the [`error` event](https://nodejs.org/api/child_process.html#event-error).7270 [More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)71 */72 kill(signal?: keyof SignalConstants | number, error?: Error): boolean;73 kill(error?: Error): boolean;73 [More info.](https://nodejs.org/api/child_process.html#subprocesskillsignal)74 */75 kill(signal?: keyof SignalConstants | number, error?: Error): boolean;76 kill(error?: Error): boolean;7775 /**76 Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.77 */78 [Symbol.asyncIterator](): SubprocessAsyncIterable<undefined, OptionsType['encoding']>;78 /**79 Subprocesses are [async iterables](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator). They iterate over each output line.80 */81 [Symbol.asyncIterator](): SubprocessAsyncIterable<undefined, OptionsType['encoding']>;8280 /**81 Same as `subprocess[Symbol.asyncIterator]` except options can be provided.82 */83 iterable<IterableOptions extends ReadableOptions = {}>(readableOptions?: IterableOptions): SubprocessAsyncIterable<IterableOptions['binary'], OptionsType['encoding']>;83 /**84 Same as `subprocess[Symbol.asyncIterator]` except options can be provided.85 */86 iterable<IterableOptions extends ReadableOptions = {}>(readableOptions?: IterableOptions): SubprocessAsyncIterable<IterableOptions['binary'], OptionsType['encoding']>;8785 /**86 Converts the subprocess to a readable stream.87 */88 readable(readableOptions?: ReadableOptions): Readable;88 /**89 Converts the subprocess to a readable stream.90 */91 readable(readableOptions?: ReadableOptions): Readable;9290 /**91 Converts the subprocess to a writable stream.92 */93 writable(writableOptions?: WritableOptions): Writable;93 /**94 Converts the subprocess to a writable stream.95 */96 writable(writableOptions?: WritableOptions): Writable;9795 /**96 Converts the subprocess to a duplex stream.97 */98 duplex(duplexOptions?: DuplexOptions): Duplex;99}100& IpcMethods<HasIpc<OptionsType>, OptionsType['serialization']>101& PipableSubprocess;98 /**99 Converts the subprocess to a duplex stream.100 */101 duplex(duplexOptions?: DuplexOptions): Duplex;102 };103104/**105[`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with additional methods and properties.106*/
14 unmodified lines
modified:types/transform/normalize.d.ts+10 added-10 removed
4 unmodified lines
5// `options.std*: Generator`6// @todo Use `string`, `Uint8Array` or `unknown` for both the argument and the return type, based on whether `encoding: 'buffer'` and `objectMode: true` are used.7// See https://github.com/sindresorhus/execa/issues/6948export type GeneratorTransform<IsSync extends boolean> = (chunk: unknown) =>9| Unless<IsSync, AsyncGenerator<unknown, void, void>>10| Generator<unknown, void, void>;9 | Unless<IsSync, AsyncGenerator<unknown, void, void>>10 | Generator<unknown, void, void>;11type GeneratorFinal<IsSync extends boolean> = () =>12| Unless<IsSync, AsyncGenerator<unknown, void, void>>13| Generator<unknown, void, void>;12 | Unless<IsSync, AsyncGenerator<unknown, void, void>>13 | Generator<unknown, void, void>;1415export type TransformCommon = {16 /**17 If `true`, allow `transformOptions.transform` and `transformOptions.final` to return any type, not just `string` or `Uint8Array`.
5 unmodified lines
23A transform or an array of transforms can be passed to the `stdin`, `stdout`, `stderr` or `stdio` option.2425A transform is either a generator function or a plain object with the following members.26*/27export type GeneratorTransformFull<IsSync extends boolean> = {27export type GeneratorTransformFull<IsSync extends boolean> = TransformCommon & {28 /**29 Map or filter the input or output of the subprocess.30 */31 readonly transform: GeneratorTransform<IsSync>;
11 unmodified lines
43 /**44 If `true`, keep newlines in each `line` argument. Also, this allows multiple `yield`s to produces a single line.45 */46 readonly preserveNewlines?: boolean;47} & TransformCommon;47};4849// `options.std*: Duplex`50export type DuplexTransform = {50export type DuplexTransform = TransformCommon & {51 readonly transform: Duplex;52} & TransformCommon;52};5354// `options.std*: TransformStream`55export type WebTransform = {55export type WebTransform = TransformCommon & {56 readonly transform: TransformStream;57} & TransformCommon;57};5859export {};
modified:types/convert.d.ts+4 added-4 removed
48 unmodified lines
49export type SubprocessAsyncIterable<50 BinaryOption extends boolean | undefined,51 EncodingOption extends Options['encoding'],52> = AsyncIterableIterator<53EncodingOption extends BinaryEncodingOption54 ? Uint8Array55 : BinaryOption extends true53 EncodingOption extends BinaryEncodingOption54 ? Uint8Array55 : BinaryOption extends true56 ? Uint8Array57 : string57 : string58>;5960export {};
modified:types/ipc.d.ts+3 added-3 removed
134 unmodified lines
135 };136137// Whether IPC is enabled, based on the `ipc`, `ipcInput` and `gracefulCancel` options138export type HasIpc<OptionsType extends Options> = HasIpcOption<139OptionsType['ipc'],140'ipcInput' extends keyof OptionsType ? OptionsType['ipcInput'] : undefined,141'gracefulCancel' extends keyof OptionsType ? OptionsType['gracefulCancel'] : undefined139 OptionsType['ipc'],140 'ipcInput' extends keyof OptionsType ? OptionsType['ipcInput'] : undefined,141 'gracefulCancel' extends keyof OptionsType ? OptionsType['gracefulCancel'] : undefined142>;143144type HasIpcOption<145 IpcOption extends Options['ipc'],
13 unmodified lines
modified:types/verbose.d.ts+4 added-4 removed
1 unmodified line
2import type {Options, SyncOptions} from './arguments/options.js';3import type {Result, SyncResult} from './return/result.js';45export type VerboseOption = FdGenericOption<6| 'none'7| 'short'8| 'full'9| VerboseFunction6 | 'none'7 | 'short'8 | 'full'9 | VerboseFunction10>;1112type VerboseFunction = (verboseLine: string, verboseObject: MinimalVerboseObject) => string | void;13
87 unmodified lines
modified:.gitignore+1 added
1node_modules2yarn.lock3.nyc_output4coverage5lychee
modified:package.json+42 added-16 removed
15 unmodified lines
16 "default": "./index.js"17 },18 "sideEffects": false,19 "engines": {20 "node": "^18.19.0 || >=20.5.0"20 "node": ">=22"21 },22 "scripts": {23 "test": "npm run lint && npm run unit && npm run type",24 "lint": "xo",25 "unit": "c8 --merge-async ava",26 "type": "tsd && tsc && npx --yes tsd@0.29.0 && npx --yes --package typescript@5.1 tsc"26 "type": "tsd && tsc"27 },28 "files": [29 "index.js",30 "index.d.ts",
22 unmodified lines
53 "dependencies": {54 "@sindresorhus/merge-streams": "^4.0.0",55 "cross-spawn": "^7.0.6",56 "figures": "^6.1.0",57 "get-stream": "^9.0.0",57 "get-stream": "^9.0.1",58 "human-signals": "^8.0.1",59 "is-plain-obj": "^4.1.0",60 "is-stream": "^4.0.1",61 "npm-run-path": "^6.0.0",62 "pretty-ms": "^9.2.0",62 "pretty-ms": "^9.3.0",63 "signal-exit": "^4.1.0",64 "strip-final-newline": "^4.0.0",65 "yoctocolors": "^2.1.1"65 "yoctocolors": "^2.1.2"66 },67 "devDependencies": {68 "@types/node": "^22.15.21",69 "ava": "^6.3.0",70 "c8": "^10.1.3",71 "get-node": "^15.0.3",72 "is-in-ci": "^1.0.0",68 "@types/node": "^26.1.0",69 "ava": "^8.0.1",70 "c8": "^11.0.0",71 "get-node": "^15.0.4",72 "is-in-ci": "^2.0.0",73 "is-running": "^2.1.0",74 "log-process-errors": "^12.0.1",75 "path-exists": "^5.0.0",76 "path-key": "^4.0.0",77 "tempfile": "^5.0.0",78 "tsd": "^0.32.0",79 "typescript": "^5.8.3",80 "which": "^5.0.0",81 "xo": "^0.60.0"77 "tempfile": "^6.0.1",78 "tsd": "^0.33.0",79 "typescript": "^6.0.3",80 "which": "^7.0.0",81 "xo": "^3.0.2"82 },83 "c8": {84 "reporter": [85 "text",
12 unmodified lines
98 },99 "xo": {100 "rules": {101 "unicorn/no-empty-file": "off",102 "unicorn/prefer-string-raw": "off",103 "ava/test-title": "off",104 "@typescript-eslint/no-empty-object-type": "off",105 "unicorn/no-useless-template-literals": "off",106 "require-unicode-regexp": "off",107 "ava/no-nested-assertions": "off",108 "@stylistic/max-len": "off",109 "@typescript-eslint/no-unsafe-call": "off",110 "@typescript-eslint/no-unsafe-member-access": "off",111 "@typescript-eslint/no-unsafe-assignment": "off",112 "@typescript-eslint/await-thenable": "off",113 "@typescript-eslint/no-unnecessary-type-assertion": "off",114 "@typescript-eslint/no-restricted-types": "off",115 "no-shadow": "off",116 "unicorn/no-computed-property-existence-check": "off",117 "unicorn/max-nested-calls": "off",118 "markdown/fenced-code-language": "off",119 "unicorn/no-array-sort": "off",120 "unicorn/prefer-minimal-ternary": "off",121 "unicorn/no-array-reverse": "off",122 "unicorn/no-array-from-fill": "off",123 "unicorn/prefer-number-is-safe-integer": "off",124 "unicorn/require-array-sort-compare": "off",102 "@typescript-eslint/ban-types": "off"125 "@typescript-eslint/ban-types": "off",126 "regexp/strict": "off",127 "unicorn/require-module-specifiers": "off",128 "jsdoc/require-asterisk-prefix": "off"129 }130 }131}
modified:tsconfig.json+2 added-1 removed
1 unmodified line
2 "compilerOptions": {3 "module": "nodenext",4 "moduleResolution": "nodenext",5 "target": "ES2022",6 "strict": true6 "strict": true,7 "types": ["node"]8 },9 "files": [10 "index.d.ts"11 ]
1 unmodified line