Skip to content
Myr

Upgrade xo (#980)

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

authored by ehmicky · committed by GitHub · parent 0bd0f0d · Browse files · 193 files+1505 added−686 removed
This commit

State

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

Diff stats

193 files+1505 added−686 removed

  • tests:+741 added−493 removed
  • other:+764 added−193 removed

193 files+1505 added−686 removed

modified:lib/arguments/command.js+8 added-3 removed
modified:lib/arguments/escape.js+11 added-9 removed
modified:lib/arguments/options.js+15 added-9 removed
modified:lib/convert/duplex.js+28 added-4 removed
19 unmodified lines
20 const binary = binaryOption || BINARY_ENCODINGS.has(encoding);21 const {subprocessStdout, waitReadableDestroy} = getSubprocessStdout(subprocess, from, concurrentStreams);22 const {subprocessStdin, waitWritableFinal, waitWritableDestroy} = getSubprocessStdin(subprocess, to, concurrentStreams);23 const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary);24 const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, encoding, preserveNewlines});24 const {read, onStdoutDataDone} = getReadableMethods({25 subprocessStdout,26 subprocess,27 binary,28 encoding,29 preserveNewlines,30 });31 const duplex = new Duplex({32 read,33 ...getWritableMethods(subprocessStdin, subprocess, waitWritableFinal),28 destroy: callbackify(onDuplexDestroy.bind(undefined, {subprocessStdout, subprocessStdin, subprocess, waitReadableDestroy, waitWritableFinal, waitWritableDestroy})),34 destroy: callbackify(onDuplexDestroy.bind(undefined, {35 subprocessStdout,36 subprocessStdin,37 subprocess,38 waitReadableDestroy,39 waitWritableFinal,40 waitWritableDestroy,41 })),42 readableHighWaterMark,43 writableHighWaterMark: subprocessStdin.writableHighWaterMark,44 readableObjectMode,45 writableObjectMode: subprocessStdin.writableObjectMode,46 encoding: readableEncoding,47 });35 onStdoutFinished({subprocessStdout, onStdoutDataDone, readable: duplex, subprocess, subprocessStdin});48 onStdoutFinished({49 subprocessStdout,50 onStdoutDataDone,51 readable: duplex,52 subprocess,53 subprocessStdin,54 });55 onStdinFinished(subprocessStdin, duplex, subprocessStdout);56 return duplex;57};5859const onDuplexDestroy = async ({subprocessStdout, subprocessStdin, subprocess, waitReadableDestroy, waitWritableFinal, waitWritableDestroy}, error) => {60 await Promise.all([61 onReadableDestroy({subprocessStdout, subprocess, waitReadableDestroy}, error),43 onWritableDestroy({subprocessStdin, subprocess, waitWritableFinal, waitWritableDestroy}, error),62 onWritableDestroy({63 subprocessStdin,64 subprocess,65 waitWritableFinal,66 waitWritableDestroy,67 }, error),68 ]);69};
modified:lib/convert/iterable.js+8 added-1 removed
modified:lib/convert/readable.js+21 added-3 removed
15 unmodified lines
16export const createReadable = ({subprocess, concurrentStreams, encoding}, {from, binary: binaryOption = true, preserveNewlines = true} = {}) => {17 const binary = binaryOption || BINARY_ENCODINGS.has(encoding);18 const {subprocessStdout, waitReadableDestroy} = getSubprocessStdout(subprocess, from, concurrentStreams);19 const {readableEncoding, readableObjectMode, readableHighWaterMark} = getReadableOptions(subprocessStdout, binary);20 const {read, onStdoutDataDone} = getReadableMethods({subprocessStdout, subprocess, binary, encoding, preserveNewlines});20 const {read, onStdoutDataDone} = getReadableMethods({21 subprocessStdout,22 subprocess,23 binary,24 encoding,25 preserveNewlines,26 });27 const readable = new Readable({28 read,29 destroy: callbackify(onReadableDestroy.bind(undefined, {subprocessStdout, subprocess, waitReadableDestroy})),30 highWaterMark: readableHighWaterMark,31 objectMode: readableObjectMode,32 encoding: readableEncoding,33 });28 onStdoutFinished({subprocessStdout, onStdoutDataDone, readable, subprocess});34 onStdoutFinished({35 subprocessStdout,36 onStdoutDataDone,37 readable,38 subprocess,39 });40 return readable;41};4243// Retrieve `stdout` (or other stream depending on `from`)
8 unmodified lines
52 : {readableEncoding, readableObjectMode: true, readableHighWaterMark: DEFAULT_OBJECT_HIGH_WATER_MARK};5354export const getReadableMethods = ({subprocessStdout, subprocess, binary, encoding, preserveNewlines}) => {55 const onStdoutDataDone = createDeferred();45 const onStdoutData = iterateOnSubprocessStream({subprocessStdout, subprocess, binary, shouldEncode: !binary, encoding, preserveNewlines});56 const onStdoutData = iterateOnSubprocessStream({57 subprocessStdout,58 subprocess,59 binary,60 shouldEncode: !binary,61 encoding,62 preserveNewlines,63 });6465 return {66 read() {67 onRead(this, onStdoutData, onStdoutDataDone);
46 unmodified lines
modified:lib/convert/writable.js+6 added-1 removed
12 unmodified lines
13export const createWritable = ({subprocess, concurrentStreams}, {to} = {}) => {14 const {subprocessStdin, waitWritableFinal, waitWritableDestroy} = getSubprocessStdin(subprocess, to, concurrentStreams);15 const writable = new Writable({16 ...getWritableMethods(subprocessStdin, subprocess, waitWritableFinal),17 destroy: callbackify(onWritableDestroy.bind(undefined, {subprocessStdin, subprocess, waitWritableFinal, waitWritableDestroy})),17 destroy: callbackify(onWritableDestroy.bind(undefined, {18 subprocessStdin,19 subprocess,20 waitWritableFinal,21 waitWritableDestroy,22 })),23 highWaterMark: subprocessStdin.writableHighWaterMark,24 objectMode: subprocessStdin.writableObjectMode,25 });26 onStdinFinished(subprocessStdin, writable);
64 unmodified lines
modified:lib/io/contents.js+38 added-5 removed
5 unmodified lines
6import {handleMaxBuffer} from './max-buffer.js';7import {getStripFinalNewline} from './strip-newline.js';89export const getStreamOutput = async ({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo: {fileDescriptors}}) => {10 if (shouldLogOutput({stdioItems: fileDescriptors[fdNumber]?.stdioItems, encoding, verboseInfo, fdNumber})) {11 const linesIterable = iterateForResult({stream, onStreamEnd, lines: true, encoding, stripFinalNewline: true, allMixed});10 if (shouldLogOutput({11 stdioItems: fileDescriptors[fdNumber]?.stdioItems,12 encoding,13 verboseInfo,14 fdNumber,15 })) {16 const linesIterable = iterateForResult({17 stream,18 onStreamEnd,19 lines: true,20 encoding,21 stripFinalNewline: true,22 allMixed,23 });24 logLines(linesIterable, stream, verboseInfo);25 }2627 if (!buffer) {
1 unmodified line
29 return;30 }3132 const stripFinalNewlineValue = getStripFinalNewline(stripFinalNewline, fdNumber);21 const iterable = iterateForResult({stream, onStreamEnd, lines, encoding, stripFinalNewline: stripFinalNewlineValue, allMixed});22 return getStreamContents({stream, iterable, fdNumber, encoding, maxBuffer, lines});33 const iterable = iterateForResult({34 stream,35 onStreamEnd,36 lines,37 encoding,38 stripFinalNewline: stripFinalNewlineValue,39 allMixed,40 });41 return getStreamContents({42 stream,43 iterable,44 fdNumber,45 encoding,46 maxBuffer,47 lines,48 });49};5051// When using `buffer: false`, users need to read `subprocess.stdout|stderr|all` right away52// See https://github.com/sindresorhus/execa/issues/730 and https://github.com/sindresorhus/execa/pull/729#discussion_r1465496310
15 unmodified lines
68 }6970 return await getStream(iterable, {maxBuffer});71 } catch (error) {46 return handleBufferedData(handleMaxBuffer({error, stream, readableObjectMode, lines, encoding, fdNumber}));72 return handleBufferedData(handleMaxBuffer({73 error,74 stream,75 readableObjectMode,76 lines,77 encoding,78 fdNumber,79 }));80 }81};8283// On failure, `result.stdout|stderr|all` should contain the currently buffered stream
13 unmodified lines
modified:lib/io/iterate.js+16 added-2 removed
60 unmodified lines
61 // See https://github.com/nodejs/node/pull/52080#discussion_r152522786162 // @todo Remove after removing support for Node 2163 highWatermark: HIGH_WATER_MARK,64 });65 return iterateOnData({onStdoutChunk, controller, binary, shouldEncode, encoding, shouldSplit, preserveNewlines});65 return iterateOnData({66 onStdoutChunk,67 controller,68 binary,69 shouldEncode,70 encoding,71 shouldSplit,72 preserveNewlines,73 });74};7576// @todo: replace with `getDefaultHighWaterMark(true)` after dropping support for Node <18.17.077export const DEFAULT_OBJECT_HIGH_WATER_MARK = 16;
4 unmodified lines
82// Note: this option does not exist on Node 18, but this is ok since the logic works without it. It just consumes more memory.83const HIGH_WATER_MARK = DEFAULT_OBJECT_HIGH_WATER_MARK;8485const iterateOnData = async function * ({onStdoutChunk, controller, binary, shouldEncode, encoding, shouldSplit, preserveNewlines}) {78 const generators = getGenerators({binary, shouldEncode, encoding, shouldSplit, preserveNewlines});86 const generators = getGenerators({87 binary,88 shouldEncode,89 encoding,90 shouldSplit,91 preserveNewlines,92 });9394 try {95 for await (const [chunk] of onStdoutChunk) {96 yield * transformChunkSync(chunk, generators, 0);
14 unmodified lines
modified:lib/io/output-async.js+8 added-1 removed
13 unmodified lines
14 pipeTransform(subprocess, stream, direction, fdNumber);15 }1617 for (const {stream} of stdioItems.filter(({type}) => !TRANSFORM_TYPES.has(type))) {18 pipeStdioItem({subprocess, stream, direction, fdNumber, inputStreamsGroups, controller});18 pipeStdioItem({19 subprocess,20 stream,21 direction,22 fdNumber,23 inputStreamsGroups,24 controller,25 });26 }27 }2829 for (const [fdNumber, inputStreams] of Object.entries(inputStreamsGroups)) {
49 unmodified lines
modified:lib/io/output-sync.js+22 added-6 removed
12 unmodified lines
13 }1415 const state = {};16 const transformedOutput = output.map((result, fdNumber) =>17 transformOutputResultSync({result, fileDescriptors, fdNumber, state, isMaxBuffer, verboseInfo}, options));17 transformOutputResultSync({18 result,19 fileDescriptors,20 fdNumber,21 state,22 isMaxBuffer,23 verboseInfo,24 }, options));25 return {output: transformedOutput, ...state};26};2728const transformOutputResultSync = ({result, fileDescriptors, fdNumber, state, isMaxBuffer, verboseInfo}, {buffer, encoding, lines, stripFinalNewline, maxBuffer}) => {
4 unmodified lines
33 const truncatedResult = truncateResult(result, isMaxBuffer, getMaxBufferSync(maxBuffer));34 const uint8ArrayResult = bufferToUint8Array(truncatedResult);35 const {stdioItems, objectMode} = fileDescriptors[fdNumber];36 const chunks = runOutputGeneratorsSync([uint8ArrayResult], stdioItems, encoding, state);30 const {31 serializedResult,32 finalResult = serializedResult,33 } = serializeChunks({chunks, objectMode, encoding, lines, stripFinalNewline, fdNumber});37 const {serializedResult, finalResult = serializedResult} = serializeChunks({38 chunks,39 objectMode,40 encoding,41 lines,42 stripFinalNewline,43 fdNumber,44 });4535 if (shouldLogOutput({stdioItems, encoding, verboseInfo, fdNumber})) {46 if (shouldLogOutput({47 stdioItems,48 encoding,49 verboseInfo,50 fdNumber,51 })) {52 const linesArray = splitLinesSync(serializedResult, false, objectMode);53 logLinesSync(linesArray, verboseInfo);54 }55
51 unmodified lines
modified:lib/methods/command.js+7 added-7 removed
1export const mapCommandAsync = ({file, args}) => parseCommand(file, args);2export const mapCommandSync = ({file, args}) => ({...parseCommand(file, args), isSync: true});1export const mapCommandAsync = ({file, commandArguments}) => parseCommand(file, commandArguments);2export const mapCommandSync = ({file, commandArguments}) => ({...parseCommand(file, commandArguments), isSync: true});34const parseCommand = (command, unusedArgs) => {5 if (unusedArgs.length > 0) {6 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArgs}.`);4const parseCommand = (command, unusedArguments) => {5 if (unusedArguments.length > 0) {6 throw new TypeError(`The command and its arguments must be passed as a single string: ${command} ${unusedArguments}.`);7 }89 const tokens = [];10 for (const token of command.trim().split(SPACES_REGEXP)) {
6 unmodified lines
17 tokens.push(token);18 }19 }2021 const [file, ...args] = tokens;22 return {file, args};21 const [file, ...commandArguments] = tokens;22 return {file, commandArguments};23};2425const SPACES_REGEXP = / +/g;
modified:lib/methods/create.js+27 added-10 removed
5 unmodified lines
6import {execaCoreAsync} from './main-async.js';78export const createExeca = (mapArguments, boundOptions, deepOptions, setBoundExeca) => {9 const createNested = (mapArguments, boundOptions, setBoundExeca) => createExeca(mapArguments, boundOptions, deepOptions, setBoundExeca);10 const boundExeca = (...args) => callBoundExeca({mapArguments, deepOptions, boundOptions, setBoundExeca, createNested}, ...args);10 const boundExeca = (...execaArguments) => callBoundExeca({11 mapArguments,12 deepOptions,13 boundOptions,14 setBoundExeca,15 createNested,16 }, ...execaArguments);1718 if (setBoundExeca !== undefined) {19 setBoundExeca(boundExeca, createNested, boundOptions);20 }
5 unmodified lines
26 if (isPlainObject(firstArgument)) {27 return createNested(mapArguments, mergeOptions(boundOptions, firstArgument), setBoundExeca);28 }2924 const {file, args, options, isSync} = parseArguments({mapArguments, firstArgument, nextArguments, deepOptions, boundOptions});30 const {file, commandArguments, options, isSync} = parseArguments({31 mapArguments,32 firstArgument,33 nextArguments,34 deepOptions,35 boundOptions,36 });37 return isSync26 ? execaCoreSync(file, args, options)27 : execaCoreAsync(file, args, options, createNested);38 ? execaCoreSync(file, commandArguments, options)39 : execaCoreAsync(file, commandArguments, options, createNested);40};4142const parseArguments = ({mapArguments, firstArgument, nextArguments, deepOptions, boundOptions}) => {43 const callArguments = isTemplateString(firstArgument)44 ? parseTemplates(firstArgument, nextArguments)45 : [firstArgument, ...nextArguments];34 const [rawFile, rawArgs, rawOptions] = normalizeParameters(...callArguments);35 const mergedOptions = mergeOptions(mergeOptions(deepOptions, boundOptions), rawOptions);46 const [initialFile, initialArguments, initialOptions] = normalizeParameters(...callArguments);47 const mergedOptions = mergeOptions(mergeOptions(deepOptions, boundOptions), initialOptions);48 const {37 file = rawFile,38 args = rawArgs,49 file = initialFile,50 commandArguments = initialArguments,51 options = mergedOptions,52 isSync = false,41 } = mapArguments({file: rawFile, args: rawArgs, options: mergedOptions});42 return {file, args, options, isSync};53 } = mapArguments({file: initialFile, commandArguments: initialArguments, options: mergedOptions});54 return {55 file,56 commandArguments,57 options,58 isSync,59 };60};6162// Deep merge specific options like `env`. Shallow merge the other ones.63const mergeOptions = (boundOptions, options) => {
18 unmodified lines
modified:lib/methods/main-async.js+88 added-21 removed
17 unmodified lines
18import {waitForSubprocessResult} from '../resolve/wait-subprocess.js';19import {addConvertedStreams} from '../convert/add.js';20import {mergePromise} from './promise.js';2122export const execaCoreAsync = (rawFile, rawArgs, rawOptions, createNested) => {23 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleAsyncArguments(rawFile, rawArgs, rawOptions);24 const {subprocess, promise} = spawnSubprocessAsync({file, args, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors});25 subprocess.pipe = pipeToSubprocess.bind(undefined, {source: subprocess, sourcePromise: promise, boundOptions: {}, createNested});22export const execaCoreAsync = (rawFile, rawArguments, rawOptions, createNested) => {23 const {file, commandArguments, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleAsyncArguments(rawFile, rawArguments, rawOptions);24 const {subprocess, promise} = spawnSubprocessAsync({25 file,26 commandArguments,27 options,28 startTime,29 verboseInfo,30 command,31 escapedCommand,32 fileDescriptors,33 });34 subprocess.pipe = pipeToSubprocess.bind(undefined, {35 source: subprocess,36 sourcePromise: promise,37 boundOptions: {},38 createNested,39 });40 mergePromise(subprocess, promise);41 SUBPROCESS_OPTIONS.set(subprocess, {options, fileDescriptors});42 return subprocess;43};4431const handleAsyncArguments = (rawFile, rawArgs, rawOptions) => {32 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);45const handleAsyncArguments = (rawFile, rawArguments, rawOptions) => {46 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArguments, rawOptions);4748 try {35 const {file, args, options: normalizedOptions} = handleOptions(rawFile, rawArgs, rawOptions);49 const {file, commandArguments, options: normalizedOptions} = handleOptions(rawFile, rawArguments, rawOptions);50 const options = handleAsyncOptions(normalizedOptions);51 const fileDescriptors = handleStdioAsync(options, verboseInfo);38 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};52 return {53 file,54 commandArguments,55 command,56 escapedCommand,57 startTime,58 verboseInfo,59 options,60 fileDescriptors,61 };62 } catch (error) {63 logEarlyResult(error, startTime, verboseInfo);64 throw error;65 }
7 unmodified lines
7374 return {...options, timeoutDuration: timeout, signal: cancelSignal};75};7654const spawnSubprocessAsync = ({file, args, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors}) => {77const spawnSubprocessAsync = ({file, commandArguments, options, startTime, verboseInfo, command, escapedCommand, fileDescriptors}) => {78 let subprocess;79 try {57 subprocess = spawn(file, args, options);80 subprocess = spawn(file, commandArguments, options);81 } catch (error) {59 return handleEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, verboseInfo});82 return handleEarlyError({83 error,84 command,85 escapedCommand,86 fileDescriptors,87 options,88 startTime,89 verboseInfo,90 });91 }9293 const controller = new AbortController();94 setMaxListeners(Number.POSITIVE_INFINITY, controller.signal);
1 unmodified line
96 const originalStreams = [...subprocess.stdio];97 pipeOutputAsync(subprocess, fileDescriptors, controller);98 cleanupOnExit(subprocess, options, controller);9969 subprocess.kill = subprocessKill.bind(undefined, {kill: subprocess.kill.bind(subprocess), subprocess, options, controller});100 subprocess.kill = subprocessKill.bind(undefined, {101 kill: subprocess.kill.bind(subprocess),102 subprocess,103 options,104 controller,105 });106 subprocess.all = makeAllStream(subprocess, options);107 addConvertedStreams(subprocess, options);10873 const promise = handlePromise({subprocess, options, startTime, verboseInfo, fileDescriptors, originalStreams, command, escapedCommand, controller});109 const promise = handlePromise({110 subprocess,111 options,112 startTime,113 verboseInfo,114 fileDescriptors,115 originalStreams,116 command,117 escapedCommand,118 controller,119 });120 return {subprocess, promise};121};122123const handlePromise = async ({subprocess, options, startTime, verboseInfo, fileDescriptors, originalStreams, command, escapedCommand, controller}) => {124 const context = {timedOut: false};12580 const [81 errorInfo,82 [exitCode, signal],83 stdioResults,84 allResult,85 ] = await waitForSubprocessResult({subprocess, options, context, verboseInfo, fileDescriptors, originalStreams, controller});126 const [errorInfo, [exitCode, signal], stdioResults, allResult] = await waitForSubprocessResult({127 subprocess,128 options,129 context,130 verboseInfo,131 fileDescriptors,132 originalStreams,133 controller,134 });135 controller.abort();136137 const stdio = stdioResults.map((stdioResult, fdNumber) => stripNewline(stdioResult, options, fdNumber));138 const all = stripNewline(allResult, options, 'all');90 const result = getAsyncResult({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime});139 const result = getAsyncResult({140 errorInfo,141 exitCode,142 signal,143 stdio,144 all,145 context,146 options,147 command,148 escapedCommand,149 startTime,150 });151 return handleResult(result, verboseInfo, options);152};153154const getAsyncResult = ({errorInfo, exitCode, signal, stdio, all, context, options, command, escapedCommand, startTime}) => 'error' in errorInfo
11 unmodified lines
166 options,167 startTime,168 isSync: false,169 })110 : makeSuccessResult({command, escapedCommand, stdio, all, options, startTime});170 : makeSuccessResult({171 command,172 escapedCommand,173 stdio,174 all,175 options,176 startTime,177 });
modified:lib/methods/main-sync.js+74 added-15 removed
10 unmodified lines
11import {logEarlyResult} from '../verbose/complete.js';12import {getAllSync} from '../resolve/all-sync.js';13import {getExitResultSync} from '../resolve/exit-sync.js';1415export const execaCoreSync = (rawFile, rawArgs, rawOptions) => {16 const {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArgs, rawOptions);17 const result = spawnSubprocessSync({file, args, options, command, escapedCommand, verboseInfo, fileDescriptors, startTime});15export const execaCoreSync = (rawFile, rawArguments, rawOptions) => {16 const {file, commandArguments, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors} = handleSyncArguments(rawFile, rawArguments, rawOptions);17 const result = spawnSubprocessSync({18 file,19 commandArguments,20 options,21 command,22 escapedCommand,23 verboseInfo,24 fileDescriptors,25 startTime,26 });27 return handleResult(result, verboseInfo, options);28};2921const handleSyncArguments = (rawFile, rawArgs, rawOptions) => {22 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArgs, rawOptions);30const handleSyncArguments = (rawFile, rawArguments, rawOptions) => {31 const {command, escapedCommand, startTime, verboseInfo} = handleCommand(rawFile, rawArguments, rawOptions);3233 try {34 const syncOptions = normalizeSyncOptions(rawOptions);26 const {file, args, options} = handleOptions(rawFile, rawArgs, syncOptions);35 const {file, commandArguments, options} = handleOptions(rawFile, rawArguments, syncOptions);36 validateSyncOptions(options);37 const fileDescriptors = handleStdioSync(options, verboseInfo);29 return {file, args, command, escapedCommand, startTime, verboseInfo, options, fileDescriptors};38 return {39 file,40 commandArguments,41 command,42 escapedCommand,43 startTime,44 verboseInfo,45 options,46 fileDescriptors,47 };48 } catch (error) {49 logEarlyResult(error, startTime, verboseInfo);50 throw error;51 }
18 unmodified lines
70const throwInvalidSyncOption = value => {71 throw new TypeError(`The "${value}" option cannot be used with synchronous methods.`);72};7356const spawnSubprocessSync = ({file, args, options, command, escapedCommand, verboseInfo, fileDescriptors, startTime}) => {57 const syncResult = runSubprocessSync({file, args, options, command, escapedCommand, fileDescriptors, startTime});74const spawnSubprocessSync = ({file, commandArguments, options, command, escapedCommand, verboseInfo, fileDescriptors, startTime}) => {75 const syncResult = runSubprocessSync({76 file,77 commandArguments,78 options,79 command,80 escapedCommand,81 fileDescriptors,82 startTime,83 });84 if (syncResult.failed) {85 return syncResult;86 }8788 const {resultError, exitCode, signal, timedOut, isMaxBuffer} = getExitResultSync(syncResult, options);63 const {output, error = resultError} = transformOutputSync({fileDescriptors, syncResult, options, isMaxBuffer, verboseInfo});89 const {output, error = resultError} = transformOutputSync({90 fileDescriptors,91 syncResult,92 options,93 isMaxBuffer,94 verboseInfo,95 });96 const stdio = output.map((stdioOutput, fdNumber) => stripNewline(stdioOutput, options, fdNumber));97 const all = stripNewline(getAllSync(output, options), options, 'all');66 return getSyncResult({error, exitCode, signal, timedOut, isMaxBuffer, stdio, all, options, command, escapedCommand, startTime});98 return getSyncResult({99 error,100 exitCode,101 signal,102 timedOut,103 isMaxBuffer,104 stdio,105 all,106 options,107 command,108 escapedCommand,109 startTime,110 });111};11269const runSubprocessSync = ({file, args, options, command, escapedCommand, fileDescriptors, startTime}) => {113const runSubprocessSync = ({file, commandArguments, options, command, escapedCommand, fileDescriptors, startTime}) => {114 try {115 addInputOptionsSync(fileDescriptors, options);116 const normalizedOptions = normalizeSpawnSyncOptions(options);73 return spawnSync(file, args, normalizedOptions);117 return spawnSync(file, commandArguments, normalizedOptions);118 } catch (error) {75 return makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: true});119 return makeEarlyError({120 error,121 command,122 escapedCommand,123 fileDescriptors,124 options,125 startTime,126 isSync: true,127 });128 }129};130131const normalizeSpawnSyncOptions = ({encoding, maxBuffer, ...options}) => ({...options, encoding: 'buffer', maxBuffer: getMaxBufferSync(maxBuffer)});132133const getSyncResult = ({error, exitCode, signal, timedOut, isMaxBuffer, stdio, all, options, command, escapedCommand, startTime}) => error === undefined82 ? makeSuccessResult({command, escapedCommand, stdio, all, options, startTime})134 ? makeSuccessResult({135 command,136 escapedCommand,137 stdio,138 all,139 options,140 startTime,141 })142 : makeError({143 error,144 command,145 escapedCommand,
11 unmodified lines
modified:lib/methods/node.js+10 added-5 removed
8 unmodified lines
910 return {options: {...options, node: true}};11};1213export const handleNodeOption = (file, args, {13export const handleNodeOption = (file, commandArguments, {14 node: shouldHandleNode = false,15 nodePath = execPath,16 nodeOptions = execArgv.filter(arg => !arg.startsWith('--inspect')),16 nodeOptions = execArgv.filter(nodeOption => !nodeOption.startsWith('--inspect')),17 cwd,18 execPath: formerNodePath,19 ...options20}) => {
2 unmodified lines
23 }2425 const normalizedNodePath = safeNormalizeFileUrl(nodePath, 'The "nodePath" option');26 const resolvedNodePath = resolve(cwd, normalizedNodePath);27 const newOptions = {...options, nodePath: resolvedNodePath, node: shouldHandleNode, cwd};27 const newOptions = {28 ...options,29 nodePath: resolvedNodePath,30 node: shouldHandleNode,31 cwd,32 };3334 if (!shouldHandleNode) {30 return [file, args, newOptions];35 return [file, commandArguments, newOptions];36 }3738 if (basename(file, '.exe') === 'node') {39 throw new TypeError('When the "node" option is true, the first argument does not need to be "node".');40 }4142 return [43 resolvedNodePath,39 [...nodeOptions, file, ...args],44 [...nodeOptions, file, ...commandArguments],45 {ipc: true, ...newOptions, shell: false},46 ];47};
modified:lib/methods/parameters.js+13 added-13 removed
1import isPlainObject from 'is-plain-obj';2import {safeNormalizeFileUrl} from '../arguments/file-url.js';34export const normalizeParameters = (rawFile, rawArgs = [], rawOptions = {}) => {4export const normalizeParameters = (rawFile, rawArguments = [], rawOptions = {}) => {5 const filePath = safeNormalizeFileUrl(rawFile, 'First argument');6 const [args, options] = isPlainObject(rawArgs)7 ? [[], rawArgs]8 : [rawArgs, rawOptions];6 const [commandArguments, options] = isPlainObject(rawArguments)7 ? [[], rawArguments]8 : [rawArguments, rawOptions];910 if (!Array.isArray(args)) {11 throw new TypeError(`Second argument must be either an array of arguments or an options object: ${args}`);10 if (!Array.isArray(commandArguments)) {11 throw new TypeError(`Second argument must be either an array of arguments or an options object: ${commandArguments}`);12 }1314 if (args.some(arg => typeof arg === 'object' && arg !== null)) {15 throw new TypeError(`Second argument must be an array of strings: ${args}`);14 if (commandArguments.some(commandArgument => typeof commandArgument === 'object' && commandArgument !== null)) {15 throw new TypeError(`Second argument must be an array of strings: ${commandArguments}`);16 }1718 const normalizedArgs = args.map(String);19 const nullByteArg = normalizedArgs.find(arg => arg.includes('\0'));20 if (nullByteArg !== undefined) {21 throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${nullByteArg}`);18 const normalizedArguments = commandArguments.map(String);19 const nullByteArgument = normalizedArguments.find(normalizedArgument => normalizedArgument.includes('\0'));20 if (nullByteArgument !== undefined) {21 throw new TypeError(`Arguments cannot contain null bytes ("\\0"): ${nullByteArgument}`);22 }2324 if (!isPlainObject(options)) {25 throw new TypeError(`Last argument must be an options object: ${options}`);26 }2728 return [filePath, normalizedArgs, options];28 return [filePath, normalizedArguments, options];29};
modified:lib/methods/template.js+9 added-3 removed
5 unmodified lines
6export const parseTemplates = (templates, expressions) => {7 let tokens = [];89 for (const [index, template] of templates.entries()) {10 tokens = parseTemplate({templates, expressions, tokens, index, template});10 tokens = parseTemplate({11 templates,12 expressions,13 tokens,14 index,15 template,16 });17 }1819 if (tokens.length === 0) {20 throw new TypeError('Template script must not be empty');21 }2217 const [file, ...args] = tokens;18 return [file, args, {}];23 const [file, ...commandArguments] = tokens;24 return [file, commandArguments, {}];25};2627const parseTemplate = ({templates, expressions, tokens, index, template}) => {28 if (template === undefined) {
113 unmodified lines
modified:lib/pipe/abort.js+8 added-3 removed
1import {aborted} from 'node:util';2import {createNonCommandError} from './throw.js';34export const unpipeOnAbort = (unpipeSignal, ...args) => unpipeSignal === undefined4export const unpipeOnAbort = (unpipeSignal, unpipeContext) => unpipeSignal === undefined5 ? []6 : [unpipeOnSignalAbort(unpipeSignal, ...args)];6 : [unpipeOnSignalAbort(unpipeSignal, unpipeContext)];78const unpipeOnSignalAbort = async (unpipeSignal, {sourceStream, mergedStream, fileDescriptors, sourceOptions, startTime}) => {9 await aborted(unpipeSignal, sourceStream);10 await mergedStream.remove(sourceStream);11 const error = new Error('Pipe cancelled by `unpipeSignal` option.');12 throw createNonCommandError({error, fileDescriptors, sourceOptions, startTime});12 throw createNonCommandError({13 error,14 fileDescriptors,15 sourceOptions,16 startTime,17 });18};
modified:lib/pipe/pipe-arguments.js+15 added-10 removed
1import {normalizeParameters} from '../methods/parameters.js';2import {getStartTime} from '../return/duration.js';3import {SUBPROCESS_OPTIONS, getWritable, getReadable} from '../arguments/fd-options.js';45export const normalizePipeArguments = ({source, sourcePromise, boundOptions, createNested}, ...args) => {5export const normalizePipeArguments = ({source, sourcePromise, boundOptions, createNested}, ...pipeArguments) => {6 const startTime = getStartTime();7 const {8 destination,9 destinationStream,10 destinationError,11 from,12 unpipeSignal,13 } = getDestinationStream(boundOptions, createNested, args);13 } = getDestinationStream(boundOptions, createNested, pipeArguments);14 const {sourceStream, sourceError} = getSourceStream(source, from);15 const {options: sourceOptions, fileDescriptors} = SUBPROCESS_OPTIONS.get(source);16 return {17 sourcePromise,
8 unmodified lines
26 startTime,27 };28};2930const getDestinationStream = (boundOptions, createNested, args) => {30const getDestinationStream = (boundOptions, createNested, pipeArguments) => {31 try {32 const {33 destination,34 pipeOptions: {from, to, unpipeSignal} = {},35 } = getDestination(boundOptions, createNested, ...args);35 } = getDestination(boundOptions, createNested, ...pipeArguments);36 const destinationStream = getWritable(destination, to);37 return {destination, destinationStream, from, unpipeSignal};37 return {38 destination,39 destinationStream,40 from,41 unpipeSignal,42 };43 } catch (error) {44 return {destinationError: error};45 }46};4743const getDestination = (boundOptions, createNested, firstArgument, ...args) => {48const getDestination = (boundOptions, createNested, firstArgument, ...pipeArguments) => {49 if (Array.isArray(firstArgument)) {45 const destination = createNested(mapDestinationArguments, boundOptions)(firstArgument, ...args);50 const destination = createNested(mapDestinationArguments, boundOptions)(firstArgument, ...pipeArguments);51 return {destination, pipeOptions: boundOptions};52 }5354 if (typeof firstArgument === 'string' || firstArgument instanceof URL) {55 if (Object.keys(boundOptions).length > 0) {56 throw new TypeError('Please use .pipe("file", ..., options) or .pipe(execa("file", ..., options)) instead of .pipe(options)("file", ...).');57 }5854 const [rawFile, rawArgs, rawOptions] = normalizeParameters(firstArgument, ...args);55 const destination = createNested(mapDestinationArguments)(rawFile, rawArgs, rawOptions);59 const [rawFile, rawArguments, rawOptions] = normalizeParameters(firstArgument, ...pipeArguments);60 const destination = createNested(mapDestinationArguments)(rawFile, rawArguments, rawOptions);61 return {destination, pipeOptions: rawOptions};62 }6364 if (SUBPROCESS_OPTIONS.has(firstArgument)) {65 if (Object.keys(boundOptions).length > 0) {66 throw new TypeError('Please use .pipe(options)`command` or .pipe($(options)`command`) instead of .pipe(options)($`command`).');67 }6864 return {destination: firstArgument, pipeOptions: args[0]};69 return {destination: firstArgument, pipeOptions: pipeArguments[0]};70 }7172 throw new TypeError(`The first argument must be a template string, an options object, or an Execa subprocess: ${firstArgument}`);73};
11 unmodified lines
modified:lib/pipe/setup.js+17 added-6 removed
4 unmodified lines
5import {pipeSubprocessStream} from './streaming.js';6import {unpipeOnAbort} from './abort.js';78// Pipe a subprocess' `stdout`/`stderr`/`stdio` into another subprocess' `stdin`9export const pipeToSubprocess = (sourceInfo, ...args) => {10 if (isPlainObject(args[0])) {9export const pipeToSubprocess = (sourceInfo, ...pipeArguments) => {10 if (isPlainObject(pipeArguments[0])) {11 return pipeToSubprocess.bind(undefined, {12 ...sourceInfo,13 boundOptions: {...sourceInfo.boundOptions, ...args[0]},13 boundOptions: {...sourceInfo.boundOptions, ...pipeArguments[0]},14 });15 }1617 const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...args);17 const {destination, ...normalizedInfo} = normalizePipeArguments(sourceInfo, ...pipeArguments);18 const promise = handlePipePromise({...normalizedInfo, destination});19 promise.pipe = pipeToSubprocess.bind(undefined, {...sourceInfo, source: destination, sourcePromise: promise, boundOptions: {}});19 promise.pipe = pipeToSubprocess.bind(undefined, {20 ...sourceInfo,21 source: destination,22 sourcePromise: promise,23 boundOptions: {},24 });25 return promise;26};2728const handlePipePromise = async ({
22 unmodified lines
51 try {52 const mergedStream = pipeSubprocessStream(sourceStream, destinationStream, maxListenersController);53 return await Promise.race([54 waitForBothSubprocesses(subprocessPromises),50 ...unpipeOnAbort(unpipeSignal, {sourceStream, mergedStream, sourceOptions, fileDescriptors, startTime}),55 ...unpipeOnAbort(unpipeSignal, {56 sourceStream,57 mergedStream,58 sourceOptions,59 fileDescriptors,60 startTime,61 }),62 ]);63 } finally {64 maxListenersController.abort();65 }
6 unmodified lines
modified:lib/pipe/throw.js+12 added-2 removed
8 unmodified lines
9 fileDescriptors,10 sourceOptions,11 startTime,12}) => {13 const error = getPipeArgumentsError({sourceStream, sourceError, destinationStream, destinationError});13 const error = getPipeArgumentsError({14 sourceStream,15 sourceError,16 destinationStream,17 destinationError,18 });19 if (error !== undefined) {15 throw createNonCommandError({error, fileDescriptors, sourceOptions, startTime});20 throw createNonCommandError({21 error,22 fileDescriptors,23 sourceOptions,24 startTime,25 });26 }27};2829const getPipeArgumentsError = ({sourceStream, sourceError, destinationStream, destinationError}) => {
26 unmodified lines
modified:lib/resolve/exit-sync.js+7 added-1 removed
4 unmodified lines
5export const getExitResultSync = ({error, status: exitCode, signal, output}, {maxBuffer}) => {6 const resultError = getResultError(error, exitCode, signal);7 const timedOut = resultError?.code === 'ETIMEDOUT';8 const isMaxBuffer = isMaxBufferSync(resultError, output, maxBuffer);9 return {resultError, exitCode, signal, timedOut, isMaxBuffer};9 return {10 resultError,11 exitCode,12 signal,13 timedOut,14 isMaxBuffer,15 };16};1718const getResultError = (error, exitCode, signal) => {19 if (error !== undefined) {
5 unmodified lines
modified:lib/resolve/stdio.js+13 added-1 removed
25 unmodified lines
26 return;27 }2829 const [output] = await Promise.all([30 getStreamOutput({stream, onStreamEnd, fdNumber, encoding, buffer, maxBuffer, lines, allMixed, stripFinalNewline, verboseInfo, streamInfo}),30 getStreamOutput({31 stream,32 onStreamEnd,33 fdNumber,34 encoding,35 buffer,36 maxBuffer,37 lines,38 allMixed,39 stripFinalNewline,40 verboseInfo,41 streamInfo,42 }),43 onStreamEnd,44 ]);45 return output;46};
modified:lib/resolve/wait-stream.js+2 added-2 removed
40 unmodified lines
41};4243const spyOnStdinDestroy = (subprocessStdin, subprocess, state) => {44 const {_destroy} = subprocessStdin;45 subprocessStdin._destroy = (...args) => {45 subprocessStdin._destroy = (...destroyArguments) => {46 setStdinCleanedUp(subprocess, state);47 _destroy.call(subprocessStdin, ...args);47 _destroy.call(subprocessStdin, ...destroyArguments);48 };49};5051const setStdinCleanedUp = ({exitCode, signalCode}, state) => {
45 unmodified lines
modified:lib/resolve/wait-subprocess.js+27 added-3 removed
19 unmodified lines
20 originalStreams,21 controller,22}) => {23 const exitPromise = waitForExit(subprocess);24 const streamInfo = {originalStreams, fileDescriptors, subprocess, exitPromise, propagating: false};24 const streamInfo = {25 originalStreams,26 fileDescriptors,27 subprocess,28 exitPromise,29 propagating: false,30 };3126 const stdioPromises = waitForStdioStreams({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo});27 const allPromise = waitForAllStream({subprocess, encoding, buffer, maxBuffer, lines, stripFinalNewline, verboseInfo, streamInfo});32 const stdioPromises = waitForStdioStreams({33 subprocess,34 encoding,35 buffer,36 maxBuffer,37 lines,38 stripFinalNewline,39 verboseInfo,40 streamInfo,41 });42 const allPromise = waitForAllStream({43 subprocess,44 encoding,45 buffer,46 maxBuffer,47 lines,48 stripFinalNewline,49 verboseInfo,50 streamInfo,51 });52 const originalPromises = waitForOriginalStreams(originalStreams, subprocess, streamInfo);53 const customStreamsEndPromises = waitForCustomStreamsEnd(fileDescriptors, streamInfo);5455 try {
51 unmodified lines
modified:lib/return/early-error.js+22 added-3 removed
1import {ChildProcess} from 'node:child_process';2import {PassThrough, Readable, Writable, Duplex} from 'node:stream';2import {3 PassThrough,4 Readable,5 Writable,6 Duplex,7} from 'node:stream';8import {cleanupCustomStreams} from '../stdio/handle-async.js';9import {makeEarlyError} from './result.js';10import {handleResult} from './reject.js';11
5 unmodified lines
17 const subprocess = new ChildProcess();18 createDummyStreams(subprocess, fileDescriptors);19 Object.assign(subprocess, {readable, writable, duplex});2016 const earlyError = makeEarlyError({error, command, escapedCommand, fileDescriptors, options, startTime, isSync: false});21 const earlyError = makeEarlyError({22 error,23 command,24 escapedCommand,25 fileDescriptors,26 options,27 startTime,28 isSync: false,29 });30 const promise = handleDummyPromise(earlyError, verboseInfo, options);31 return {subprocess, promise};32};33
3 unmodified lines
37 const stderr = createDummyStream();38 const extraStdio = Array.from({length: fileDescriptors.length - 3}, createDummyStream);39 const all = createDummyStream();40 const stdio = [stdin, stdout, stderr, ...extraStdio];28 Object.assign(subprocess, {stdin, stdout, stderr, all, stdio});41 Object.assign(subprocess, {42 stdin,43 stdout,44 stderr,45 all,46 stdio,47 });48};4950const createDummyStream = () => {51 const stream = new PassThrough();
9 unmodified lines
modified:lib/return/message.js+12 added-1 removed
19 unmodified lines
20 timeout,21 cwd,22}) => {23 const errorCode = originalError?.code;24 const prefix = getErrorPrefix({originalError, timedOut, timeout, isMaxBuffer, maxBuffer, errorCode, signal, signalDescription, exitCode, isCanceled});24 const prefix = getErrorPrefix({25 originalError,26 timedOut,27 timeout,28 isMaxBuffer,29 maxBuffer,30 errorCode,31 signal,32 signalDescription,33 exitCode,34 isCanceled,35 });36 const originalMessage = getOriginalMessage(originalError, cwd);37 const newline = originalMessage === '' ? '' : '\n';38 const shortMessage = `${prefix}: ${escapedCommand}${newline}${originalMessage}`;39 const messageStdio = all === undefined ? [stdio[2], stdio[1]] : [all];
61 unmodified lines
modified:lib/stdio/handle.js+26 added-5 removed
1import {getStreamName} from '../utils/standard-stream.js';2import {normalizeTransforms} from '../transform/normalize.js';3import {getFdObjectMode} from '../transform/object-mode.js';4import {getStdioItemType, isRegularUrl, isUnknownStdioString, FILE_TYPES} from './type.js';4import {5 getStdioItemType,6 isRegularUrl,7 isUnknownStdioString,8 FILE_TYPES,9} from './type.js';10import {getStreamDirection} from './direction.js';11import {normalizeStdioOption} from './stdio-option.js';12import {handleNativeStream} from './native.js';13import {handleInputOptions} from './input-option.js';1415// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async/sync mode16export const handleStdio = (addProperties, options, verboseInfo, isSync) => {17 const stdio = normalizeStdioOption(options, isSync);13 const fileDescriptors = stdio.map((stdioOption, fdNumber) =>14 getFileDescriptor({stdioOption, fdNumber, addProperties, options, isSync}));18 const fileDescriptors = stdio.map((stdioOption, fdNumber) => getFileDescriptor({19 stdioOption,20 fdNumber,21 addProperties,22 options,23 isSync,24 }));25 options.stdio = fileDescriptors.map(({stdioItems}) => forwardStdio(stdioItems));26 return fileDescriptors;27};28
1 unmodified line
30// This is what users would expect.31// For example, `stdout: ['ignore']` behaves the same as `stdout: 'ignore'`.32const getFileDescriptor = ({stdioOption, fdNumber, addProperties, options, isSync}) => {33 const optionName = getStreamName(fdNumber);24 const {stdioItems: initialStdioItems, isStdioArray} = initializeStdioItems({stdioOption, fdNumber, options, optionName});34 const {stdioItems: initialStdioItems, isStdioArray} = initializeStdioItems({35 stdioOption,36 fdNumber,37 options,38 optionName,39 });40 const direction = getStreamDirection(initialStdioItems, fdNumber, optionName);26 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({stdioItem, isStdioArray, fdNumber, direction, isSync}));41 const stdioItems = initialStdioItems.map(stdioItem => handleNativeStream({42 stdioItem,43 isStdioArray,44 fdNumber,45 direction,46 isSync,47 }));48 const normalizedStdioItems = normalizeTransforms(stdioItems, optionName, direction, options);49 const objectMode = getFdObjectMode(normalizedStdioItems, direction);50 validateFileObjectMode(normalizedStdioItems, objectMode);51 const finalStdioItems = normalizedStdioItems.map(stdioItem => addStreamProperties(stdioItem, addProperties, direction, options));
96 unmodified lines
modified:lib/stdio/native.js+6 added-1 removed
21 unmodified lines
22 : handleNativeStreamAsync({stdioItem, fdNumber});23};2425const handleNativeStreamSync = ({stdioItem, stdioItem: {value, optionName}, fdNumber, direction}) => {26 const targetFd = getTargetFd({value, optionName, fdNumber, direction});26 const targetFd = getTargetFd({27 value,28 optionName,29 fdNumber,30 direction,31 });32 if (targetFd !== undefined) {33 return targetFd;34 }35
69 unmodified lines
modified:lib/terminate/kill.js+8 added-1 removed
23 unmodified lines
24export const subprocessKill = ({kill, subprocess, options: {forceKillAfterDelay, killSignal}, controller}, signalOrError, errorArgument) => {25 const {signal, error} = parseKillArguments(signalOrError, errorArgument, killSignal);26 emitKillError(subprocess, error);27 const killResult = kill(signal);28 setKillTimeout({kill, signal, forceKillAfterDelay, killSignal, killResult, controller});28 setKillTimeout({29 kill,30 signal,31 forceKillAfterDelay,32 killSignal,33 killResult,34 controller,35 });36 return killResult;37};3839const parseKillArguments = (signalOrError, errorArgument, killSignal) => {
44 unmodified lines
modified:lib/transform/generator.js+18 added-3 removed
1 unmodified line
2import {isAsyncGenerator} from '../stdio/type.js';3import {getSplitLinesGenerator, getAppendNewlineGenerator} from './split.js';4import {getValidateTransformInput, getValidateTransformReturn} from './validate.js';5import {getEncodingTransformGenerator} from './encoding-transform.js';6import {pushChunks, transformChunk, finalChunks, destroyTransform} from './run-async.js';7import {pushChunksSync, transformChunkSync, finalChunksSync, runTransformSync} from './run-sync.js';6import {7 pushChunks,8 transformChunk,9 finalChunks,10 destroyTransform,11} from './run-async.js';12import {13 pushChunksSync,14 transformChunkSync,15 finalChunksSync,16 runTransformSync,17} from './run-sync.js';1819/*20Generators can be used to transform/filter standard streams.21
72 unmodified lines
94 getEncodingTransformGenerator(binary, encoding, writableObjectMode),95 getSplitLinesGenerator(binary, preserveNewlines, writableObjectMode, state),96 {transform, final},97 {transform: getValidateTransformReturn(readableObjectMode, optionName)},88 getAppendNewlineGenerator({binary, preserveNewlines, readableObjectMode, state}),98 getAppendNewlineGenerator({99 binary,100 preserveNewlines,101 readableObjectMode,102 state,103 }),104 ].filter(Boolean);105};
modified:lib/transform/normalize.js+32 added-4 removed
13 unmodified lines
14 const transforms = stdioItems.filter(({type}) => TRANSFORM_TYPES.has(type));15 const newTransforms = Array.from({length: transforms.length});1617 for (const [index, stdioItem] of Object.entries(transforms)) {18 newTransforms[index] = normalizeTransform({stdioItem, index: Number(index), newTransforms, optionName, direction, encoding});18 newTransforms[index] = normalizeTransform({19 stdioItem,20 index: Number(index),21 newTransforms,22 optionName,23 direction,24 encoding,25 });26 }2728 return sortTransforms(newTransforms, direction);29};
3 unmodified lines
33 return normalizeDuplex({stdioItem, optionName});34 }3536 if (type === 'webTransform') {30 return normalizeTransformStream({stdioItem, index, newTransforms, direction});37 return normalizeTransformStream({38 stdioItem,39 index,40 newTransforms,41 direction,42 });43 }4433 return normalizeGenerator({stdioItem, index, newTransforms, direction, encoding});45 return normalizeGenerator({46 stdioItem,47 index,48 newTransforms,49 direction,50 encoding,51 });52};5354const normalizeDuplex = ({55 stdioItem,
38 unmodified lines
94 objectMode,95 } = isPlainObj(value) ? value : {transform: value};96 const binary = binaryOption || BINARY_ENCODINGS.has(encoding);97 const {writableObjectMode, readableObjectMode} = getTransformObjectModes(objectMode, index, newTransforms, direction);80 return {...stdioItem, value: {transform, final, binary, preserveNewlines, writableObjectMode, readableObjectMode}};98 return {99 ...stdioItem,100 value: {101 transform,102 final,103 binary,104 preserveNewlines,105 writableObjectMode,106 readableObjectMode,107 },108 };109};110111const sortTransforms = (newTransforms, direction) => direction === 'input' ? newTransforms.reverse() : newTransforms;
modified:lib/transform/run-async.js+2 added-2 removed
1import {callbackify} from 'node:util';23export const pushChunks = callbackify(async (getChunks, state, args, transformStream) => {4 state.currentIterable = getChunks(...args);3export const pushChunks = callbackify(async (getChunks, state, getChunksArguments, transformStream) => {4 state.currentIterable = getChunks(...getChunksArguments);56 try {7 for await (const chunk of state.currentIterable) {8 transformStream.push(chunk);
51 unmodified lines
modified:lib/transform/run-sync.js+2 added-2 removed
1// Duplicate the code from `transform-async.js` but as synchronous functions2export const pushChunksSync = (getChunksSync, args, transformStream, done) => {2export const pushChunksSync = (getChunksSync, getChunksArguments, transformStream, done) => {3 try {4 for (const chunk of getChunksSync(...args)) {4 for (const chunk of getChunksSync(...getChunksArguments)) {5 transformStream.push(chunk);6 }78 done();
42 unmodified lines
modified:lib/verbose/complete.js+14 added-2 removed
6 unmodified lines
7import {logError} from './error.js';89// When `verbose` is `short|full`, print each command's completion, duration and error10export const logFinalResult = ({shortMessage, failed, durationMs}, reject, verboseInfo) => {11 logResult({message: shortMessage, failed, reject, durationMs, verboseInfo});11 logResult({12 message: shortMessage,13 failed,14 reject,15 durationMs,16 verboseInfo,17 });18};1920// Same but for early validation errors21export const logEarlyResult = (error, startTime, verboseInfo) => {
11 unmodified lines
33 return;34 }3536 const icon = getIcon(failed, reject);31 logError({message, failed, reject, verboseId, icon});37 logError({38 message,39 failed,40 reject,41 verboseId,42 icon,43 });44 logDuration(durationMs, verboseId, icon);45};4647const logDuration = (durationMs, verboseId, icon) => {
11 unmodified lines
modified:test/arguments/cwd.js+7 added-7 removed
3 unmodified lines
4import {pathToFileURL, fileURLToPath} from 'node:url';5import tempfile from 'tempfile';6import test from 'ava';7import {execa, execaSync} from '../../index.js';8import {FIXTURES_DIR, setFixtureDir} from '../helpers/fixtures-dir.js';8import {FIXTURES_DIRECTORY, setFixtureDirectory} from '../helpers/fixtures-directory.js';910setFixtureDir();10setFixtureDirectory();1112const isWindows = process.platform === 'win32';1314const testOptionCwdString = async (t, execaMethod) => {
55 unmodified lines
70}7172const cwdNotExisting = {cwd: 'does_not_exist', expectedCode: 'ENOENT', expectedMessage: 'The "cwd" option is invalid'};73const cwdTooLong = {cwd: '.'.repeat(1e5), expectedCode: 'ENAMETOOLONG', expectedMessage: 'The "cwd" option is invalid'};74const cwdNotDir = {cwd: fileURLToPath(import.meta.url), expectedCode: isWindows ? 'ENOENT' : 'ENOTDIR', expectedMessage: 'The "cwd" option is not a directory'};74const cwdNotDirectory = {cwd: fileURLToPath(import.meta.url), expectedCode: isWindows ? 'ENOENT' : 'ENOTDIR', expectedMessage: 'The "cwd" option is not a directory'};7576const testCwdPostSpawn = async (t, {cwd, expectedCode, expectedMessage}, execaMethod) => {77 const {failed, code, message} = await execaMethod('empty.js', {cwd, reject: false});78 t.true(failed);
5 unmodified lines
84test('The "cwd" option must be an existing file', testCwdPostSpawn, cwdNotExisting, execa);85test('The "cwd" option must be an existing file - sync', testCwdPostSpawn, cwdNotExisting, execaSync);86test('The "cwd" option must not be too long', testCwdPostSpawn, cwdTooLong, execa);87test('The "cwd" option must not be too long - sync', testCwdPostSpawn, cwdTooLong, execaSync);88test('The "cwd" option must be a directory', testCwdPostSpawn, cwdNotDir, execa);89test('The "cwd" option must be a directory - sync', testCwdPostSpawn, cwdNotDir, execaSync);88test('The "cwd" option must be a directory', testCwdPostSpawn, cwdNotDirectory, execa);89test('The "cwd" option must be a directory - sync', testCwdPostSpawn, cwdNotDirectory, execaSync);9091const successProperties = {fixtureName: 'empty.js', expectedFailed: false};92const errorProperties = {fixtureName: 'fail.js', expectedFailed: true};9394const testErrorCwd = async (t, execaMethod, {fixtureName, expectedFailed}) => {95 const {failed, cwd} = await execaMethod(fixtureName, {cwd: relative('.', FIXTURES_DIR), reject: false});95 const {failed, cwd} = await execaMethod(fixtureName, {cwd: relative('.', FIXTURES_DIRECTORY), reject: false});96 t.is(failed, expectedFailed);97 t.is(cwd, FIXTURES_DIR);97 t.is(cwd, FIXTURES_DIRECTORY);98};99100test('result.cwd is defined', testErrorCwd, execa, successProperties);101test('result.cwd is defined - sync', testErrorCwd, execaSync, successProperties);
2 unmodified lines
modified:test/arguments/encoding-option.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';45setFixtureDir();5setFixtureDirectory();67const testInvalidEncoding = (t, encoding, message, execaMethod) => {8 const error = t.throws(() => {9 execaMethod('empty.js', {encoding});
30 unmodified lines
modified:test/arguments/env.js+2 added-2 removed
1import process from 'node:process';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir, PATH_KEY} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory, PATH_KEY} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();7process.env.FOO = 'foo';89const isWindows = process.platform === 'win32';10
22 unmodified lines
modified:test/arguments/escape.js+10 added-10 removed
1import {platform} from 'node:process';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();78const isWindows = platform === 'win32';910const testResultCommand = async (t, expected, ...args) => {11 const {command: failCommand} = await t.throwsAsync(execa('fail.js', args));10const testResultCommand = async (t, expected, ...commandArguments) => {11 const {command: failCommand} = await t.throwsAsync(execa('fail.js', commandArguments));12 t.is(failCommand, `fail.js${expected}`);1314 const {command} = await execa('noop.js', args);14 const {command} = await execa('noop.js', commandArguments);15 t.is(command, `noop.js${expected}`);16};1718testResultCommand.title = (message, expected) => `result.command is: ${JSON.stringify(expected)}`;
1 unmodified line
20test(testResultCommand, ' foo bar', 'foo', 'bar');21test(testResultCommand, ' baz quz', 'baz', 'quz');22test(testResultCommand, '');2324const testEscapedCommand = async (t, args, expectedUnix, expectedWindows) => {24const testEscapedCommand = async (t, commandArguments, expectedUnix, expectedWindows) => {25 const expected = isWindows ? expectedWindows : expectedUnix;2627 t.like(28 await t.throwsAsync(execa('fail.js', args)),28 await t.throwsAsync(execa('fail.js', commandArguments)),29 {escapedCommand: `fail.js ${expected}`},30 );3132 t.like(t.throws(() => {33 execaSync('fail.js', args);33 execaSync('fail.js', commandArguments);34 }), {escapedCommand: `fail.js ${expected}`});3536 t.like(37 await execa('noop.js', args),37 await execa('noop.js', commandArguments),38 {escapedCommand: `noop.js ${expected}`},39 );4041 t.like(42 execaSync('noop.js', args),42 execaSync('noop.js', commandArguments),43 {escapedCommand: `noop.js ${expected}`},44 );45};46
54 unmodified lines
modified:test/arguments/fd-options.js+18 added-4 removed
1 unmodified line
2import {spawn} from 'node:child_process';3import process from 'node:process';4import test from 'ava';5import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {fullStdio, getStdio} from '../helpers/stdio.js';8import {getEarlyErrorSubprocess} from '../helpers/early-error.js';9import {assertPipeError} from '../helpers/pipe.js';1011setFixtureDir();11setFixtureDirectory();1213const getMessage = message => Array.isArray(message)14 ? `"${message[0]}: ${message[1]}" option is incompatible`15 : message;
20 unmodified lines
36 from,37 to,38 writable = to !== undefined,39}) => {40 assertNodeStream({t, message, getSource, from, to, methodName: writable ? 'writable' : 'readable'});41 assertNodeStream({t, message, getSource, from, to, methodName: 'duplex'});40 assertNodeStream({41 t,42 message,43 getSource,44 from,45 to,46 methodName: writable ? 'writable' : 'readable',47 });48 assertNodeStream({49 t,50 message,51 getSource,52 from,53 to,54 methodName: 'duplex',55 });56};5758const assertNodeStream = ({t, message, getSource, from, to, methodName}) => {59 const error = t.throws(() => {
680 unmodified lines
modified:test/arguments/local.js+14 added-14 removed
1 unmodified line
2import process from 'node:process';3import {pathToFileURL} from 'node:url';4import test from 'ava';5import {execa, $} from '../../index.js';6import {setFixtureDir, PATH_KEY} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory, PATH_KEY} from '../helpers/fixtures-directory.js';78setFixtureDir();8setFixtureDirectory();9process.env.FOO = 'foo';1011const isWindows = process.platform === 'win32';12const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;1314const getPathWithoutLocalDir = () => {15 const newPath = process.env[PATH_KEY].split(delimiter).filter(pathDir => !BIN_DIR_REGEXP.test(pathDir)).join(delimiter);14const getPathWithoutLocalDirectory = () => {15 const newPath = process.env[PATH_KEY].split(delimiter).filter(pathDirectory => !BIN_DIR_REGEXP.test(pathDirectory)).join(delimiter);16 return {[PATH_KEY]: newPath};17};1819const BIN_DIR_REGEXP = /node_modules[\\/]\.bin/;2021const pathWitoutLocalDir = getPathWithoutLocalDir();21const pathWitoutLocalDirectory = getPathWithoutLocalDirectory();2223test('preferLocal: true', async t => {24 await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWitoutLocalDir}));24 await t.notThrowsAsync(execa('ava', ['--version'], {preferLocal: true, env: pathWitoutLocalDirectory}));25});2627test('preferLocal: false', async t => {28 await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});28 await t.throwsAsync(execa('ava', ['--version'], {preferLocal: false, env: pathWitoutLocalDirectory}), {message: ENOENT_REGEXP});29});3031test('preferLocal: undefined', async t => {32 await t.throwsAsync(execa('ava', ['--version'], {env: pathWitoutLocalDir}), {message: ENOENT_REGEXP});32 await t.throwsAsync(execa('ava', ['--version'], {env: pathWitoutLocalDirectory}), {message: ENOENT_REGEXP});33});3435test('preferLocal: undefined with $', async t => {36 await t.notThrowsAsync($('ava', ['--version'], {env: pathWitoutLocalDir}));36 await t.notThrowsAsync($('ava', ['--version'], {env: pathWitoutLocalDirectory}));37});3839test('preferLocal: undefined with $.sync', t => {40 t.notThrows(() => $.sync('ava', ['--version'], {env: pathWitoutLocalDir}));40 t.notThrows(() => $.sync('ava', ['--version'], {env: pathWitoutLocalDirectory}));41});4243test('preferLocal: undefined with execa.pipe`...`', async t => {44 await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);44 await t.throwsAsync(() => execa('node', ['--version']).pipe({env: pathWitoutLocalDirectory})`ava --version`);45});4647test('preferLocal: undefined with $.pipe`...`', async t => {48 await t.notThrows(() => $('node', ['--version']).pipe({env: pathWitoutLocalDir})`ava --version`);48 await t.notThrows(() => $('node', ['--version']).pipe({env: pathWitoutLocalDirectory})`ava --version`);49});5051test('preferLocal: undefined with execa.pipe()', async t => {52 await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));52 await t.throwsAsync(() => execa('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDirectory}));53});5455test('preferLocal: undefined with $.pipe()', async t => {56 await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDir}));56 await t.notThrows(() => $('node', ['--version']).pipe('ava', ['--version'], {env: pathWitoutLocalDirectory}));57});5859test('localDir option', async t => {60 const command = isWindows ? 'echo %PATH%' : 'echo $PATH';
11 unmodified lines
modified:test/arguments/shell.js+2 added-2 removed
1 unmodified line
2import {pathToFileURL} from 'node:url';3import test from 'ava';4import which from 'which';5import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {identity} from '../helpers/stdio.js';89setFixtureDir();9setFixtureDirectory();10process.env.FOO = 'foo';1112const isWindows = process.platform === 'win32';13
14 unmodified lines
modified:test/arguments/specific.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';56setFixtureDir();6setFixtureDirectory();78// eslint-disable-next-line max-params9const testPriorityOrder = async (t, buffer, bufferStdout, bufferStderr, execaMethod) => {10 const {stdout, stderr} = await execaMethod('noop-both.js', {buffer});
28 unmodified lines
modified:test/convert/concurrent.js+2 added-2 removed
1import {setTimeout} from 'node:timers/promises';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';6import {fullReadableStdio} from '../helpers/stdio.js';7import {8 finishedStream,
4 unmodified lines
13 assertSubprocessError,14 getReadWriteSubprocess,15} from '../helpers/convert.js';1617setFixtureDir();17setFixtureDirectory();1819const endStream = async stream => {20 stream.end(foobarString);21 await setTimeout(0);
351 unmodified lines
modified:test/convert/duplex.js+8 added-3 removed
1import {compose, Readable, Writable, PassThrough} from 'node:stream';1import {2 compose,3 Readable,4 Writable,5 PassThrough,6} from 'node:stream';7import {pipeline} from 'node:stream/promises';8import {text} from 'node:stream/consumers';9import test from 'ava';10import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';11import {setFixtureDirectory} from '../helpers/fixtures-directory.js';12import {13 finishedStream,14 assertReadableAborted,15 assertWritableAborted,
9 unmodified lines
25import {foobarString} from '../helpers/input.js';26import {prematureClose, fullStdio, fullReadableStdio} from '../helpers/stdio.js';27import {defaultHighWaterMark} from '../helpers/stream.js';2824setFixtureDir();29setFixtureDirectory();3031test('.duplex() success', async t => {32 const subprocess = getReadWriteSubprocess();33 const stream = subprocess.duplex();
160 unmodified lines
modified:test/convert/iterable.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {fullStdio, assertEpipe} from '../helpers/stdio.js';6import {7 arrayFromAsync,
2 unmodified lines
10 assertProcessNormalExit,11} from '../helpers/convert.js';12import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';1314setFixtureDir();14setFixtureDirectory();1516const partialArrayFromAsync = async (asyncIterable, lines = []) => {17 // eslint-disable-next-line no-unreachable-loop18 for await (const line of asyncIterable) {
136 unmodified lines
modified:test/convert/readable.js+8 added-3 removed
1import {once} from 'node:events';2import process from 'node:process';3import {compose, Readable, Writable, PassThrough} from 'node:stream';3import {4 compose,5 Readable,6 Writable,7 PassThrough,8} from 'node:stream';9import {pipeline} from 'node:stream/promises';10import {text} from 'node:stream/consumers';11import {setTimeout} from 'node:timers/promises';12import test from 'ava';13import {execa} from '../../index.js';9import {setFixtureDir} from '../helpers/fixtures-dir.js';14import {setFixtureDirectory} from '../helpers/fixtures-directory.js';15import {16 finishedStream,17 assertReadableAborted,18 assertWritableAborted,
13 unmodified lines
32import {prematureClose, fullStdio} from '../helpers/stdio.js';33import {outputObjectGenerator, getOutputsAsyncGenerator} from '../helpers/generator.js';34import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';3531setFixtureDir();36setFixtureDirectory();3738test('.readable() success', async t => {39 const subprocess = getReadableSubprocess();40 const stream = subprocess.readable();
419 unmodified lines
modified:test/convert/shared.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {5 finishedStream,6 assertWritableAborted,7 assertStreamError,
1 unmodified line
9 getReadWriteSubprocess,10} from '../helpers/convert.js';11import {foobarString} from '../helpers/input.js';1213setFixtureDir();13setFixtureDirectory();1415const testSubprocessFail = async (t, methodName) => {16 const subprocess = getReadWriteSubprocess();17 const stream = subprocess[methodName]();
39 unmodified lines
modified:test/convert/writable.js+8 added-3 removed
4 unmodified lines
5import {setTimeout, scheduler} from 'node:timers/promises';6import {promisify} from 'node:util';7import test from 'ava';8import {execa} from '../../index.js';9import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {setFixtureDirectory} from '../helpers/fixtures-directory.js';10import {11 finishedStream,12 assertWritableAborted,13 assertProcessNormalExit,
5 unmodified lines
19 getWritableSubprocess,20 getReadableSubprocess,21 getReadWriteSubprocess,22} from '../helpers/convert.js';23import {foobarString, foobarBuffer, foobarObject, foobarObjectString} from '../helpers/input.js';23import {24 foobarString,25 foobarBuffer,26 foobarObject,27 foobarObjectString,28} from '../helpers/input.js';29import {prematureClose, fullReadableStdio} from '../helpers/stdio.js';30import {31 throwingGenerator,32 serializeGenerator,33 noopAsyncGenerator,34} from '../helpers/generator.js';35import {defaultHighWaterMark, defaultObjectHighWaterMark} from '../helpers/stream.js';3632setFixtureDir();37setFixtureDirectory();3839test('.writable() success', async t => {40 const subprocess = getWritableSubprocess();41 const stream = subprocess.writable();
353 unmodified lines
modified:test/fixtures/nested-double.js+5 added-5 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, ...args] = process.argv.slice(2);6const firstArgs = args.slice(0, -1);7const lastArg = args.at(-1);5const [options, file, ...commandArguments] = process.argv.slice(2);6const firstArguments = commandArguments.slice(0, -1);7const lastArgument = commandArguments.at(-1);8await Promise.all([9 execa(file, [...firstArgs, lastArg], JSON.parse(options)),10 execa(file, [...firstArgs, lastArg.toUpperCase()], JSON.parse(options)),9 execa(file, [...firstArguments, lastArgument], JSON.parse(options)),10 execa(file, [...firstArguments, lastArgument.toUpperCase()], JSON.parse(options)),11]);
modified:test/fixtures/nested-fail.js+3 added-3 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, ...args] = process.argv.slice(2);6const subprocess = execa(file, args, JSON.parse(options));7subprocess.kill(new Error(args[0]));5const [options, file, ...commandArguments] = process.argv.slice(2);6const subprocess = execa(file, commandArguments, JSON.parse(options));7subprocess.kill(new Error(commandArguments[0]));8await subprocess;
modified:test/fixtures/nested-file-url.js+2 added-2 removed
1 unmodified line
2import process from 'node:process';3import {pathToFileURL} from 'node:url';4import {execa} from '../../index.js';56const [options, file, arg] = process.argv.slice(2);6const [options, file, commandArgument] = process.argv.slice(2);7const parsedOptions = JSON.parse(options);8await execa(file, [arg], {...parsedOptions, stdout: pathToFileURL(parsedOptions.stdout)});8await execa(file, [commandArgument], {...parsedOptions, stdout: pathToFileURL(parsedOptions.stdout)});
modified:test/fixtures/nested-input.js+3 added-3 removed
1 unmodified line
2import process from 'node:process';3import {execa, execaSync} from '../../index.js';4import {foobarUtf16Uint8Array} from '../helpers/input.js';56const [optionsString, file, isSync, ...args] = process.argv.slice(2);6const [optionsString, file, isSync, ...commandArguments] = process.argv.slice(2);7const options = {...JSON.parse(optionsString), input: foobarUtf16Uint8Array};8if (isSync === 'true') {9 execaSync(file, args, options);9 execaSync(file, commandArguments, options);10} else {11 await execa(file, args, options);11 await execa(file, commandArguments, options);12}
modified:test/fixtures/nested-node.js+3 added-3 removed
1 unmodified line
2import process from 'node:process';3import {getWriteStream} from '../helpers/fs.js';4import {execa, execaNode} from '../../index.js';56const [fakeExecArgv, execaMethod, nodeOptions, file, ...args] = process.argv.slice(2);6const [fakeExecArgv, execaMethod, nodeOptions, file, ...commandArguments] = process.argv.slice(2);78if (fakeExecArgv !== '') {9 process.execArgv = [fakeExecArgv];10}1112const filteredNodeOptions = [nodeOptions].filter(Boolean);13const {stdout, stderr} = await (execaMethod === 'execaNode'14 ? execaNode(file, args, {nodeOptions: filteredNodeOptions})15 : execa(file, args, {nodeOptions: filteredNodeOptions, node: true}));14 ? execaNode(file, commandArguments, {nodeOptions: filteredNodeOptions})15 : execa(file, commandArguments, {nodeOptions: filteredNodeOptions, node: true}));16console.log(stdout);17getWriteStream(3).write(stderr);
modified:test/fixtures/nested-pipe-file.js+10 added-3 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [6 sourceOptions,7 sourceFile,8 sourceArgument,9 destinationOptions,10 destinationFile,11 destinationArgument,5const [sourceOptions, sourceFile, sourceArg, destinationOptions, destinationFile, destinationArg] = process.argv.slice(2);6await execa(sourceFile, [sourceArg], JSON.parse(sourceOptions))7 .pipe(destinationFile, destinationArg === undefined ? [] : [destinationArg], JSON.parse(destinationOptions));12] = process.argv.slice(2);13await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))14 .pipe(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions));
modified:test/fixtures/nested-pipe-script.js+10 added-3 removed
1#!/usr/bin/env node2import process from 'node:process';3import {$} from '../../index.js';45const [6 sourceOptions,7 sourceFile,8 sourceArgument,9 destinationOptions,10 destinationFile,11 destinationArgument,5const [sourceOptions, sourceFile, sourceArg, destinationOptions, destinationFile, destinationArg] = process.argv.slice(2);6await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArg}`7 .pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArg === undefined ? [] : [destinationArg]}`;12] = process.argv.slice(2);13await $(JSON.parse(sourceOptions))`${sourceFile} ${sourceArgument}`14 .pipe(JSON.parse(destinationOptions))`${destinationFile} ${destinationArgument === undefined ? [] : [destinationArgument]}`;
modified:test/fixtures/nested-pipe-stream.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg, unpipe] = process.argv.slice(2);6const subprocess = execa(file, [arg], JSON.parse(options));5const [options, file, commandArgument, unpipe] = process.argv.slice(2);6const subprocess = execa(file, [commandArgument], JSON.parse(options));7subprocess.stdout.pipe(process.stdout);8if (unpipe === 'true') {9 subprocess.stdout.unpipe(process.stdout);10}
2 unmodified lines
modified:test/fixtures/nested-pipe-subprocess.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg, unpipe] = process.argv.slice(2);6const source = execa(file, [arg], JSON.parse(options));5const [options, file, commandArgument, unpipe] = process.argv.slice(2);6const source = execa(file, [commandArgument], JSON.parse(options));7const destination = execa('stdin.js');8const controller = new AbortController();9const pipePromise = source.pipe(destination, {unpipeSignal: controller.signal});10if (unpipe === 'true') {
5 unmodified lines
modified:test/fixtures/nested-pipe-subprocesses.js+10 added-3 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [6 sourceOptions,7 sourceFile,8 sourceArgument,9 destinationOptions,10 destinationFile,11 destinationArgument,5const [sourceOptions, sourceFile, sourceArg, destinationOptions, destinationFile, destinationArg] = process.argv.slice(2);6await execa(sourceFile, [sourceArg], JSON.parse(sourceOptions))7 .pipe(execa(destinationFile, destinationArg === undefined ? [] : [destinationArg], JSON.parse(destinationOptions)));12] = process.argv.slice(2);13await execa(sourceFile, [sourceArgument], JSON.parse(sourceOptions))14 .pipe(execa(destinationFile, destinationArgument === undefined ? [] : [destinationArgument], JSON.parse(destinationOptions)));
modified:test/fixtures/nested-stdio.js+2 added-2 removed
1 unmodified line
2import process from 'node:process';3import {execa, execaSync} from '../../index.js';4import {parseStdioOption} from '../helpers/stdio.js';56const [stdioOption, fdNumber, isSyncString, file, ...args] = process.argv.slice(2);6const [stdioOption, fdNumber, isSyncString, file, ...commandArguments] = process.argv.slice(2);7const optionValue = parseStdioOption(stdioOption);8const isSync = isSyncString === 'true';9const stdio = ['ignore', 'inherit', 'inherit'];10stdio[fdNumber] = optionValue;11const execaMethod = isSync ? execaSync : execa;12const returnValue = execaMethod(file, [`${fdNumber}`, ...args], {stdio});12const returnValue = execaMethod(file, [`${fdNumber}`, ...commandArguments], {stdio});1314const shouldPipe = Array.isArray(optionValue) && optionValue.includes('pipe');15const fdReturnValue = returnValue.stdio[fdNumber];16const hasPipe = fdReturnValue !== undefined && fdReturnValue !== null;
12 unmodified lines
modified:test/fixtures/nested-sync-tty.js+4 added-4 removed
2 unmodified lines
3import tty from 'node:tty';4import {execa, execaSync} from '../../index.js';56const mockIsatty = fdNumber => {7 tty.isatty = fdNumberArg => fdNumber === fdNumberArg;7 tty.isatty = fdNumberArgument => fdNumber === fdNumberArgument;8};910const originalIsatty = tty.isatty;11const unmockIsatty = () => {12 tty.isatty = originalIsatty;13};1415const [options, isSync, file, fdNumber, ...args] = process.argv.slice(2);15const [options, isSync, file, fdNumber, ...commandArguments] = process.argv.slice(2);16mockIsatty(Number(fdNumber));1718try {19 if (isSync === 'true') {20 execaSync(file, [fdNumber, ...args], JSON.parse(options));20 execaSync(file, [fdNumber, ...commandArguments], JSON.parse(options));21 } else {22 await execa(file, [fdNumber, ...args], JSON.parse(options));22 await execa(file, [fdNumber, ...commandArguments], JSON.parse(options));23 }24} finally {25 unmockIsatty();26}
modified:test/fixtures/nested-sync.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execaSync} from '../../index.js';45const [options, file, ...args] = process.argv.slice(2);5const [options, file, ...commandArguments] = process.argv.slice(2);6try {7 const result = execaSync(file, args, JSON.parse(options));7 const result = execaSync(file, commandArguments, JSON.parse(options));8 process.send({result});9} catch (error) {10 process.send({error});11}
modified:test/fixtures/nested-transform.js+3 added-3 removed
22 unmodified lines
23 return getOutputGenerator(bigArray)(true);24 }25};2627const [optionsString, file, ...args] = process.argv.slice(2);27const [optionsString, file, ...commandArguments] = process.argv.slice(2);28const {type, transformName, isSync, ...options} = JSON.parse(optionsString);29const newOptions = {stdout: getTransform(type, transformName), ...options};30if (isSync) {31 execaSync(file, args, newOptions);31 execaSync(file, commandArguments, newOptions);32} else {33 await execa(file, args, newOptions);33 await execa(file, commandArguments, newOptions);34}
modified:test/fixtures/nested-writable-web.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg] = process.argv.slice(2);6await execa(file, [arg], {...JSON.parse(options), stdout: new WritableStream()});5const [options, file, commandArgument] = process.argv.slice(2);6await execa(file, [commandArgument], {...JSON.parse(options), stdout: new WritableStream()});
modified:test/fixtures/nested-writable.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, arg] = process.argv.slice(2);6await execa(file, [arg], {...JSON.parse(options), stdout: process.stdout});5const [options, file, commandArgument] = process.argv.slice(2);6await execa(file, [commandArgument], {...JSON.parse(options), stdout: process.stdout});
modified:test/fixtures/nested.js+2 added-2 removed
1#!/usr/bin/env node2import process from 'node:process';3import {execa} from '../../index.js';45const [options, file, ...args] = process.argv.slice(2);5const [options, file, ...commandArguments] = process.argv.slice(2);6try {7 const result = await execa(file, args, JSON.parse(options));7 const result = await execa(file, commandArguments, JSON.parse(options));8 process.send({result});9} catch (error) {10 process.send({error});11}
modified:test/fixtures/no-await.js+2 added-2 removed
1 unmodified line
2import process from 'node:process';3import {once} from 'node:events';4import {execa} from '../../index.js';56const [options, file, ...args] = process.argv.slice(2);7execa(file, args, JSON.parse(options));6const [options, file, ...commandArguments] = process.argv.slice(2);7execa(file, commandArguments, JSON.parse(options));8const [error] = await once(process, 'unhandledRejection');9console.log(error.shortMessage);
modified:test/fixtures/stdin-script.js+2 added-2 removed
1#!/usr/bin/env node2import {$} from '../../index.js';3import {FIXTURES_DIR} from '../helpers/fixtures-dir.js';3import {FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';45await $({stdout: 'inherit'})`node ${`${FIXTURES_DIR}/stdin.js`}`;5await $({stdout: 'inherit'})`node ${`${FIXTURES_DIRECTORY}/stdin.js`}`;
modified:test/fixtures/worker.js+4 added-4 removed
1import {once} from 'node:events';2import {workerData, parentPort} from 'node:worker_threads';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();78const {nodeFile, args, options} = workerData;8const {nodeFile, commandArguments, options} = workerData;9try {10 const subprocess = execa(nodeFile, args, options);10 const subprocess = execa(nodeFile, commandArguments, options);11 const [parentResult, [{result, error}]] = await Promise.all([subprocess, once(subprocess, 'message')]);12 parentPort.postMessage({parentResult, result, error});13} catch (parentError) {14 parentPort.postMessage({parentError});
1 unmodified line
deleted:test/helpers/fixtures-dir.js-15 removed
1import {delimiter, resolve} from 'node:path';2import process from 'node:process';3import {fileURLToPath} from 'node:url';4import pathKey from 'path-key';56export const PATH_KEY = pathKey();7export const FIXTURES_DIR_URL = new URL('../fixtures/', import.meta.url);8export const FIXTURES_DIR = resolve(fileURLToPath(FIXTURES_DIR_URL));910// Add the fixtures directory to PATH so fixtures can be executed without adding11// `node`. This is only meant to make writing tests simpler.12export const setFixtureDir = () => {13 process.env[PATH_KEY] = FIXTURES_DIR + delimiter + process.env[PATH_KEY];14};15
added:test/helpers/fixtures-directory.js+15 added
1import {delimiter, resolve} from 'node:path';2import process from 'node:process';3import {fileURLToPath} from 'node:url';4import pathKey from 'path-key';56export const PATH_KEY = pathKey();7export const FIXTURES_DIRECTORY_URL = new URL('../fixtures/', import.meta.url);8export const FIXTURES_DIRECTORY = resolve(fileURLToPath(FIXTURES_DIRECTORY_URL));910// Add the fixtures directory to PATH so fixtures can be executed without adding11// `node`. This is only meant to make writing tests simpler.12export const setFixtureDirectory = () => {13 process.env[PATH_KEY] = FIXTURES_DIRECTORY + delimiter + process.env[PATH_KEY];14};15
modified:test/helpers/generator.js+6 added-1 removed
1import {setImmediate, setInterval, setTimeout, scheduler} from 'node:timers/promises';1import {2 setImmediate,3 setInterval,4 setTimeout,5 scheduler,6} from 'node:timers/promises';7import {foobarObject, foobarString} from './input.js';89const getGenerator = transform => (objectMode, binary, preserveNewlines) => ({10 transform,
108 unmodified lines
modified:test/helpers/nested.js+20 added-16 removed
1import {once} from 'node:events';2import {Worker} from 'node:worker_threads';3import {execa} from '../../index.js';4import {FIXTURES_DIR_URL} from './fixtures-dir.js';4import {FIXTURES_DIRECTORY_URL} from './fixtures-directory.js';56const WORKER_URL = new URL('worker.js', FIXTURES_DIR_URL);6const WORKER_URL = new URL('worker.js', FIXTURES_DIRECTORY_URL);78const runWorker = (nodeFile, args, options) => {9 [args, options] = Array.isArray(args) ? [args, options] : [[], args];10 return new Worker(WORKER_URL, {workerData: {nodeFile, args, options}});8const runWorker = (nodeFile, commandArguments, options) => {9 [commandArguments, options] = Array.isArray(commandArguments)10 ? [commandArguments, options]11 : [[], commandArguments];12 return new Worker(WORKER_URL, {workerData: {nodeFile, commandArguments, options}});13};1415// eslint-disable-next-line max-params14const nestedCall = (isWorker, fixtureName, execaMethod, file, args, options, parentOptions) => {15 [args, options = {}, parentOptions = {}] = Array.isArray(args) ? [args, options, parentOptions] : [[], args, options];16 const subprocessOrWorker = execaMethod(fixtureName, [JSON.stringify(options), file, ...args], {...parentOptions, ipc: true});16const nestedCall = (isWorker, fixtureName, execaMethod, file, commandArguments, options, parentOptions) => {17 [commandArguments, options = {}, parentOptions = {}] = Array.isArray(commandArguments)18 ? [commandArguments, options, parentOptions]19 : [[], commandArguments, options];20 const subprocessOrWorker = execaMethod(fixtureName, [JSON.stringify(options), file, ...commandArguments], {...parentOptions, ipc: true});21 const onMessage = once(subprocessOrWorker, 'message');22 const promise = getNestedResult(onMessage);23 promise.parent = isWorker ? getParentResult(onMessage) : subprocessOrWorker;24 return promise;
17 unmodified lines
4243 return {result, parentResult};44};4542export const nestedWorker = (...args) => nestedCall(true, 'nested.js', runWorker, ...args);43const nestedExeca = (fixtureName, ...args) => nestedCall(false, fixtureName, execa, ...args);44export const nestedExecaAsync = (...args) => nestedExeca('nested.js', ...args);45export const nestedExecaSync = (...args) => nestedExeca('nested-sync.js', ...args);46export const parentWorker = (...args) => nestedWorker(...args).parent;47export const parentExeca = (...args) => nestedExeca(...args).parent;48export const parentExecaAsync = (...args) => nestedExecaAsync(...args).parent;49export const parentExecaSync = (...args) => nestedExecaSync(...args).parent;46export const nestedWorker = (...commandArguments) => nestedCall(true, 'nested.js', runWorker, ...commandArguments);47const nestedExeca = (fixtureName, ...commandArguments) => nestedCall(false, fixtureName, execa, ...commandArguments);48export const nestedExecaAsync = (...commandArguments) => nestedExeca('nested.js', ...commandArguments);49export const nestedExecaSync = (...commandArguments) => nestedExeca('nested-sync.js', ...commandArguments);50export const parentWorker = (...commandArguments) => nestedWorker(...commandArguments).parent;51export const parentExeca = (...commandArguments) => nestedExeca(...commandArguments).parent;52export const parentExecaAsync = (...commandArguments) => nestedExecaAsync(...commandArguments).parent;53export const parentExecaSync = (...commandArguments) => nestedExecaSync(...commandArguments).parent;
modified:test/helpers/stream.js+6 added-1 removed
1import {Readable, Writable, PassThrough, getDefaultHighWaterMark} from 'node:stream';1import {2 Readable,3 Writable,4 PassThrough,5 getDefaultHighWaterMark,6} from 'node:stream';7import {foobarString} from './input.js';89export const noopReadable = () => new Readable({read() {}});10export const noopWritable = () => new Writable({write() {}});
5 unmodified lines
modified:test/io/input-option.js+15 added-4 removed
1import {Writable} from 'node:stream';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';6import {foobarUint8Array, foobarBuffer, foobarArrayBuffer, foobarUint16Array, foobarDataView} from '../helpers/input.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {6 runExeca,7 runExecaSync,8 runScript,9 runScriptSync,10} from '../helpers/run.js';11import {12 foobarUint8Array,13 foobarBuffer,14 foobarArrayBuffer,15 foobarUint16Array,16 foobarDataView,17} from '../helpers/input.js';188setFixtureDir();19setFixtureDirectory();2021const testInput = async (t, input, execaMethod) => {22 const {stdout} = await execaMethod('stdin.js', {input});23 t.is(stdout, 'foobar');
31 unmodified lines
modified:test/io/input-sync.js+2 added-2 removed
1import test from 'ava';2import {execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getStdio} from '../helpers/stdio.js';56setFixtureDir();6setFixtureDirectory();78const getFd3InputMessage = type => `not \`stdio[3]\`, can be ${type}`;910const testFd3InputSync = (t, stdioOption, expectedMessage) => {
8 unmodified lines
modified:test/io/iterate.js+8 added-3 removed
1import {once} from 'node:events';2import {getDefaultHighWaterMark} from 'node:stream';3import test from 'ava';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {6 assertStreamOutput,7 assertIterableChunks,8 assertStreamChunks,
20 unmodified lines
29 complexChunksEnd,30} from '../helpers/lines.js';31import {outputObjectGenerator, getOutputGenerator} from '../helpers/generator.js';32import {foobarString, foobarObject} from '../helpers/input.js';33import {multibyteChar, multibyteUint8Array, breakingLength, brokenSymbol} from '../helpers/encoding.js';33import {34 multibyteChar,35 multibyteUint8Array,36 breakingLength,37 brokenSymbol,38} from '../helpers/encoding.js';3935setFixtureDir();40setFixtureDirectory();4142const foobarObjectChunks = [foobarObject, foobarObject, foobarObject];4344const getSubprocess = (methodName, output, options) => {
162 unmodified lines
modified:test/io/max-buffer.js+8 added-3 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import getStream from 'get-stream';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {fullStdio} from '../helpers/stdio.js';7import {getEarlyErrorSubprocess, getEarlyErrorSubprocessSync} from '../helpers/early-error.js';8import {maxBuffer, assertErrorMessage} from '../helpers/max-buffer.js';910setFixtureDir();10setFixtureDirectory();1112const maxBufferMessage = {message: /maxBuffer exceeded/};13const maxBufferCodeSync = {code: 'ENOBUFS'};14
126 unmodified lines
141 const maxBufferStderr = 4 - difference;142 const {isMaxBuffer, shortMessage, stdout, stderr, all} = await execa(143 'noop-both.js',144 ['\n'.repeat(maxBufferStdout - 1), '\n'.repeat(maxBufferStderr - difference)],145 {maxBuffer: {stdout: maxBufferStdout, stderr: maxBufferStderr}, all: true, stripFinalNewline: false, reject: false},145 {146 maxBuffer: {stdout: maxBufferStdout, stderr: maxBufferStderr},147 all: true,148 stripFinalNewline: false,149 reject: false,150 },151 );152 t.is(isMaxBuffer, shouldFail);153 if (shouldFail) {154 assertErrorMessage(t, shortMessage, {fdNumber: 2, length: maxBufferStderr});
116 unmodified lines
modified:test/io/output-async.js+2 added-2 removed
3 unmodified lines
4import test from 'ava';5import {execa} from '../../index.js';6import {STANDARD_STREAMS} from '../helpers/stdio.js';7import {foobarString} from '../helpers/input.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {assertMaxListeners} from '../helpers/listeners.js';1011setFixtureDir();11setFixtureDirectory();1213const getStandardStreamListeners = stream => Object.fromEntries(stream.eventNames().map(eventName => [eventName, stream.listeners(eventName)]));14const getStandardStreamsListeners = () => STANDARD_STREAMS.map(stream => getStandardStreamListeners(stream));15
69 unmodified lines
modified:test/io/output-sync.js+2 added-2 removed
1import test from 'ava';2import {execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {throwingGenerator} from '../helpers/generator.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89test('Handles errors with stdout generator, sync', t => {10 const cause = new Error(foobarString);11 const error = t.throws(() => {
22 unmodified lines
modified:test/io/pipeline.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {getStdio, STANDARD_STREAMS} from '../helpers/stdio.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();78const testDestroyStandard = async (t, fdNumber) => {9 const subprocess = execa('forever.js', {...getStdio(fdNumber, [STANDARD_STREAMS[fdNumber], 'pipe']), timeout: 1});10 await t.throwsAsync(subprocess, {message: /timed out/});
28 unmodified lines
modified:test/io/strip-newline.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {fullStdio} from '../helpers/stdio.js';5import {noopGenerator} from '../helpers/generator.js';6import {foobarString} from '../helpers/input.js';78setFixtureDir();8setFixtureDirectory();910// eslint-disable-next-line max-params11const testStripFinalNewline = async (t, fdNumber, stripFinalNewline, shouldStrip, execaMethod) => {12 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, `${foobarString}\n`], {...fullStdio, stripFinalNewline});
44 unmodified lines
modified:test/methods/command.js+9 added-9 removed
1import {join} from 'node:path';2import test from 'ava';3import {execaCommand, execaCommandSync} from '../../index.js';4import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';5import {QUOTE} from '../helpers/verbose.js';67setFixtureDir();8const STDIN_FIXTURE = join(FIXTURES_DIR, 'stdin.js');7setFixtureDirectory();8const STDIN_FIXTURE = join(FIXTURES_DIRECTORY, 'stdin.js');910test('execaCommand()', async t => {11 const {stdout} = await execaCommand('echo.js foo bar');12 t.is(stdout, 'foo\nbar');
78 unmodified lines
91 const {stdout} = await execaCommand(' echo.js foo bar ');92 t.is(stdout, 'foo\nbar');93});9495const testInvalidArgsArray = (t, execaMethod) => {95const testInvalidArgumentsArray = (t, execaMethod) => {96 t.throws(() => {97 execaMethod('echo', ['foo']);98 }, {message: /The command and its arguments must be passed as a single string/});99};100101test('execaCommand() must not pass an array of arguments', testInvalidArgsArray, execaCommand);102test('execaCommandSync() must not pass an array of arguments', testInvalidArgsArray, execaCommandSync);101test('execaCommand() must not pass an array of arguments', testInvalidArgumentsArray, execaCommand);102test('execaCommandSync() must not pass an array of arguments', testInvalidArgumentsArray, execaCommandSync);103104const testInvalidArgsTemplate = (t, execaMethod) => {104const testInvalidArgumentsTemplate = (t, execaMethod) => {105 t.throws(() => {106 // eslint-disable-next-line no-unused-expressions107 execaMethod`echo foo`;108 }, {message: /The command and its arguments must be passed as a single string/});109};110111test('execaCommand() must not pass an array of arguments with a template string', testInvalidArgsTemplate, execaCommand);112test('execaCommandSync() must not pass an array of arguments with a template string', testInvalidArgsTemplate, execaCommandSync);111test('execaCommand() must not pass an array of arguments with a template string', testInvalidArgumentsTemplate, execaCommand);112test('execaCommandSync() must not pass an array of arguments with a template string', testInvalidArgumentsTemplate, execaCommandSync);
modified:test/methods/create-bind.js+10 added-5 removed
1import {join} from 'node:path';2import test from 'ava';3import {execa, execaSync, execaNode, $} from '../../index.js';3import {4 execa,5 execaSync,6 execaNode,7 $,8} from '../../index.js';9import {foobarString, foobarUppercase} from '../helpers/input.js';10import {uppercaseGenerator} from '../helpers/generator.js';6import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';11import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';128setFixtureDir();13setFixtureDirectory();1410const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');11const PRINT_ENV_PATH = join(FIXTURES_DIR, 'environment.js');15const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');16const PRINT_ENV_PATH = join(FIXTURES_DIRECTORY, 'environment.js');1718const testBindOptions = async (t, execaMethod) => {19 const {stdout} = await execaMethod({stripFinalNewline: false})(NOOP_PATH, [foobarString]);20 t.is(stdout, `${foobarString}\n`);
89 unmodified lines
modified:test/methods/create-main.js+12 added-7 removed
1import {join} from 'node:path';2import test from 'ava';3import {execa, execaSync, execaNode, $} from '../../index.js';3import {4 execa,5 execaSync,6 execaNode,7 $,8} from '../../index.js';9import {foobarString, foobarArray} from '../helpers/input.js';5import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';10import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';117setFixtureDir();12setFixtureDirectory();139const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');14const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');1516const testTemplate = async (t, execaMethod) => {17 const {stdout} = await execaMethod`${NOOP_PATH} ${foobarString}`;18 t.is(stdout, foobarString);
27 unmodified lines
4647test('execaSync() can use template strings with options', testTemplateOptionsSync, execaSync);48test('$.sync can use template strings with options', testTemplateOptionsSync, $.sync);4945const testSpacedCommand = async (t, args, execaMethod) => {46 const {stdout} = await execaMethod('command with space.js', args);47 const expectedStdout = args === undefined ? '' : args.join('\n');50const testSpacedCommand = async (t, commandArguments, execaMethod) => {51 const {stdout} = await execaMethod('command with space.js', commandArguments);52 const expectedStdout = commandArguments === undefined ? '' : commandArguments.join('\n');53 t.is(stdout, expectedStdout);54};5556test('allow commands with spaces and no array arguments', testSpacedCommand, undefined, execa);
7 unmodified lines
modified:test/methods/main-async.js+2 added-2 removed
1import process from 'node:process';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();78const isWindows = process.platform === 'win32';910if (isWindows) {
16 unmodified lines
modified:test/methods/node.js+7 added-7 removed
4 unmodified lines
5import test from 'ava';6import getNode from 'get-node';7import {pEvent} from 'p-event';8import {execa, execaSync, execaNode} from '../../index.js';9import {FIXTURES_DIR} from '../helpers/fixtures-dir.js';9import {FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';10import {identity, fullStdio} from '../helpers/stdio.js';11import {foobarString} from '../helpers/input.js';1213process.chdir(FIXTURES_DIR);13process.chdir(FIXTURES_DIRECTORY);1415const runWithNodeOption = (file, args, options) => Array.isArray(args)16 ? execa(file, args, {...options, node: true})15const runWithNodeOption = (file, commandArguments, options) => Array.isArray(commandArguments)16 ? execa(file, commandArguments, {...options, node: true})17 : execa(file, {...options, node: true});18const runWithNodeOptionSync = (file, args, options) => Array.isArray(args)19 ? execaSync(file, args, {...options, node: true})18const runWithNodeOptionSync = (file, commandArguments, options) => Array.isArray(commandArguments)19 ? execaSync(file, commandArguments, {...options, node: true})20 : execaSync(file, {...options, node: true});21const runWithIpc = (file, options) => execa('node', [file], {...options, ipc: true});2223const testNodeSuccess = async (t, execaMethod) => {
163 unmodified lines
187188const spawnNestedExecaNode = (realExecArgv, fakeExecArgv, execaMethod, nodeOptions) => execa(189 'node',190 [...realExecArgv, 'nested-node.js', fakeExecArgv, execaMethod, nodeOptions, 'noop.js', foobarString],191 {...fullStdio, cwd: FIXTURES_DIR},191 {...fullStdio, cwd: FIXTURES_DIRECTORY},192);193194const testInspectRemoval = async (t, fakeExecArgv, execaMethod) => {195 const {stdout, stdio} = await spawnNestedExecaNode([], fakeExecArgv, execaMethod, '');
110 unmodified lines
modified:test/methods/override-promise.js+2 added-2 removed
1import test from 'ava';2// The helper module overrides Promise on import so has to be imported before `execa`.3import {restorePromise} from '../helpers/override-promise.js';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';67restorePromise();8setFixtureDir();8setFixtureDirectory();910test('should work with third-party Promise', async t => {11 const {stdout} = await execa('noop.js', ['foo']);12 t.is(stdout, 'foo');
1 unmodified line
modified:test/methods/parameters-args.js+34 added-27 removed
1import test from 'ava';2import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';2import {3 execa,4 execaSync,5 execaCommand,6 execaCommandSync,7 execaNode,8 $,9} from '../../index.js';10import {setFixtureDirectory} from '../helpers/fixtures-directory.js';115setFixtureDir();12setFixtureDirectory();137const testInvalidArgs = async (t, execaMethod) => {14const testInvalidArguments = async (t, execaMethod) => {15 t.throws(() => {16 execaMethod('echo', true);17 }, {message: /Second argument must be either/});18};1913test('execa()\'s second argument must be valid', testInvalidArgs, execa);14test('execaSync()\'s second argument must be valid', testInvalidArgs, execaSync);15test('execaCommand()\'s second argument must be valid', testInvalidArgs, execaCommand);16test('execaCommandSync()\'s second argument must be valid', testInvalidArgs, execaCommandSync);17test('execaNode()\'s second argument must be valid', testInvalidArgs, execaNode);18test('$\'s second argument must be valid', testInvalidArgs, $);19test('$.sync\'s second argument must be valid', testInvalidArgs, $.sync);20test('execa()\'s second argument must be valid', testInvalidArguments, execa);21test('execaSync()\'s second argument must be valid', testInvalidArguments, execaSync);22test('execaCommand()\'s second argument must be valid', testInvalidArguments, execaCommand);23test('execaCommandSync()\'s second argument must be valid', testInvalidArguments, execaCommandSync);24test('execaNode()\'s second argument must be valid', testInvalidArguments, execaNode);25test('$\'s second argument must be valid', testInvalidArguments, $);26test('$.sync\'s second argument must be valid', testInvalidArguments, $.sync);2721const testInvalidArgsItems = async (t, execaMethod) => {28const testInvalidArgumentsItems = async (t, execaMethod) => {29 t.throws(() => {30 execaMethod('echo', [{}]);31 }, {message: 'Second argument must be an array of strings: [object Object]'});32};3327test('execa()\'s second argument must not be objects', testInvalidArgsItems, execa);28test('execaSync()\'s second argument must not be objects', testInvalidArgsItems, execaSync);29test('execaCommand()\'s second argument must not be objects', testInvalidArgsItems, execaCommand);30test('execaCommandSync()\'s second argument must not be objects', testInvalidArgsItems, execaCommandSync);31test('execaNode()\'s second argument must not be objects', testInvalidArgsItems, execaNode);32test('$\'s second argument must not be objects', testInvalidArgsItems, $);33test('$.sync\'s second argument must not be objects', testInvalidArgsItems, $.sync);34test('execa()\'s second argument must not be objects', testInvalidArgumentsItems, execa);35test('execaSync()\'s second argument must not be objects', testInvalidArgumentsItems, execaSync);36test('execaCommand()\'s second argument must not be objects', testInvalidArgumentsItems, execaCommand);37test('execaCommandSync()\'s second argument must not be objects', testInvalidArgumentsItems, execaCommandSync);38test('execaNode()\'s second argument must not be objects', testInvalidArgumentsItems, execaNode);39test('$\'s second argument must not be objects', testInvalidArgumentsItems, $);40test('$.sync\'s second argument must not be objects', testInvalidArgumentsItems, $.sync);4135const testNullByteArg = async (t, execaMethod) => {42const testNullByteArgument = async (t, execaMethod) => {43 t.throws(() => {44 execaMethod('echo', ['a\0b']);45 }, {message: /null bytes/});46};4741test('execa()\'s second argument must not include \\0', testNullByteArg, execa);42test('execaSync()\'s second argument must not include \\0', testNullByteArg, execaSync);43test('execaCommand()\'s second argument must not include \\0', testNullByteArg, execaCommand);44test('execaCommandSync()\'s second argument must not include \\0', testNullByteArg, execaCommandSync);45test('execaNode()\'s second argument must not include \\0', testNullByteArg, execaNode);46test('$\'s second argument must not include \\0', testNullByteArg, $);47test('$.sync\'s second argument must not include \\0', testNullByteArg, $.sync);48test('execa()\'s second argument must not include \\0', testNullByteArgument, execa);49test('execaSync()\'s second argument must not include \\0', testNullByteArgument, execaSync);50test('execaCommand()\'s second argument must not include \\0', testNullByteArgument, execaCommand);51test('execaCommandSync()\'s second argument must not include \\0', testNullByteArgument, execaCommandSync);52test('execaNode()\'s second argument must not include \\0', testNullByteArgument, execaNode);53test('$\'s second argument must not include \\0', testNullByteArgument, $);54test('$.sync\'s second argument must not include \\0', testNullByteArgument, $.sync);
modified:test/methods/parameters-command.js+16 added-9 removed
1import {join, basename} from 'node:path';2import {fileURLToPath} from 'node:url';3import test from 'ava';4import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';5import {setFixtureDir, FIXTURES_DIR_URL} from '../helpers/fixtures-dir.js';4import {5 execa,6 execaSync,7 execaCommand,8 execaCommandSync,9 execaNode,10 $,11} from '../../index.js';12import {setFixtureDirectory, FIXTURES_DIRECTORY_URL} from '../helpers/fixtures-directory.js';13import {foobarString} from '../helpers/input.js';148setFixtureDir();15setFixtureDirectory();1617const testFileUrl = async (t, execaMethod) => {11 const command = new URL('noop.js', FIXTURES_DIR_URL);18 const command = new URL('noop.js', FIXTURES_DIRECTORY_URL);19 const {stdout} = await execaMethod(command);20 t.is(stdout, foobarString);21};22
19 unmodified lines
42test('execaNode()\'s command argument cannot be a non-file URL', testInvalidFileUrl, execaNode);43test('$\'s command argument cannot be a non-file URL', testInvalidFileUrl, $);44test('$.sync\'s command argument cannot be a non-file URL', testInvalidFileUrl, $.sync);4539const testInvalidCommand = async (t, arg, execaMethod) => {46const testInvalidCommand = async (t, commandArgument, execaMethod) => {47 t.throws(() => {41 execaMethod(arg);48 execaMethod(commandArgument);49 }, {message: /First argument must be a string or a file URL/});50};5152test('execa()\'s first argument must be defined', testInvalidCommand, undefined, execa);
18 unmodified lines
71test('$\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $);72test('$.sync\'s command argument must be a string or file URL', testInvalidCommand, ['command', 'arg'], $.sync);7374const testRelativePath = async (t, execaMethod) => {68 const rootDir = basename(fileURLToPath(new URL('../..', import.meta.url)));69 const pathViaParentDir = join('..', rootDir, 'test', 'fixtures', 'noop.js');70 const {stdout} = await execaMethod(pathViaParentDir);75 const rootDirectory = basename(fileURLToPath(new URL('../..', import.meta.url)));76 const pathViaParentDirectory = join('..', rootDirectory, 'test', 'fixtures', 'noop.js');77 const {stdout} = await execaMethod(pathViaParentDirectory);78 t.is(stdout, foobarString);79};8081test('execa() use relative path with \'..\' chars', testRelativePath, execa);
6 unmodified lines
modified:test/methods/parameters-options.js+54 added-47 removed
1import {join} from 'node:path';2import test from 'ava';3import {execa, execaSync, execaCommand, execaCommandSync, execaNode, $} from '../../index.js';4import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';3import {4 execa,5 execaSync,6 execaCommand,7 execaCommandSync,8 execaNode,9 $,10} from '../../index.js';11import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';126setFixtureDir();13setFixtureDirectory();148const NOOP_PATH = join(FIXTURES_DIR, 'noop.js');15const NOOP_PATH = join(FIXTURES_DIRECTORY, 'noop.js');1610const testSerializeArg = async (t, arg, execaMethod) => {11 const {stdout} = await execaMethod(NOOP_PATH, [arg]);12 t.is(stdout, String(arg));17const testSerializeArgument = async (t, commandArgument, execaMethod) => {18 const {stdout} = await execaMethod(NOOP_PATH, [commandArgument]);19 t.is(stdout, String(commandArgument));20};2115test('execa()\'s arguments can be numbers', testSerializeArg, 1, execa);16test('execa()\'s arguments can be booleans', testSerializeArg, true, execa);17test('execa()\'s arguments can be NaN', testSerializeArg, Number.NaN, execa);18test('execa()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execa);19test('execa()\'s arguments can be null', testSerializeArg, null, execa);20test('execa()\'s arguments can be undefined', testSerializeArg, undefined, execa);21test('execa()\'s arguments can be bigints', testSerializeArg, 1n, execa);22test('execa()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execa);23test('execaSync()\'s arguments can be numbers', testSerializeArg, 1, execaSync);24test('execaSync()\'s arguments can be booleans', testSerializeArg, true, execaSync);25test('execaSync()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaSync);26test('execaSync()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaSync);27test('execaSync()\'s arguments can be null', testSerializeArg, null, execaSync);28test('execaSync()\'s arguments can be undefined', testSerializeArg, undefined, execaSync);29test('execaSync()\'s arguments can be bigints', testSerializeArg, 1n, execaSync);30test('execaSync()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaSync);31test('execaNode()\'s arguments can be numbers', testSerializeArg, 1, execaNode);32test('execaNode()\'s arguments can be booleans', testSerializeArg, true, execaNode);33test('execaNode()\'s arguments can be NaN', testSerializeArg, Number.NaN, execaNode);34test('execaNode()\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, execaNode);35test('execaNode()\'s arguments can be null', testSerializeArg, null, execaNode);36test('execaNode()\'s arguments can be undefined', testSerializeArg, undefined, execaNode);37test('execaNode()\'s arguments can be bigints', testSerializeArg, 1n, execaNode);38test('execaNode()\'s arguments can be symbols', testSerializeArg, Symbol('test'), execaNode);39test('$\'s arguments can be numbers', testSerializeArg, 1, $);40test('$\'s arguments can be booleans', testSerializeArg, true, $);41test('$\'s arguments can be NaN', testSerializeArg, Number.NaN, $);42test('$\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $);43test('$\'s arguments can be null', testSerializeArg, null, $);44test('$\'s arguments can be undefined', testSerializeArg, undefined, $);45test('$\'s arguments can be bigints', testSerializeArg, 1n, $);46test('$\'s arguments can be symbols', testSerializeArg, Symbol('test'), $);47test('$.sync\'s arguments can be numbers', testSerializeArg, 1, $.sync);48test('$.sync\'s arguments can be booleans', testSerializeArg, true, $.sync);49test('$.sync\'s arguments can be NaN', testSerializeArg, Number.NaN, $.sync);50test('$.sync\'s arguments can be Infinity', testSerializeArg, Number.POSITIVE_INFINITY, $.sync);51test('$.sync\'s arguments can be null', testSerializeArg, null, $.sync);52test('$.sync\'s arguments can be undefined', testSerializeArg, undefined, $.sync);53test('$.sync\'s arguments can be bigints', testSerializeArg, 1n, $.sync);54test('$.sync\'s arguments can be symbols', testSerializeArg, Symbol('test'), $.sync);22test('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);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);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);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, $);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);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);6263const testInvalidOptions = async (t, execaMethod) => {64 t.throws(() => {65 execaMethod('echo', [], new Map());
10 unmodified lines
modified:test/methods/promise.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';45setFixtureDir();5setFixtureDirectory();67test('promise methods are not enumerable', t => {8 const descriptors = Object.getOwnPropertyDescriptors(execa('noop.js'));9 t.false(descriptors.then.enumerable);
44 unmodified lines
modified:test/methods/script.js+2 added-2 removed
1import test from 'ava';2import {isStream} from 'is-stream';3import {$} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89const testScriptStdoutSync = (t, getSubprocess, expectedStdout) => {10 const {stdout} = getSubprocess();11 t.is(stdout, expectedStdout);
48 unmodified lines
modified:test/methods/template.js+2 added-2 removed
1import test from 'ava';2import {$} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';45setFixtureDir();5setFixtureDirectory();67// Workaround since some text editors or IDEs do not allow inputting \r directly8const escapedCall = string => {9 const templates = [string];
320 unmodified lines
modified:test/pipe/abort.js+2 added-2 removed
1import {once} from 'node:events';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89const assertUnPipeError = async (t, pipePromise) => {10 const error = await t.throwsAsync(pipePromise);11
156 unmodified lines
modified:test/pipe/pipe-arguments.js+11 added-11 removed
1import {spawn} from 'node:child_process';2import {pathToFileURL} from 'node:url';3import test from 'ava';4import {$, execa} from '../../index.js';5import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';6import {foobarString} from '../helpers/input.js';78setFixtureDir();8setFixtureDirectory();910test('$.pipe(subprocess)', async t => {11 const {stdout} = await $`noop.js ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`);12 t.is(stdout, foobarString);
45 unmodified lines
58 t.is(stdout, foobarString);59});6061test('execa.$.pipe(fileUrl)`', async t => {62 const {stdout} = await execa('noop.js', [foobarString]).pipe(pathToFileURL(`${FIXTURES_DIR}/stdin.js`));62 const {stdout} = await execa('noop.js', [foobarString]).pipe(pathToFileURL(`${FIXTURES_DIRECTORY}/stdin.js`));63 t.is(stdout, foobarString);64});6566test('$.pipe("file", args, options)', async t => {67 const {stdout} = await $`noop.js ${foobarString}`.pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});66test('$.pipe("file", commandArguments, options)', async t => {67 const {stdout} = await $`noop.js ${foobarString}`.pipe('node', ['stdin.js'], {cwd: FIXTURES_DIRECTORY});68 t.is(stdout, foobarString);69});7071test('execa.$.pipe("file", args, options)`', async t => {72 const {stdout} = await execa('noop.js', [foobarString]).pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});71test('execa.$.pipe("file", commandArguments, options)`', async t => {72 const {stdout} = await execa('noop.js', [foobarString]).pipe('node', ['stdin.js'], {cwd: FIXTURES_DIRECTORY});73 t.is(stdout, foobarString);74});7576test('$.pipe.pipe("file", args, options)', async t => {76test('$.pipe.pipe("file", commandArguments, options)', async t => {77 const {stdout} = await $`noop.js ${foobarString}`78 .pipe`stdin.js`79 .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});79 .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIRECTORY});80 t.is(stdout, foobarString);81});8283test('$.pipe(subprocess, pipeOptions)', async t => {
176 unmodified lines
260 {message: /Please use \.pipe/},261 );262});263264const testInvalidPipe = async (t, ...args) => {264const testInvalidPipe = async (t, ...pipeArguments) => {265 await t.throwsAsync(266 $`empty.js`.pipe(...args),266 $`empty.js`.pipe(...pipeArguments),267 {message: /must be a template string/},268 );269};270
2 unmodified lines
modified:test/pipe/sequence.js+2 added-2 removed
1 unmodified line
2import process from 'node:process';3import {PassThrough} from 'node:stream';4import test from 'ava';5import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {foobarString} from '../helpers/input.js';8import {noopGenerator} from '../helpers/generator.js';9import {prematureClose} from '../helpers/stdio.js';1011setFixtureDir();11setFixtureDirectory();1213const isLinux = process.platform === 'linux';1415test('Source stream abort -> destination success', async t => {
298 unmodified lines
modified:test/pipe/setup.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {fullStdio, fullReadableStdio} from '../helpers/stdio.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89// eslint-disable-next-line max-params10const pipeToSubprocess = async (t, readableFdNumber, writableFdNumber, from, to, readableOptions = {}, writableOptions = {}) => {11 const {stdout} = await execa('noop-fd.js', [`${readableFdNumber}`, foobarString], readableOptions)
17 unmodified lines
modified:test/pipe/streaming.js+2 added-2 removed
1import {once} from 'node:events';2import {PassThrough} from 'node:stream';3import test from 'ava';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString} from '../helpers/input.js';7import {assertMaxListeners} from '../helpers/listeners.js';8import {fullReadableStdio} from '../helpers/stdio.js';910setFixtureDir();10setFixtureDirectory();1112test('Can pipe two sources to same destination', async t => {13 const source = execa('noop.js', [foobarString]);14 const secondSource = execa('noop.js', [foobarString]);
427 unmodified lines
modified:test/pipe/throw.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {foobarString} from '../helpers/input.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {assertPipeError} from '../helpers/pipe.js';67setFixtureDir();7setFixtureDirectory();89test('Destination stream is ended when first argument is invalid', async t => {10 const source = execa('empty.js', {stdout: 'ignore'});11 const destination = execa('stdin.js');
27 unmodified lines
modified:test/resolve/all.js+9 added-3 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {defaultHighWaterMark} from '../helpers/stream.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89const textEncoder = new TextEncoder();10const foobarStringFull = `${foobarString}\n`;11const doubleFoobarStringFull = `${foobarStringFull}${foobarStringFull}`;
5 unmodified lines
1718// eslint-disable-next-line max-params19const testAllBoth = async (t, expectedOutput, encoding, lines, stripFinalNewline, isFailure, execaMethod) => {20 const fixtureName = isFailure ? 'noop-both-fail.js' : 'noop-both.js';21 const {exitCode, all} = await execaMethod(fixtureName, [foobarString], {all: true, encoding, lines, stripFinalNewline, reject: !isFailure});21 const {exitCode, all} = await execaMethod(fixtureName, [foobarString], {22 all: true,23 encoding,24 lines,25 stripFinalNewline,26 reject: !isFailure,27 });28 t.is(exitCode, isFailure ? 1 : 0);29 t.deepEqual(all, expectedOutput);30};31
146 unmodified lines
modified:test/resolve/buffer-end.js+2 added-2 removed
1import {once} from 'node:events';2import {setTimeout} from 'node:timers/promises';3import test from 'ava';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';78setFixtureDir();8setFixtureDirectory();910const testBufferIgnore = async (t, fdNumber, all) => {11 await t.notThrowsAsync(execa('max-buffer.js', [`${fdNumber}`], {...getStdio(fdNumber, 'ignore'), buffer: false, all}));12};
66 unmodified lines
modified:test/resolve/exit.js+2 added-2 removed
1import process from 'node:process';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56const isWindows = process.platform === 'win32';78setFixtureDir();8setFixtureDirectory();910test('exitCode is 0 on success', async t => {11 const {exitCode} = await execa('noop.js', ['foo']);12 t.is(exitCode, 0);
73 unmodified lines
modified:test/resolve/no-buffer.js+2 added-2 removed
1import {once} from 'node:events';2import test from 'ava';3import getStream from 'get-stream';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {fullStdio, getStdio} from '../helpers/stdio.js';7import {foobarString, foobarUppercase, foobarUppercaseUint8Array} from '../helpers/input.js';8import {resultGenerator, uppercaseGenerator, uppercaseBufferGenerator} from '../helpers/generator.js';910setFixtureDir();10setFixtureDirectory();1112const testLateStream = async (t, fdNumber, all) => {13 const subprocess = execa('noop-fd-ipc.js', [`${fdNumber}`, foobarString], {...getStdio(4, 'ipc', 4), buffer: false, all});14 await once(subprocess, 'message');
178 unmodified lines
modified:test/resolve/stdio.js+8 added-3 removed
1import {setTimeout} from 'node:timers/promises';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {fullStdio, getStdio, prematureClose, assertEpipe} from '../helpers/stdio.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {6 fullStdio,7 getStdio,8 prematureClose,9 assertEpipe,10} from '../helpers/stdio.js';11import {infiniteGenerator} from '../helpers/generator.js';128setFixtureDir();13setFixtureDirectory();1415const getStreamInputSubprocess = fdNumber => execa('stdin-fd.js', [`${fdNumber}`], fdNumber === 316 ? getStdio(3, [new Uint8Array(), infiniteGenerator()])17 : {});
105 unmodified lines
modified:test/resolve/wait-abort.js+8 added-3 removed
1import {setImmediate} from 'node:timers/promises';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {prematureClose} from '../helpers/stdio.js';6import {noopReadable, noopWritable, noopDuplex} from '../helpers/stream.js';7import {endOptionStream, destroyOptionStream, destroySubprocessStream, getStreamStdio} from '../helpers/wait.js';7import {8 endOptionStream,9 destroyOptionStream,10 destroySubprocessStream,11 getStreamStdio,12} from '../helpers/wait.js';139setFixtureDir();14setFixtureDirectory();1516const noop = () => {};1718// eslint-disable-next-line max-params
86 unmodified lines
modified:test/resolve/wait-epipe.js+8 added-3 removed
1import {setImmediate} from 'node:timers/promises';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {assertEpipe} from '../helpers/stdio.js';6import {foobarString} from '../helpers/input.js';7import {noopWritable, noopDuplex} from '../helpers/stream.js';8import {endOptionStream, destroyOptionStream, destroySubprocessStream, getStreamStdio} from '../helpers/wait.js';8import {9 endOptionStream,10 destroyOptionStream,11 destroySubprocessStream,12 getStreamStdio,13} from '../helpers/wait.js';1410setFixtureDir();15setFixtureDirectory();1617// eslint-disable-next-line max-params18const testStreamEpipeFail = async (t, streamMethod, stream, fdNumber, useTransform) => {19 const subprocess = execa('noop-stdin-fd.js', [`${fdNumber}`], getStreamStdio(fdNumber, stream, useTransform));
41 unmodified lines
modified:test/resolve/wait-error.js+8 added-3 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {noopReadable, noopWritable, noopDuplex} from '../helpers/stream.js';5import {destroyOptionStream, destroySubprocessStream, getStreamStdio} from '../helpers/wait.js';67setFixtureDir();7setFixtureDirectory();89// eslint-disable-next-line max-params10const testStreamError = async (t, streamMethod, stream, fdNumber, useTransform) => {11 const subprocess = execa('empty.js', getStreamStdio(fdNumber, stream, useTransform));12 const cause = new Error('test');13 streamMethod({stream, subprocess, fdNumber, error: cause});13 streamMethod({14 stream,15 subprocess,16 fdNumber,17 error: cause,18 });1920 const error = await t.throwsAsync(subprocess);21 t.is(error.cause, cause);22 t.is(error.exitCode, 0);
42 unmodified lines
modified:test/resolve/wait-subprocess.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getStdio} from '../helpers/stdio.js';56setFixtureDir();6setFixtureDirectory();78const testIgnore = async (t, fdNumber, execaMethod) => {9 const result = await execaMethod('noop.js', getStdio(fdNumber, 'ignore'));10 t.is(result.stdio[fdNumber], undefined);
39 unmodified lines
modified:test/return/duration.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getEarlyErrorSubprocess, getEarlyErrorSubprocessSync} from '../helpers/early-error.js';56setFixtureDir();6setFixtureDirectory();78const assertDurationMs = (t, durationMs) => {9 t.is(typeof durationMs, 'number');10 t.true(Number.isFinite(durationMs));
51 unmodified lines
modified:test/return/early-error.js+8 added-3 removed
1import process from 'node:process';2import test from 'ava';3import {execa, execaSync, $} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {fullStdio} from '../helpers/stdio.js';6import {earlyErrorOptions, getEarlyErrorSubprocess, getEarlyErrorSubprocessSync, expectedEarlyError} from '../helpers/early-error.js';6import {7 earlyErrorOptions,8 getEarlyErrorSubprocess,9 getEarlyErrorSubprocessSync,10 expectedEarlyError,11} from '../helpers/early-error.js';128setFixtureDir();13setFixtureDirectory();1415const isWindows = process.platform === 'win32';16const ENOENT_REGEXP = isWindows ? /failed with exit code 1/ : /spawn.* ENOENT/;17
96 unmodified lines
modified:test/return/final-error.js+8 added-3 removed
1import test from 'ava';2import {execa, execaSync, ExecaError, ExecaSyncError} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';2import {3 execa,4 execaSync,5 ExecaError,6 ExecaSyncError,7} from '../../index.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {foobarString} from '../helpers/input.js';10import {getEarlyErrorSubprocess, getEarlyErrorSubprocessSync} from '../helpers/early-error.js';117setFixtureDir();12setFixtureDirectory();1314const testUnusualError = async (t, error, expectedOriginalMessage = String(error)) => {15 const subprocess = execa('empty.js');16 subprocess.emit('error', error);
147 unmodified lines
modified:test/return/message.js+8 added-3 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {fullStdio, getStdio} from '../helpers/stdio.js';5import {foobarString} from '../helpers/input.js';6import {QUOTE} from '../helpers/verbose.js';7import {noopGenerator, outputObjectGenerator} from '../helpers/generator.js';89setFixtureDir();9setFixtureDirectory();1011test('error.message contains the command', async t => {12 await t.throwsAsync(execa('exit.js', ['2', 'foo', 'bar']), {message: /exit.js 2 foo bar/});13});1415// eslint-disable-next-line max-params16const testStdioMessage = async (t, encoding, all, objectMode, execaMethod) => {17 const {exitCode, message} = await execaMethod('echo-fail.js', {...getStdio(1, noopGenerator(objectMode, false, true), 4), encoding, all, reject: false});17 const {exitCode, message} = await execaMethod('echo-fail.js', {18 ...getStdio(1, noopGenerator(objectMode, false, true), 4),19 encoding,20 all,21 reject: false,22 });23 t.is(exitCode, 1);24 const output = all ? 'stdout\nstderr' : 'stderr\n\nstdout';25 t.true(message.endsWith(`echo-fail.js\n\n${output}\n\nfd3`));26};
70 unmodified lines
modified:test/return/output.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {fullStdio, getStdio} from '../helpers/stdio.js';5import {foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89const testOutput = async (t, fdNumber, execaMethod) => {10 const {stdout, stderr, stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], fullStdio);11 t.is(stdio[fdNumber], foobarString);
99 unmodified lines
modified:test/return/reject.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';45setFixtureDir();5setFixtureDirectory();67test('skip throwing when using reject option', async t => {8 const {exitCode} = await execa('fail.js', {reject: false});9 t.is(exitCode, 2);
6 unmodified lines
modified:test/return/result.js+2 added-2 removed
1import process from 'node:process';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {fullStdio} from '../helpers/stdio.js';67const isWindows = process.platform === 'win32';89setFixtureDir();9setFixtureDirectory();1011const testSuccessShape = async (t, execaMethod) => {12 const result = await execaMethod('empty.js', {...fullStdio, all: true});13 t.deepEqual(Reflect.ownKeys(result), [
132 unmodified lines
modified:test/stdio/direction.js+2 added-2 removed
2 unmodified lines
3import test from 'ava';4import tempfile from 'tempfile';5import {execa, execaSync} from '../../index.js';6import {getStdio} from '../helpers/stdio.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';89setFixtureDir();9setFixtureDirectory();1011const testInputOutput = (t, stdioOption, execaMethod) => {12 t.throws(() => {13 execaMethod('empty.js', getStdio(3, [new ReadableStream(), stdioOption]));
37 unmodified lines
modified:test/stdio/duplex.js+8 added-3 removed
1 unmodified line
2import {promisify} from 'node:util';3import {createGzip, gunzip} from 'node:zlib';4import test from 'ava';5import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {foobarString, foobarObject, foobarUppercase, foobarUppercaseHex} from '../helpers/input.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {8 foobarString,9 foobarObject,10 foobarUppercase,11 foobarUppercaseHex,12} from '../helpers/input.js';13import {uppercaseEncodingDuplex, getOutputDuplex} from '../helpers/duplex.js';1410setFixtureDir();15setFixtureDirectory();1617test('Can use crypto.createHash()', async t => {18 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: {transform: createHash('sha1')}, encoding: 'hex'});19 const expectedStdout = createHash('sha1').update(foobarString).digest('hex');
43 unmodified lines
modified:test/stdio/file-descriptor.js+2 added-2 removed
1import {readFile, open, rm} from 'node:fs/promises';2import test from 'ava';3import tempfile from 'tempfile';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getStdio} from '../helpers/stdio.js';78setFixtureDir();8setFixtureDirectory();910const testFileDescriptorOption = async (t, fdNumber, execaMethod) => {11 const filePath = tempfile();12 const fileDescriptor = await open(filePath, 'w');
22 unmodified lines
modified:test/stdio/file-path-error.js+8 added-3 removed
2 unmodified lines
3import test from 'ava';4import {pathExists} from 'path-exists';5import tempfile from 'tempfile';6import {execa, execaSync} from '../../index.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {identity, getStdio} from '../helpers/stdio.js';9import {foobarString, foobarUppercase} from '../helpers/input.js';10import {outputObjectGenerator, uppercaseGenerator, serializeGenerator, throwingGenerator} from '../helpers/generator.js';10import {11 outputObjectGenerator,12 uppercaseGenerator,13 serializeGenerator,14 throwingGenerator,15} from '../helpers/generator.js';16import {getAbsolutePath} from '../helpers/file-path.js';1713setFixtureDir();18setFixtureDirectory();1920const nonFileUrl = new URL('https://example.com');2122const testStdioNonFileUrl = (t, fdNumber, execaMethod) => {
151 unmodified lines
modified:test/stdio/file-path-main.js+8 added-3 removed
3 unmodified lines
4import {pathToFileURL} from 'node:url';5import test from 'ava';6import tempfile from 'tempfile';7import {execa, execaSync} from '../../index.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';9import {identity, getStdio} from '../helpers/stdio.js';10import {runExeca, runExecaSync, runScript, runScriptSync} from '../helpers/run.js';10import {11 runExeca,12 runExecaSync,13 runScript,14 runScriptSync,15} from '../helpers/run.js';16import {foobarString, foobarUint8Array} from '../helpers/input.js';17import {getAbsolutePath, getRelativePath} from '../helpers/file-path.js';1814setFixtureDir();19setFixtureDirectory();2021const getStdioInput = (fdNumberOrName, file) => {22 if (fdNumberOrName === 'string') {23 return {input: foobarString};
137 unmodified lines
modified:test/stdio/file-path-mixed.js+2 added-2 removed
1 unmodified line
2import {pathToFileURL} from 'node:url';3import test from 'ava';4import tempfile from 'tempfile';5import {execa, execaSync} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {getStdio} from '../helpers/stdio.js';8import {foobarString, foobarUppercase} from '../helpers/input.js';9import {uppercaseGenerator} from '../helpers/generator.js';10import {getAbsolutePath} from '../helpers/file-path.js';1112setFixtureDir();12setFixtureDirectory();1314const testInputFileTransform = async (t, fdNumber, mapFile, execaMethod) => {15 const filePath = tempfile();16 await writeFile(filePath, foobarString);
78 unmodified lines
modified:test/stdio/forward.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {getStdio} from '../helpers/stdio.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString, foobarUint8Array} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89const testInputOverlapped = async (t, fdNumber) => {10 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`, foobarString], getStdio(fdNumber, [foobarUint8Array, 'overlapped', 'pipe']));11 t.is(stdout, foobarString);
36 unmodified lines
modified:test/stdio/handle-invalid.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {getStdio} from '../helpers/stdio.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();78const testEmptyArray = (t, fdNumber, optionName, execaMethod) => {9 t.throws(() => {10 execaMethod('empty.js', getStdio(fdNumber, []));
50 unmodified lines
modified:test/stdio/handle-options.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {getStdio} from '../helpers/stdio.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {appendGenerator, appendAsyncGenerator, casedSuffix} from '../helpers/generator.js';6import {appendDuplex} from '../helpers/duplex.js';7import {appendWebTransform} from '../helpers/web-transform.js';8import {foobarString} from '../helpers/input.js';910setFixtureDir();10setFixtureDirectory();1112const testNoPipeOption = async (t, stdioOption, fdNumber) => {13 const subprocess = execa('empty.js', getStdio(fdNumber, stdioOption));14 t.is(subprocess.stdio[fdNumber], null);
58 unmodified lines
modified:test/stdio/iterable.js+15 added-5 removed
1import {once} from 'node:events';2import {setImmediate} from 'node:timers/promises';3import test from 'ava';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getStdio} from '../helpers/stdio.js';7import {foobarString, foobarObject, foobarObjectString, foobarArray} from '../helpers/input.js';8import {noopGenerator, serializeGenerator, infiniteGenerator, throwingGenerator} from '../helpers/generator.js';7import {8 foobarString,9 foobarObject,10 foobarObjectString,11 foobarArray,12} from '../helpers/input.js';13import {14 noopGenerator,15 serializeGenerator,16 infiniteGenerator,17 throwingGenerator,18} from '../helpers/generator.js';1920const stringGenerator = function * () {21 yield * foobarArray;22};
17 unmodified lines
40 await setImmediate();41 yield * foobarArray;42};4334setFixtureDir();44setFixtureDirectory();4546const testIterable = async (t, stdioOption, fdNumber, execaMethod) => {47 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, stdioOption));48 t.is(stdout, 'foobar');
147 unmodified lines
196197test('stdin option iterable is canceled on subprocess error', async t => {198 const iterable = infiniteGenerator().transform();199 await t.throwsAsync(execa('stdin.js', {stdin: iterable, timeout: 1}), {message: /timed out/});190 // eslint-disable-next-line no-unused-vars, no-empty200 // eslint-disable-next-line no-empty201 for await (const _ of iterable) {}202});
modified:test/stdio/lines-main.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {fullStdio} from '../helpers/stdio.js';5import {getOutputsGenerator} from '../helpers/generator.js';6import {foobarString} from '../helpers/input.js';7import {
5 unmodified lines
13 noNewlinesChunks,14 getSimpleChunkSubprocessAsync,15} from '../helpers/lines.js';1617setFixtureDir();17setFixtureDirectory();1819// eslint-disable-next-line max-params20const testStreamLines = async (t, fdNumber, input, expectedOutput, lines, stripFinalNewline, execaMethod) => {21 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, input], {...fullStdio, lines, stripFinalNewline});
87 unmodified lines
modified:test/stdio/lines-max-buffer.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {simpleLines, noNewlinesChunks, getSimpleChunkSubprocessAsync} from '../helpers/lines.js';5import {assertErrorMessage} from '../helpers/max-buffer.js';67setFixtureDir();7setFixtureDirectory();89const maxBuffer = simpleLines.length - 1;1011const testBelowMaxBuffer = async (t, lines) => {
39 unmodified lines
modified:test/stdio/lines-mixed.js+8 added-3 removed
1import {Writable} from 'node:stream';2import test from 'ava';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {assertStreamOutput, assertStreamDataEvents, assertIterableChunks} from '../helpers/convert.js';5import {simpleFull, simpleLines, noNewlinesChunks, getSimpleChunkSubprocessAsync} from '../helpers/lines.js';5import {6 simpleFull,7 simpleLines,8 noNewlinesChunks,9 getSimpleChunkSubprocessAsync,10} from '../helpers/lines.js';117setFixtureDir();12setFixtureDirectory();1314const testAsyncIteration = async (t, expectedLines, stripFinalNewline) => {15 const subprocess = getSimpleChunkSubprocessAsync({stripFinalNewline});16 t.false(subprocess.stdout.readableObjectMode);
44 unmodified lines
modified:test/stdio/lines-noop.js+8 added-3 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getOutputsGenerator} from '../helpers/generator.js';5import {foobarObject} from '../helpers/input.js';6import {7 simpleFull,
4 unmodified lines
12 noNewlinesChunks,13 getSimpleChunkSubprocess,14} from '../helpers/lines.js';1516setFixtureDir();16setFixtureDirectory();1718const testStreamLinesNoop = async (t, lines, execaMethod) => {19 const {stdout} = await execaMethod('noop-fd.js', ['1', simpleFull], {lines});20 t.is(stdout, simpleFull);
20 unmodified lines
41test('"lines: true" is a noop with objects generators, fd-specific, objectMode, sync', testLinesObjectMode, {stdout: true}, execaSync);4243// eslint-disable-next-line max-params44const testEncoding = async (t, input, expectedOutput, encoding, lines, stripFinalNewline, execaMethod) => {45 const {stdout} = await execaMethod('stdin.js', {lines, stripFinalNewline, encoding, input});45 const {stdout} = await execaMethod('stdin.js', {46 lines,47 stripFinalNewline,48 encoding,49 input,50 });51 t.deepEqual(stdout, expectedOutput);52};5354test('"lines: true" is a noop with "encoding: utf16"', testEncoding, simpleFullUtf16Uint8Array, simpleLines, 'utf16le', true, false, execa);
35 unmodified lines
modified:test/stdio/native-fd.js+2 added-2 removed
1import {platform} from 'node:process';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {getStdio, fullStdio} from '../helpers/stdio.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString} from '../helpers/input.js';7import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';89setFixtureDir();9setFixtureDirectory();1011const isLinux = platform === 'linux';12const isWindows = platform === 'win32';13
63 unmodified lines
modified:test/stdio/native-inherit-pipe.js+2 added-2 removed
1 unmodified line
2import test from 'ava';3import tempfile from 'tempfile';4import {execa} from '../../index.js';5import {getStdio, fullStdio} from '../helpers/stdio.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';7import {foobarString} from '../helpers/input.js';8import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';910setFixtureDir();10setFixtureDirectory();1112const testInheritStdin = async (t, stdioOption, isSync) => {13 const {stdout} = await execa('nested-multiple-stdin.js', [JSON.stringify(stdioOption), `${isSync}`], {input: foobarString});14 t.is(stdout, `${foobarString}${foobarString}`);
83 unmodified lines
modified:test/stdio/native-redirect.js+2 added-2 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';56setFixtureDir();6setFixtureDirectory();78// eslint-disable-next-line max-params9const testRedirect = async (t, stdioOption, fdNumber, isInput, isSync) => {10 const {fixtureName, ...options} = isInput
65 unmodified lines
modified:test/stdio/node-stream-custom.js+2 added-2 removed
5 unmodified lines
6import {callbackify} from 'node:util';7import test from 'ava';8import tempfile from 'tempfile';9import {execa, execaSync} from '../../index.js';10import {setFixtureDir} from '../helpers/fixtures-dir.js';10import {setFixtureDirectory} from '../helpers/fixtures-directory.js';11import {getStdio} from '../helpers/stdio.js';12import {foobarString} from '../helpers/input.js';13import {noopReadable, noopWritable} from '../helpers/stream.js';1415setFixtureDir();15setFixtureDirectory();1617const testLazyFileReadable = async (t, fdNumber) => {18 const filePath = tempfile();19 await writeFile(filePath, 'foobar');
139 unmodified lines
modified:test/stdio/node-stream-native.js+8 added-3 removed
2 unmodified lines
3import {readFile, writeFile, rm} from 'node:fs/promises';4import test from 'ava';5import tempfile from 'tempfile';6import {execa, execaSync} from '../../index.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {getStdio} from '../helpers/stdio.js';9import {foobarString} from '../helpers/input.js';10import {noopReadable, noopWritable, noopDuplex, simpleReadable} from '../helpers/stream.js';10import {11 noopReadable,12 noopWritable,13 noopDuplex,14 simpleReadable,15} from '../helpers/stream.js';1612setFixtureDir();17setFixtureDirectory();1819const testNoFileStreamSync = async (t, fdNumber, stream) => {20 t.throws(() => {21 execaSync('empty.js', getStdio(fdNumber, stream));
164 unmodified lines
modified:test/stdio/stdio-option.js+3 added-6 removed
1import {inspect} from 'node:util';2import test from 'ava';3import {normalizeStdioOption} from '../../lib/stdio/stdio-option.js';45const macro = (t, input, expected, func) => {5const stdioMacro = (t, input, expected) => {6 if (expected instanceof Error) {7 t.throws(() => {8 normalizeStdioOption(input);9 }, {message: expected.message});10 return;11 }1213 t.deepEqual(func(input), expected);13 t.deepEqual(normalizeStdioOption(input), expected);14};1516const macroTitle = name => (title, input) => `${name} ${(inspect(input))}`;16stdioMacro.title = (_, input) => `execa() ${(inspect(input))}`;1718const stdioMacro = (...args) => macro(...args, normalizeStdioOption);19stdioMacro.title = macroTitle('execa()');2018test(stdioMacro, {stdio: 'inherit'}, ['inherit', 'inherit', 'inherit']);19test(stdioMacro, {stdio: 'pipe'}, ['pipe', 'pipe', 'pipe']);20test(stdioMacro, {stdio: 'ignore'}, ['ignore', 'ignore', 'ignore']);21
33 unmodified lines
modified:test/stdio/type.js+2 added-2 removed
3 unmodified lines
4import {noopGenerator, uppercaseGenerator} from '../helpers/generator.js';5import {uppercaseBufferDuplex} from '../helpers/duplex.js';6import {uppercaseBufferWebTransform} from '../helpers/web-transform.js';7import {generatorsMap} from '../helpers/map.js';8import {setFixtureDir} from '../helpers/fixtures-dir.js';8import {setFixtureDirectory} from '../helpers/fixtures-directory.js';910setFixtureDir();10setFixtureDirectory();1112const testInvalidGenerator = (t, fdNumber, stdioOption, execaMethod) => {13 t.throws(() => {14 execaMethod('empty.js', getStdio(fdNumber, {...noopGenerator(), ...stdioOption}));
116 unmodified lines
modified:test/stdio/typed-array.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getStdio} from '../helpers/stdio.js';5import {foobarUint8Array, foobarString} from '../helpers/input.js';67setFixtureDir();7setFixtureDirectory();89const testUint8Array = async (t, fdNumber, execaMethod) => {10 const {stdout} = await execaMethod('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, foobarUint8Array));11 t.is(stdout, foobarString);
16 unmodified lines
modified:test/stdio/web-stream.js+2 added-2 removed
1import {Readable} from 'node:stream';2import {setImmediate} from 'node:timers/promises';3import test from 'ava';4import {execa, execaSync} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {getStdio} from '../helpers/stdio.js';78setFixtureDir();8setFixtureDirectory();910const testReadableStream = async (t, fdNumber) => {11 const readableStream = Readable.toWeb(Readable.from('foobar'));12 const {stdout} = await execa('stdin-fd.js', [`${fdNumber}`], getStdio(fdNumber, readableStream));
86 unmodified lines
modified:test/stdio/web-transform.js+2 added-2 removed
1import {promisify} from 'node:util';2import {gunzip} from 'node:zlib';3import test from 'ava';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';6import {foobarString, foobarUtf16Uint8Array, foobarUint8Array} from '../helpers/input.js';78setFixtureDir();8setFixtureDirectory();910test('Can use CompressionStream()', async t => {11 const {stdout} = await execa('noop-fd.js', ['1', foobarString], {stdout: new CompressionStream('gzip'), encoding: 'buffer'});12 const decompressedStdout = await promisify(gunzip)(stdout);
11 unmodified lines
modified:test/terminate/cancel.js+2 added-2 removed
1import {once} from 'node:events';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';56setFixtureDir();6setFixtureDirectory();78test('result.isCanceled is false when abort isn\'t called (success)', async t => {9 const {isCanceled} = await execa('noop.js');10 t.false(isCanceled);
82 unmodified lines
modified:test/terminate/cleanup.js+2 added-2 removed
2 unmodified lines
3import test from 'ava';4import {pEvent} from 'p-event';5import isRunning from 'is-running';6import {execa, execaSync} from '../../index.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {nestedExecaAsync, nestedWorker} from '../helpers/nested.js';9import {foobarString} from '../helpers/input.js';1011setFixtureDir();11setFixtureDirectory();1213const isWindows = process.platform === 'win32';1415// When subprocess exits before current process
87 unmodified lines
modified:test/terminate/kill-error.js+2 added-2 removed
1 unmodified line
2import {setImmediate} from 'node:timers/promises';3import test from 'ava';4import isRunning from 'is-running';5import {execa} from '../../index.js';6import {setFixtureDir} from '../helpers/fixtures-dir.js';6import {setFixtureDirectory} from '../helpers/fixtures-directory.js';78setFixtureDir();8setFixtureDirectory();910test('.kill(error) propagates error', async t => {11 const subprocess = execa('forever.js');12 const originalMessage = 'test';
71 unmodified lines
modified:test/terminate/kill-force.js+2 added-2 removed
4 unmodified lines
5import test from 'ava';6import {pEvent} from 'p-event';7import isRunning from 'is-running';8import {execa} from '../../index.js';9import {setFixtureDir} from '../helpers/fixtures-dir.js';9import {setFixtureDirectory} from '../helpers/fixtures-directory.js';10import {assertMaxListeners} from '../helpers/listeners.js';1112setFixtureDir();12setFixtureDirectory();1314const isWindows = process.platform === 'win32';1516const spawnNoKillable = async (forceKillAfterDelay, options) => {
124 unmodified lines
modified:test/terminate/kill-signal.js+2 added-2 removed
1import {once} from 'node:events';2import {setImmediate} from 'node:timers/promises';3import test from 'ava';4import {execa} from '../../index.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';67setFixtureDir();7setFixtureDirectory();89test('Can call `.kill()` multiple times', async t => {10 const subprocess = execa('forever.js');11 subprocess.kill();
84 unmodified lines
modified:test/terminate/timeout.js+3 added-3 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';45setFixtureDir();5setFixtureDirectory();67test('timeout kills the subprocess if it times out', async t => {8 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await t.throwsAsync(execa('forever.js', {timeout: 1}));9 t.true(isTerminated);
5 unmodified lines
15});1617test('timeout kills the subprocess if it times out, in sync mode', async t => {18 const {isTerminated, signal, timedOut, originalMessage, shortMessage, message} = await t.throws(() => {19 execaSync('node', ['forever.js'], {timeout: 1, cwd: FIXTURES_DIR});19 execaSync('node', ['forever.js'], {timeout: 1, cwd: FIXTURES_DIRECTORY});20 });21 t.true(isTerminated);22 t.is(signal, 'SIGTERM');23 t.true(timedOut);
53 unmodified lines
modified:test/transform/encoding-final.js+3 added-3 removed
2 unmodified lines
3import {promisify} from 'node:util';4import test from 'ava';5import getStream from 'get-stream';6import {execa, execaSync} from '../../index.js';7import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory, FIXTURES_DIRECTORY} from '../helpers/fixtures-directory.js';8import {fullStdio} from '../helpers/stdio.js';9import {foobarString, foobarUint8Array, foobarHex} from '../helpers/input.js';1011const pExec = promisify(exec);1213setFixtureDir();13setFixtureDirectory();1415const checkEncoding = async (t, encoding, fdNumber, execaMethod) => {16 const {stdio} = await execaMethod('noop-fd.js', [`${fdNumber}`, STRING_TO_ENCODE], {...fullStdio, encoding});17 compareValues(t, stdio[fdNumber], encoding);
8 unmodified lines
26 if (fdNumber === 3) {27 return;28 }2930 const {stdout, stderr} = await pExec(`node noop-fd.js ${fdNumber} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIR});30 const {stdout, stderr} = await pExec(`node noop-fd.js ${fdNumber} ${STRING_TO_ENCODE}`, {encoding, cwd: FIXTURES_DIRECTORY});31 compareValues(t, fdNumber === 1 ? stdout : stderr, encoding);32};3334const compareValues = (t, value, encoding) => {
95 unmodified lines
modified:test/transform/encoding-ignored.js+2 added-2 removed
1import process from 'node:process';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {outputObjectGenerator, addNoopGenerator} from '../helpers/generator.js';6import {foobarObject} from '../helpers/input.js';78setFixtureDir();8setFixtureDirectory();910const testObjectMode = async (t, addNoopTransform, execaMethod) => {11 const {stdout} = await execaMethod('noop.js', {12 stdout: addNoopGenerator(outputObjectGenerator(), addNoopTransform, true),
80 unmodified lines
modified:test/transform/encoding-multibyte.js+10 added-4 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {noopGenerator, getOutputsGenerator, addNoopGenerator} from '../helpers/generator.js';5import {multibyteChar, multibyteString, multibyteUint8Array, breakingLength, brokenSymbol} from '../helpers/encoding.js';5import {6 multibyteChar,7 multibyteString,8 multibyteUint8Array,9 breakingLength,10 brokenSymbol,11} from '../helpers/encoding.js';127setFixtureDir();13setFixtureDirectory();1415const foobarArray = ['fo', 'ob', 'ar', '..'];1617const testMultibyteCharacters = async (t, objectMode, addNoopTransform, execaMethod) => {
3 unmodified lines
21 });22 if (objectMode) {23 t.deepEqual(stdout, foobarArray);24 } else {19 t.is(stdout, btoa(foobarArray.join('')));25 t.is(stdout, Buffer.from(foobarArray.join('')).toString('base64'));26 }27};2829test('Handle multibyte characters', testMultibyteCharacters, false, false, execa);
50 unmodified lines
modified:test/transform/encoding-transform.js+8 added-3 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {getStdio} from '../helpers/stdio.js';6import {foobarString, foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';6import {7 foobarString,8 foobarUint8Array,9 foobarBuffer,10 foobarObject,11} from '../helpers/input.js';12import {noopGenerator, getOutputGenerator} from '../helpers/generator.js';139setFixtureDir();14setFixtureDirectory();1516const getTypeofGenerator = lines => (objectMode, binary) => ({17 * transform(line) {18 lines.push(Object.prototype.toString.call(line));
159 unmodified lines
modified:test/transform/generator-all.js+23 added-5 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarObject} from '../helpers/input.js';6import {7 outputObjectGenerator,8 uppercaseGenerator,9 uppercaseBufferGenerator,10} from '../helpers/generator.js';1112setFixtureDir();12setFixtureDirectory();1314const textEncoder = new TextEncoder();1516const getAllStdioOption = (stdioOption, encoding, objectMode) => {
48 unmodified lines
65 lines,66 stripFinalNewline: false,67 });6869 const stdoutOutput = getStdoutStderrOutput({output: 'std\nout\n', stdioOption: stdoutOption, encoding, objectMode, lines});69 const stdoutOutput = getStdoutStderrOutput({70 output: 'std\nout\n',71 stdioOption: stdoutOption,72 encoding,73 objectMode,74 lines,75 });76 t.deepEqual(stdout, stdoutOutput);71 const stderrOutput = getStdoutStderrOutput({output: 'std\nerr\n', stdioOption: stderrOption, encoding, objectMode, lines});77 const stderrOutput = getStdoutStderrOutput({78 output: 'std\nerr\n',79 stdioOption: stderrOption,80 encoding,81 objectMode,82 lines,83 });84 t.deepEqual(stderr, stderrOutput);73 const allOutput = getAllOutput({stdoutOutput, stderrOutput, encoding, objectMode, lines});85 const allOutput = getAllOutput({86 stdoutOutput,87 stderrOutput,88 encoding,89 objectMode,90 lines,91 });92 if (Array.isArray(all) && Array.isArray(allOutput)) {93 t.deepEqual([...all].sort(), [...allOutput].sort());94 } else {95 t.deepEqual(all, allOutput);
147 unmodified lines
modified:test/transform/generator-error.js+2 added-2 removed
2 unmodified lines
3import {execa, execaSync} from '../../index.js';4import {foobarString} from '../helpers/input.js';5import {noopGenerator, infiniteGenerator, convertTransformToFinal} from '../helpers/generator.js';6import {generatorsMap} from '../helpers/map.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';89setFixtureDir();9setFixtureDirectory();1011const assertProcessError = async (t, type, execaMethod, getSubprocess) => {12 const cause = new Error(foobarString);13 const transform = generatorsMap[type].throwing(cause)();
76 unmodified lines
modified:test/transform/generator-final.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {foobarString} from '../helpers/input.js';4import {getOutputAsyncGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';5import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDirectory} from '../helpers/fixtures-directory.js';67setFixtureDir();7setFixtureDirectory();89const testGeneratorFinal = async (t, fixtureName, execaMethod) => {10 const {stdout} = await execaMethod(fixtureName, {stdout: convertTransformToFinal(getOutputGenerator(foobarString)(), true)});11 t.is(stdout, foobarString);
24 unmodified lines
modified:test/transform/generator-input.js+2 added-2 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {getStdio} from '../helpers/stdio.js';6import {7 foobarString,8 foobarUppercase,
4 unmodified lines
13 foobarObjectString,14} from '../helpers/input.js';15import {generatorsMap} from '../helpers/map.js';1617setFixtureDir();17setFixtureDirectory();1819const getInputObjectMode = (objectMode, addNoopTransform, type) => objectMode20 ? {21 input: [foobarObject],
137 unmodified lines
modified:test/transform/generator-main.js+2 added-2 removed
11 unmodified lines
12 suffix,13} from '../helpers/generator.js';14import {generatorsMap} from '../helpers/map.js';15import {defaultHighWaterMark} from '../helpers/stream.js';16import {setFixtureDir} from '../helpers/fixtures-dir.js';16import {setFixtureDirectory} from '../helpers/fixtures-directory.js';17import {maxBuffer, assertErrorMessage} from '../helpers/max-buffer.js';1819setFixtureDir();19setFixtureDirectory();2021const repeatCount = defaultHighWaterMark * 3;2223const writerGenerator = function * () {
162 unmodified lines
modified:test/transform/generator-mixed.js+2 added-2 removed
2 unmodified lines
3import test from 'ava';4import getStream from 'get-stream';5import tempfile from 'tempfile';6import {execa, execaSync} from '../../index.js';7import {setFixtureDir} from '../helpers/fixtures-dir.js';7import {setFixtureDirectory} from '../helpers/fixtures-directory.js';8import {foobarString, foobarUppercase, foobarUint8Array} from '../helpers/input.js';9import {uppercaseGenerator} from '../helpers/generator.js';10import {uppercaseBufferDuplex} from '../helpers/duplex.js';11import {uppercaseBufferWebTransform} from '../helpers/web-transform.js';12import {generatorsMap} from '../helpers/map.js';1314setFixtureDir();14setFixtureDirectory();1516const testInputOption = async (t, type, execaMethod) => {17 const {stdout} = await execaMethod('stdin-fd.js', ['0'], {stdin: generatorsMap[type].uppercase(), input: foobarUint8Array});18 t.is(stdout, foobarUppercase);
86 unmodified lines
modified:test/transform/generator-output.js+2 added-2 removed
1import test from 'ava';2import getStream, {getStreamAsArray} from 'get-stream';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {getStdio} from '../helpers/stdio.js';6import {foobarString, foobarUppercase, foobarObject} from '../helpers/input.js';7import {generatorsMap} from '../helpers/map.js';89setFixtureDir();9setFixtureDirectory();1011const getOutputObjectMode = (objectMode, addNoopTransform, type, binary) => objectMode12 ? {13 generators: generatorsMap[type].addNoop(generatorsMap[type].outputObject(), addNoopTransform, objectMode, binary),
248 unmodified lines
modified:test/transform/generator-return.js+2 added-2 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString, foobarUint8Array} from '../helpers/input.js';6import {getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';78setFixtureDir();8setFixtureDirectory();910// eslint-disable-next-line max-params11const testGeneratorReturnType = async (t, input, encoding, reject, objectMode, final, execaMethod) => {12 const fixtureName = reject ? 'noop-fd.js' : 'noop-fail.js';
138 unmodified lines
modified:test/transform/normalize-transform.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString, foobarUppercase, foobarUint8Array} from '../helpers/input.js';5import {casedSuffix} from '../helpers/generator.js';6import {generatorsMap} from '../helpers/map.js';78setFixtureDir();8setFixtureDirectory();910const testAppendInput = async (t, reversed, type, execaMethod) => {11 const stdin = [foobarUint8Array, generatorsMap[type].uppercase(), generatorsMap[type].append()];12 const reversedStdin = reversed ? stdin.reverse() : stdin;
43 unmodified lines
modified:test/transform/split-binary.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';5import {6 simpleFull,7 simpleChunks,
7 unmodified lines
15 simpleLines,16 noNewlinesChunks,17} from '../helpers/lines.js';1819setFixtureDir();19setFixtureDirectory();2021// eslint-disable-next-line max-params22const testBinaryOption = async (t, binary, input, expectedLines, expectedOutput, objectMode, preserveNewlines, encoding, execaMethod) => {23 const lines = [];
72 unmodified lines
modified:test/transform/split-lines.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getStdio} from '../helpers/stdio.js';5import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';6import {7 singleFull,
7 unmodified lines
15 noNewlinesFull,16 noNewlinesChunks,17} from '../helpers/lines.js';1819setFixtureDir();19setFixtureDirectory();2021const windowsFull = 'aaa\r\nbbb\r\nccc';22const windowsFullEnd = `${windowsFull}\r\n`;23const windowsChunks = [windowsFull];
151 unmodified lines
modified:test/transform/split-newline.js+2 added-2 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getOutputsGenerator, noopGenerator, noopAsyncGenerator} from '../helpers/generator.js';5import {singleFull, singleFullEnd} from '../helpers/lines.js';67setFixtureDir();7setFixtureDirectory();89const singleFullEndWindows = `${singleFull}\r\n`;10const mixedNewlines = '.\n.\r\n.\n.\r\n.\n';11
26 unmodified lines
modified:test/transform/split-transform.js+8 added-3 removed
1import test from 'ava';2import {execa, execaSync} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {getOutputsGenerator, resultGenerator} from '../helpers/generator.js';5import {foobarString, foobarUint8Array, foobarObject, foobarObjectString} from '../helpers/input.js';5import {6 foobarString,7 foobarUint8Array,8 foobarObject,9 foobarObjectString,10} from '../helpers/input.js';117setFixtureDir();12setFixtureDirectory();1314const resultUint8ArrayGenerator = function * (lines, chunk) {15 lines.push(chunk);16 yield new TextEncoder().encode(chunk);
67 unmodified lines
modified:test/transform/validate.js+2 added-2 removed
1import {Buffer} from 'node:buffer';2import test from 'ava';3import {execa, execaSync} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {getStdio} from '../helpers/stdio.js';6import {foobarUint8Array, foobarBuffer, foobarObject} from '../helpers/input.js';7import {serializeGenerator, getOutputGenerator, convertTransformToFinal} from '../helpers/generator.js';89setFixtureDir();9setFixtureDirectory();1011const getMessage = input => {12 if (input === null || input === undefined) {13 return 'not be called at all';
82 unmodified lines
modified:test/verbose/complete.js+2 added-2 removed
1import {stripVTControlCharacters} from 'node:util';2import test from 'ava';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';6import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {8 runErrorSubprocessAsync,
10 unmodified lines
19 fdShortOption,20 fdFullOption,21} from '../helpers/verbose.js';2223setFixtureDir();23setFixtureDirectory();2425const testPrintCompletion = async (t, verbose, execaMethod) => {26 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});27 t.is(getCompletionLine(stderr), `${testTimestamp} [0] √ (done in 0ms)`);
80 unmodified lines
modified:test/verbose/error.js+2 added-2 removed
1import test from 'ava';2import {red} from 'yoctocolors';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {8 QUOTE,
9 unmodified lines
18 fdShortOption,19 fdFullOption,20} from '../helpers/verbose.js';2122setFixtureDir();22setFixtureDirectory();2324const parentExecaFail = parentExeca.bind(undefined, 'nested-fail.js');2526const testPrintError = async (t, verbose, execaMethod) => {
119 unmodified lines
modified:test/verbose/info.js+2 added-2 removed
1import test from 'ava';2import {setFixtureDir} from '../helpers/fixtures-dir.js';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {execa, execaSync} from '../../index.js';4import {foobarString} from '../helpers/input.js';5import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6import {
3 unmodified lines
10 getNormalizedLines,11 testTimestamp,12} from '../helpers/verbose.js';1314setFixtureDir();14setFixtureDirectory();1516const testVerboseGeneral = async (t, execaMethod) => {17 const {all} = await execaMethod('verbose-script.js', {env: {NODE_DEBUG: 'execa'}, all: true});18 t.deepEqual(getNormalizedLines(all), [
26 unmodified lines
modified:test/verbose/log.js+2 added-2 removed
1import {stripVTControlCharacters} from 'node:util';2import test from 'ava';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {parentExecaAsync, parentExecaSync} from '../helpers/nested.js';67setFixtureDir();7setFixtureDirectory();89const testNoStdout = async (t, verbose, execaMethod) => {10 const {stdout} = await execaMethod('noop.js', [foobarString], {verbose, stdio: 'inherit'});11 t.is(stdout, foobarString);
16 unmodified lines
modified:test/verbose/output-buffer.js+14 added-4 removed
1import test from 'ava';2import {setFixtureDir} from '../helpers/fixtures-dir.js';2import {setFixtureDirectory} from '../helpers/fixtures-directory.js';3import {foobarString, foobarUppercase} from '../helpers/input.js';4import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';5import {getOutputLine, testTimestamp, fdFullOption, fdStderrFullOption} from '../helpers/verbose.js';5import {6 getOutputLine,7 testTimestamp,8 fdFullOption,9 fdStderrFullOption,10} from '../helpers/verbose.js';117setFixtureDir();12setFixtureDirectory();1314const testPrintOutputNoBuffer = async (t, verbose, buffer, execaMethod) => {15 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose, buffer});16 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);
16 unmodified lines
33test('Does not print stdout, buffer: false, different fd, sync', testPrintOutputNoBufferFalse, false, parentExecaSync);34test('Does not print stdout, buffer: false, different fd, fd-specific buffer, sync', testPrintOutputNoBufferFalse, {stdout: false}, parentExecaSync);3536const testPrintOutputNoBufferTransform = async (t, buffer, isSync) => {32 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {verbose: 'full', buffer, type: 'generator', isSync});37 const {stderr} = await parentExeca('nested-transform.js', 'noop.js', [foobarString], {38 verbose: 'full',39 buffer,40 type: 'generator',41 isSync,42 });43 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarUppercase}`);44};4546test('Prints stdout, buffer: false, transform', testPrintOutputNoBufferTransform, false, false);
3 unmodified lines
modified:test/verbose/output-enable.js+8 added-3 removed
1import test from 'ava';2import {red} from 'yoctocolors';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {fullStdio} from '../helpers/stdio.js';6import {nestedExecaAsync, parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6import {7 nestedExecaAsync,8 parentExeca,9 parentExecaAsync,10 parentExecaSync,11} from '../helpers/nested.js';12import {13 runErrorSubprocessAsync,14 runErrorSubprocessSync,15 getOutputLine,16 getOutputLines,
8 unmodified lines
25 fd3ShortOption,26 fd3FullOption,27} from '../helpers/verbose.js';2824setFixtureDir();29setFixtureDirectory();3031const testPrintOutput = async (t, verbose, fdNumber, execaMethod) => {32 const {stderr} = await execaMethod('noop-fd.js', [`${fdNumber}`, foobarString], {verbose});33 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);
113 unmodified lines
modified:test/verbose/output-mixed.js+2 added-2 removed
1import {inspect} from 'node:util';2import test from 'ava';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString, foobarObject} from '../helpers/input.js';5import {simpleFull, noNewlinesChunks} from '../helpers/lines.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';89setFixtureDir();9setFixtureDirectory();1011const testLines = async (t, lines, stripFinalNewline, execaMethod) => {12 const {stderr} = await execaMethod('noop-fd.js', ['1', simpleFull], {verbose: 'full', lines, stripFinalNewline});13 t.deepEqual(getOutputLines(stderr), noNewlinesChunks.map(line => `${testTimestamp} [0] ${line}`));
44 unmodified lines
modified:test/verbose/output-noop.js+2 added-2 removed
1import {rm, readFile} from 'node:fs/promises';2import test from 'ava';3import tempfile from 'tempfile';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';6import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';7import {getOutputLine, testTimestamp} from '../helpers/verbose.js';89setFixtureDir();9setFixtureDirectory();1011const testNoOutputOptions = async (t, fixtureName, options = {}) => {12 const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString], {verbose: 'full', ...options});13 t.is(getOutputLine(stderr), undefined);
44 unmodified lines
modified:test/verbose/output-pipe.js+10 added-5 removed
1import test from 'ava';2import {execa} from '../../index.js';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {parentExeca} from '../helpers/nested.js';6import {getOutputLine, getOutputLines, testTimestamp, getVerboseOption} from '../helpers/verbose.js';6import {7 getOutputLine,8 getOutputLines,9 testTimestamp,10 getVerboseOption,11} from '../helpers/verbose.js';128setFixtureDir();13setFixtureDirectory();1415const testPipeOutput = async (t, fixtureName, sourceVerbose, destinationVerbose) => {16 const {stderr} = await execa(`nested-pipe-${fixtureName}.js`, [17 JSON.stringify(getVerboseOption(sourceVerbose, 'full')),
22 unmodified lines
40test('Does not print stdout if neither verbose with .pipe("file")', testPipeOutput, 'file', false, false);41test('Does not print stdout if neither verbose with .pipe`command`', testPipeOutput, 'script', false, false);42test('Does not print stdout if neither verbose with .pipe(subprocess)', testPipeOutput, 'subprocesses', false, false);4339const testPrintOutputFixture = async (t, fixtureName, ...args) => {40 const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...args], {verbose: 'full'});44const testPrintOutputFixture = async (t, fixtureName, ...commandArguments) => {45 const {stderr} = await parentExeca(fixtureName, 'noop.js', [foobarString, ...commandArguments], {verbose: 'full'});46 t.is(getOutputLine(stderr), `${testTimestamp} [0] ${foobarString}`);47};4849test('Prints stdout, .pipe(stream) + .unpipe()', testPrintOutputFixture, 'nested-pipe-stream.js', 'true');
1 unmodified line
modified:test/verbose/output-progressive.js+2 added-2 removed
1import {on} from 'node:events';2import test from 'ava';3import {setFixtureDir} from '../helpers/fixtures-dir.js';3import {setFixtureDirectory} from '../helpers/fixtures-directory.js';4import {foobarString} from '../helpers/input.js';5import {parentExeca, parentExecaAsync, parentExecaSync} from '../helpers/nested.js';6import {getOutputLine, getOutputLines, testTimestamp} from '../helpers/verbose.js';78setFixtureDir();8setFixtureDirectory();910test('Prints stdout one line at a time', async t => {11 const subprocess = parentExecaAsync('noop-progressive.js', [foobarString], {verbose: 'full'});12
46 unmodified lines
modified:test/verbose/start.js+2 added-2 removed
1import test from 'ava';2import {red} from 'yoctocolors';3import {execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';4import {setFixtureDirectory} from '../helpers/fixtures-directory.js';5import {foobarString} from '../helpers/input.js';6import {parentExecaAsync, parentExecaSync, parentWorker} from '../helpers/nested.js';7import {8 QUOTE,
9 unmodified lines
18 fdShortOption,19 fdFullOption,20} from '../helpers/verbose.js';2122setFixtureDir();22setFixtureDirectory();2324const testPrintCommand = async (t, verbose, execaMethod) => {25 const {stderr} = await execaMethod('noop.js', [foobarString], {verbose});26 t.is(getCommandLine(stderr), `${testTimestamp} [0] $ noop.js ${foobarString}`);
96 unmodified lines
modified:test-d/arguments/options.test-d.ts+6 added-1 removed
1import * as process from 'node:process';2import {expectError, expectAssignable, expectNotAssignable} from 'tsd';3import {execa, execaSync, type Options, type SyncOptions} from '../../index.js';3import {4 execa,5 execaSync,6 type Options,7 type SyncOptions,8} from '../../index.js';910const fileUrl = new URL('file:///test');1112expectAssignable<Options>({cleanup: false});
185 unmodified lines
modified:test-d/methods/command.test-d.ts+7 added-1 removed
1import {expectType, expectError, expectAssignable} from 'tsd';2import {execaCommand, execaCommandSync, type ExecaResult, type ExecaSubprocess, type ExecaSyncResult} from '../../index.js';2import {3 execaCommand,4 execaCommandSync,5 type ExecaResult,6 type ExecaSubprocess,7 type ExecaSyncResult,8} from '../../index.js';910const fileUrl = new URL('file:///test');11const stringArray = ['foo', 'bar'] as const;12
88 unmodified lines
modified:test-d/methods/node.test-d.ts+1 added-1 removed
1import {expectType, expectError, expectAssignable, expectNotAssignable} from 'tsd';1import {expectType, expectError, expectAssignable} from 'tsd';2import {execaNode, type ExecaResult, type ExecaSubprocess} from '../../index.js';34const fileUrl = new URL('file:///test');5const stringArray = ['foo', 'bar'] as const;
58 unmodified lines
modified:test-d/return/ignore-option.test-d.ts+12 added-2 removed
1import {type Readable, type Writable} from 'node:stream';2import {expectType, expectError} from 'tsd';3import {execa, execaSync, type ExecaError, type ExecaSyncError} from '../../index.js';3import {4 execa,5 execaSync,6 type ExecaError,7 type ExecaSyncError,8} from '../../index.js';95const ignoreAnyPromise = execa('unicorns', {stdin: 'ignore', stdout: 'ignore', stderr: 'ignore', all: true});10const ignoreAnyPromise = execa('unicorns', {11 stdin: 'ignore',12 stdout: 'ignore',13 stderr: 'ignore',14 all: true,15});16expectType<null>(ignoreAnyPromise.stdin);17expectType<null>(ignoreAnyPromise.stdio[0]);18expectType<null>(ignoreAnyPromise.stdout);19expectType<null>(ignoreAnyPromise.stdio[1]);
134 unmodified lines
modified:test-d/return/ignore-other.test-d.ts+6 added-1 removed
1import * as process from 'node:process';2import {expectType} from 'tsd';3import {execa, execaSync, type ExecaError, type ExecaSyncError} from '../../index.js';3import {4 execa,5 execaSync,6 type ExecaError,7 type ExecaSyncError,8} from '../../index.js';910const inheritStdoutResult = await execa('unicorns', {stdout: 'inherit', all: true});11expectType<undefined>(inheritStdoutResult.stdout);12expectType<string>(inheritStdoutResult.stderr);
146 unmodified lines
modified:test-d/return/lines-main.test-d.ts+6 added-1 removed
1import {expectType} from 'tsd';2import {execa, execaSync, type ExecaError, type ExecaSyncError} from '../../index.js';2import {3 execa,4 execaSync,5 type ExecaError,6 type ExecaSyncError,7} from '../../index.js';89const linesResult = await execa('unicorns', {lines: true, all: true});10expectType<string[]>(linesResult.stdout);11expectType<string[]>(linesResult.stdio[1]);
62 unmodified lines
modified:test-d/return/no-buffer-main.test-d.ts+6 added-1 removed
1import type {Readable, Writable} from 'node:stream';2import {expectType, expectError} from 'tsd';3import {execa, execaSync, type ExecaError, type ExecaSyncError} from '../../index.js';3import {4 execa,5 execaSync,6 type ExecaError,7 type ExecaSyncError,8} from '../../index.js';910const noBufferPromise = execa('unicorns', {buffer: false, all: true});11expectType<Writable>(noBufferPromise.stdin);12expectType<Writable>(noBufferPromise.stdio[0]);
33 unmodified lines
modified:test-d/return/result-all.test-d.ts+6 added-1 removed
1import {expectType} from 'tsd';2import {execa, execaSync, type ExecaError, type ExecaSyncError} from '../../index.js';2import {3 execa,4 execaSync,5 type ExecaError,6 type ExecaSyncError,7} from '../../index.js';89const allResult = await execa('unicorns', {all: true});10expectType<string>(allResult.all);11
20 unmodified lines
modified:test-d/return/result-stdio.test-d.ts+6 added-1 removed
1import {Readable, Writable} from 'node:stream';2import {expectType} from 'tsd';3import {execa, execaSync, type ExecaError, type ExecaSyncError} from '../../index.js';3import {4 execa,5 execaSync,6 type ExecaError,7 type ExecaSyncError,8} from '../../index.js';910const unicornsResult = await execa('unicorns', {all: true});11expectType<undefined>(unicornsResult.stdio[0]);12expectType<string>(unicornsResult.stdout);
112 unmodified lines
modified:test-d/stdio/direction.test-d.ts+6 added-1 removed
1import {Readable, Writable} from 'node:stream';2import {expectError, expectAssignable, expectNotAssignable} from 'tsd';3import {execa, execaSync, type StdioOption, type StdioOptionSync} from '../../index.js';3import {4 execa,5 execaSync,6 type StdioOption,7 type StdioOptionSync,8} from '../../index.js';910await execa('unicorns', {stdio: [new Readable(), 'pipe', 'pipe']});11execaSync('unicorns', {stdio: [new Readable(), 'pipe', 'pipe']});12await execa('unicorns', {stdio: [[new Readable()], ['pipe'], ['pipe']]});
27 unmodified lines
modified:test-d/pipe.test-d.ts+6 added-1 removed
1import {createWriteStream} from 'node:fs';2import {expectType, expectNotType, expectError} from 'tsd';3import {execa, execaSync, $, type ExecaResult} from '../index.js';3import {4 execa,5 execaSync,6 $,7 type ExecaResult,8} from '../index.js';910const fileUrl = new URL('file:///test');11const stringArray = ['foo', 'bar'] as const;12const pipeOptions = {from: 'stderr', to: 'fd3', all: true} as const;
242 unmodified lines
modified:types/methods/script.d.ts+10 added-5 removed
1import type {CommonOptions, Options, SyncOptions, StricterOptions} from '../arguments/options';1import type {2 CommonOptions,3 Options,4 SyncOptions,5 StricterOptions,6} from '../arguments/options';7import type {ExecaSyncResult} from '../return/result';8import type {ExecaSubprocess} from '../subprocess/subprocess';9import type {TemplateString} from './template';10
5 unmodified lines
16 <NewOptionsType extends Options = {}>(17 file: string | URL,18 arguments?: readonly string[],19 options?: NewOptionsType,15 ): ExecaSubprocess<OptionsType & NewOptionsType>;20 ): ExecaSubprocess<StricterOptions<OptionsType & NewOptionsType, Options>>;2122 <NewOptionsType extends Options = {}>(23 file: string | URL,24 options?: NewOptionsType,20 ): ExecaSubprocess<OptionsType & NewOptionsType>;25 ): ExecaSubprocess<StricterOptions<OptionsType & NewOptionsType, Options>>;26};2728type ExecaScriptSync<OptionsType extends CommonOptions> = {29 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaScriptSync<OptionsType & NewOptionsType>;
3 unmodified lines
33 <NewOptionsType extends SyncOptions = {}>(34 file: string | URL,35 arguments?: readonly string[],36 options?: NewOptionsType,32 ): ExecaSyncResult<OptionsType & NewOptionsType>;37 ): ExecaSyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;3839 <NewOptionsType extends SyncOptions = {}>(40 file: string | URL,41 options?: NewOptionsType,37 ): ExecaSyncResult<OptionsType & NewOptionsType>;42 ): ExecaSyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;43};4445type ExecaScript<OptionsType extends CommonOptions> = {46 sync: ExecaScriptSync<OptionsType>;
39 unmodified lines
modified:types/stdio/option.d.ts+6 added-1 removed
1import type {CommonOptions} from '../arguments/options';2import type {StdioOptionNormalizedArray} from './array';3import type {StandardStreams, StdioOptionCommon, StdioOptionsArray, StdioOptionsProperty} from './type';3import type {4 StandardStreams,5 StdioOptionCommon,6 StdioOptionsArray,7 StdioOptionsProperty,8} from './type';910// `options.stdin|stdout|stderr|stdio` for a given file descriptor11export type FdStdioOption<12 FdNumber extends string,
28 unmodified lines
modified:types/stdio/type.d.ts+13 added-2 removed
1import type {Readable, Writable} from 'node:stream';2import type {Not, And, Or, Unless, AndUnless} from '../utils';3import type {GeneratorTransform, GeneratorTransformFull, DuplexTransform, WebTransform} from '../transform/normalize';2import type {3 Not,4 And,5 Or,6 Unless,7 AndUnless,8} from '../utils';9import type {10 GeneratorTransform,11 GeneratorTransformFull,12 DuplexTransform,13 WebTransform,14} from '../transform/normalize';1516type IsStandardStream<FdNumber extends string> = FdNumber extends keyof StandardStreams ? true : false;1718export type StandardStreams = ['stdin', 'stdout', 'stderr'];
151 unmodified lines
modified:types/subprocess/subprocess.d.ts+6 added-1 removed
2 unmodified lines
3import type {StdioOptionsArray} from '../stdio/type';4import type {Options} from '../arguments/options';5import type {ExecaResult} from '../return/result';6import type {PipableSubprocess} from '../pipe';7import type {ReadableOptions, WritableOptions, DuplexOptions, SubprocessAsyncIterable} from '../convert';7import type {8 ReadableOptions,9 WritableOptions,10 DuplexOptions,11 SubprocessAsyncIterable,12} from '../convert';13import type {SubprocessStdioStream} from './stdout';14import type {SubprocessStdioArray} from './stdio';15import type {SubprocessAll} from './all';16
128 unmodified lines
modified:index.d.ts+8 added-1 removed
1export type {StdinOption, StdinOptionSync, StdoutStderrOption, StdoutStderrOptionSync, StdioOption, StdioOptionSync} from './types/stdio/type';1export type {2 StdinOption,3 StdinOptionSync,4 StdoutStderrOption,5 StdoutStderrOptionSync,6 StdioOption,7 StdioOptionSync,8} from './types/stdio/type';9export type {Options, SyncOptions} from './types/arguments/options';10export type {ExecaResult, ExecaSyncResult} from './types/return/result';11export type {ExecaResultPromise, ExecaSubprocess} from './types/subprocess/subprocess';12/* eslint-disable import/extensions */
7 unmodified lines
modified:package.json+1 added-1 removed
71 unmodified lines
72 "path-key": "^4.0.0",73 "tempfile": "^5.0.0",74 "tsd": "^0.29.0",75 "which": "^4.0.0",76 "xo": "^0.56.0"76 "xo": "^0.58.0"77 },78 "c8": {79 "reporter": [80 "text",
20 unmodified lines