Support file path and URL types in the `stdout` and `stderr` options (#621)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 4110dfc · Browse files · 7 files·+225 added−93 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+225 added−93 removed
- tests:+119 added−22 removed
- other:+106 added−71 removed
Provenance
- Commit
b369efe- Tree
77e8a98- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4110dfc
7 files changed+225 added−93 removed
modified:lib/stdio.js+62 added-57 removed
1-import {createReadStream, readFileSync} from 'node:fs';1+import {createReadStream, createWriteStream, readFileSync, writeFileSync} from 'node:fs';2 import {isAbsolute} from 'node:path';3 import {Readable, Writable} from 'node:stream';4 import {isStream as isNodeStream} from 'is-stream';5 6-const aliases = ['stdin', 'stdout', 'stderr'];7-6 const arrifyStdio = (stdio = []) => Array.isArray(stdio) ? stdio : [stdio, stdio, stdio];7 8 const isIterableStdin = stdinOption => typeof stdinOption === 'object'9 && stdinOption !== null29 unmodified lines39 40 const NO_PIPE_STDIO = new Set(['ipc', 'ignore', 'inherit']);41 const KNOWN_STDIO = new Set([...NO_PIPE_STDIO, 'overlapped', 'pipe']);42 45-const validateFileSdio = stdioOption => {43+const validateFileSdio = (stdioOption, optionName) => {44 if (isRegularUrl(stdioOption)) {47- throw new TypeError(`The \`stdin: URL\` option must use the \`file:\` scheme.45+ throw new TypeError(`The \`${optionName}: URL\` option must use the \`file:\` scheme.46 For example, you can use the \`pathToFileURL()\` method of the \`url\` core module.`);47 }48 49 if (isUnknownStdioString(stdioOption)) {52- throw new TypeError('The `stdin: filePath` option must either be an absolute file path or start with `.`.');50+ throw new TypeError(`The \`${optionName}: filePath\` option must either be an absolute file path or start with \`.\`.`);51 }52 };53 54 const validateInputOptions = (stdioArray, input, inputFile) => {9 unmodified lines64 if (noPipeStdin && inputFile !== undefined) {65 throw new TypeError('The `inputFile` and `stdin` options cannot be both set.');66 }67 70- validateFileSdio(stdioArray[0]);68+ validateFileSdio(stdioArray[0], 'stdin');69+ validateFileSdio(stdioArray[1], 'stdout');70+ validateFileSdio(stdioArray[2], 'stderr');71 };72 73-const getStdioStreams = (stdioArray, {input, inputFile}) => ({74- ...getStdinStream(stdioArray[0], input, inputFile),75- ...getStdoutStream(stdioArray[1]),76- ...getStderrStream(stdioArray[2]),77-});73+const getStdioStreams = (stdioArray, {input, inputFile}) => [74+ {...getStdinStream(stdioArray[0], input, inputFile), isInput: true},75+ getOutputStream(stdioArray[1]),76+ getOutputStream(stdioArray[2]),77+];78 79 const getStdinStream = (stdinOption, input, inputFile) => {80 const iterableStdin = getIterableStdin(stdinOption);81 82 if (iterableStdin !== undefined) {83- return {stdinStream: Readable.from(iterableStdin)};83+ return {value: Readable.from(iterableStdin)};84 }85 86 if (isReadableStream(stdinOption)) {87- return {stdinStream: Readable.fromWeb(stdinOption)};87+ return {value: Readable.fromWeb(stdinOption)};88 }89 90 if (isFileUrl(stdinOption) || isFilePath(stdinOption)) {91- return {stdinStream: createReadStream(stdinOption)};91+ return {value: createReadStream(stdinOption), finite: true};92 }93 94 if (inputFile !== undefined) {95- return {stdinStream: createReadStream(inputFile)};95+ return {value: createReadStream(inputFile), finite: true};96 }97 98 if (input === undefined) {99 return {};100 }101 102 if (isNodeStream(input)) {103- return {stdinStream: input};103+ return {value: input};104 }105 106- return {stdinInput: input};106+ return {value: input, single: true};107 };108 109-const getStdoutStream = stdoutOption => {110- const stdoutStream = getOutputStream(stdoutOption);111- return stdoutStream === undefined ? {} : {stdoutStream};112-};113-114-const getStderrStream = stderrOption => {115- const stderrStream = getOutputStream(stderrOption);116- return stderrStream === undefined ? {} : {stderrStream};117-};118-109 const getOutputStream = stdioOption => {110 if (isWritableStream(stdioOption)) {121- return Writable.fromWeb(stdioOption);111+ return {value: Writable.fromWeb(stdioOption)};112 }123-};113 125-// When the `stdin: Iterable | ReadableStream | URL | filePath`, `input` or `inputFile` option is used, we pipe to `spawned.std*`.126-// Therefore the `std*` options must be either `pipe` or `overlapped`. Other values do not set `spawned.std*`.127-const willPipeStreams = (index, {stdinStream, stdinInput, stdoutStream, stderrStream}) => {128- if (index === 0) {129- return stdinStream !== undefined || stdinInput !== undefined;114+ if (isFileUrl(stdioOption) || isFilePath(stdioOption)) {115+ return {value: createWriteStream(stdioOption), finite: true};116 }117 132- if (index === 1) {133- return stdoutStream !== undefined;134- }135-136- if (index === 2) {137- return stderrStream !== undefined;138- }139-140- return false;118+ return {};119 };120 121+// When the `stdin: Iterable | ReadableStream | URL | filePath`, `input` or `inputFile` option is used, we pipe to `spawned.std*`.122+// Therefore the `std*` options must be either `pipe` or `overlapped`. Other values do not set `spawned.std*`.123 const transformStdioItem = (stdioItem, index, stdioStreams) =>144- willPipeStreams(index, stdioStreams) && stdioItem !== 'overlapped' ? 'pipe' : stdioItem;124+ stdioStreams[index]?.value !== undefined && stdioItem !== 'overlapped' ? 'pipe' : stdioItem;125 126 const transformStdio = (stdio, stdioStreams) => Array.isArray(stdio)127 ? stdio.map((stdioItem, index) => transformStdioItem(stdioItem, index, stdioStreams))128 : stdio;129 150-// Handle `input`, `inputFile` and `stdin` options, before spawning, in async mode130+// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, before spawning, in async mode131 export const handleStdioOption = options => {132 const stdio = normalizeStdio(options);133 const stdioArray = arrifyStdio(stdio);134 validateInputOptions(stdioArray, options.input, options.inputFile);1 unmodified line136 options.stdio = transformStdio(stdio, stdioStreams);137 return stdioStreams;138 };139 160-// Handle `input`, `inputFile` and `stdin` options, after spawning, in async mode161-export const pipeStdioOption = (spawned, {stdinStream, stdinInput, stdoutStream, stderrStream}) => {162- if (stdinStream !== undefined) {163- stdinStream.pipe(spawned.stdin);140+// Handle `input`, `inputFile`, `stdin`, `stdout` and `stderr` options, after spawning, in async mode141+export const pipeStdioOptions = (spawned, stdioStreams) => {142+ for (const [index, stdioStream] of stdioStreams.entries()) {143+ pipeStdioOption(spawned.stdio[index], stdioStream);144 }145+};146 166- if (stdinInput !== undefined) {167- spawned.stdin.end(stdinInput);147+const pipeStdioOption = (childStream, {single, value, isInput}) => {148+ if (value === undefined) {149+ return;150 }151 170- if (stdoutStream !== undefined) {171- spawned.stdout.pipe(stdoutStream);152+ if (!isInput) {153+ childStream.pipe(value);154+ return;155 }156 174- if (stderrStream !== undefined) {175- spawned.stderr.pipe(stderrStream);157+ if (single) {158+ childStream.end(value);159+ return;160 }161+162+ value.pipe(childStream);163 };164 165 const transformStdioItemSync = stdioItem => isFileUrl(stdioItem) || isFilePath(stdioItem) ? 'pipe' : stdioItem;166 40 unmodified lines207 return input;208 };209 210 // Handle `input`, `inputFile` and `stdin` options, before spawning, in sync mode225-export const handleInputOption = options => {211+export const handleInputSync = options => {212 const stdio = normalizeStdio(options);213 const stdioArray = arrifyStdio(stdio);214 validateOptionsSync(stdioArray, options);215 2 unmodified lines218 options.input = input;219 }220 221 options.stdio = transformStdioSync(stdio);222+ return stdioArray;223 };224 225+// Handle `stdout` and `stderr` options, before spawning, in sync mode226+const handleOutputOption = (stdioOption, result) => {227+ if (result === null) {228+ return;229+ }230+231+ if (isFileUrl(stdioOption) || isFilePath(stdioOption)) {232+ writeFileSync(stdioOption, result);233+ }234+};235+236+export const handleOutputSync = (stdioArray, {stdout, stderr}) => {237+ handleOutputOption(stdioArray[1], stdout);238+ handleOutputOption(stdioArray[2], stderr);239+};240+241+const aliases = ['stdin', 'stdout', 'stderr'];242+243 const hasAlias = options => aliases.some(alias => options[alias] !== undefined);244 245 export const normalizeStdio = options => {246 if (!options) {43 unmodified linesmodified:lib/stream.js+27 added-6 removed
123456745 unmodified lines535455565657585758596061626364656667686970717273747576667778798081828384857086877388899091929394959697986 unmodified linesimport {once} from 'node:events';import {setTimeout} from 'node:timers/promises';import {finished} from 'node:stream/promises';import getStream, {getStreamAsBuffer} from 'get-stream';import mergeStreams from '@sindresorhus/merge-streams';
// `all` interleaves `stdout` and `stderr`45 unmodified lines const buffer = await getStreamAsBuffer(stream, {maxBuffer}); return buffer.toString(encoding);};
// Handle any errors thrown by the iterable passed to the `stdin`/`stdout`/`stderr` option, if any.// We do not consume nor wait on those streams though, since it could potentially be infinite (like `process.stdin` in an interactive TTY).const throwOnStreamsError = streams => streams.filter(Boolean).map(stream => throwOnStreamError(stream));// We need to handle any `error` coming from the `stdin|stdout|stderr` options.// However, those might be infinite streams, e.g. a TTY passed as input or output.// We wait for completion or not depending on whether `finite` is `true`.// In either case, we handle `error` events while the process is running.const waitForStreamEnd = ({value, finite, single}, processDone) => { if (value === undefined || single) { return; }
return finite ? finished(value) : Promise.race([processDone, throwOnStreamError(value)]);};
const throwOnStreamError = async stream => { const [error] = await once(stream, 'error'); throw error;};
// Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all)export const getSpawnedResult = async (spawned, {encoding, buffer, maxBuffer}, {stdinStream, stdoutStream, stderrStream}, processDone) => {export const getSpawnedResult = async ( spawned, {encoding, buffer, maxBuffer}, stdioStreams, processDone,) => { const stdoutPromise = getStreamPromise(spawned.stdout, {encoding, buffer, maxBuffer}); const stderrPromise = getStreamPromise(spawned.stderr, {encoding, buffer, maxBuffer}); const allPromise = getStreamPromise(spawned.all, {encoding, buffer, maxBuffer: maxBuffer * 2}); const processDoneOrStreamsError = Promise.race([processDone, ...throwOnStreamsError([stdinStream, stdoutStream, stderrStream])]);
try { return await Promise.all([processDoneOrStreamsError, stdoutPromise, stderrPromise, allPromise]); return await Promise.all([ processDone, stdoutPromise, stderrPromise, allPromise, ...stdioStreams.map(stdioStream => waitForStreamEnd(stdioStream, processDone)), ]); } catch (error) { spawned.kill(); return Promise.all([ {error, signal: error.signal, timedOut: error.timedOut},6 unmodified linesmodified:test/stream.js+119 added-22 removed
1 import {Buffer} from 'node:buffer';2 import {exec} from 'node:child_process';3 import process from 'node:process';4 import fs from 'node:fs';5+import {readFile} from 'node:fs/promises';6 import {relative} from 'node:path';7 import Stream from 'node:stream';8 import {setTimeout} from 'node:timers/promises';9 import {promisify} from 'node:util';8 unmodified lines18 const pExec = promisify(exec);19 20 setFixtureDir();21 22+const nonFileUrl = new URL('https://example.com');23+24 test('buffer', async t => {25 const {stdout} = await execa('noop.js', ['foo'], {encoding: null});26 t.true(Buffer.isBuffer(stdout));27 t.is(stdout.toString(), 'foo');255 unmodified lines283 284 test('stdin can be a file URL', async t => {285 const inputFile = tempfile();286 fs.writeFileSync(inputFile, 'howdy');284- const stdin = pathToFileURL(inputFile);285- const {stdout} = await execa('stdin.js', {stdin});287+ const {stdout} = await execa('stdin.js', {stdin: pathToFileURL(inputFile)});288 t.is(stdout, 'howdy');289 });290 289-test('stdin cannot be a non-file URL', async t => {290- await t.throws(() => {291- execa('stdin.js', {stdin: new URL('https://example.com')});291+const testOutputFileUrl = async (t, streamName, fixtureName) => {292+ const outputFile = tempfile();293+ await execa(fixtureName, ['foobar'], {[streamName]: pathToFileURL(outputFile)});294+ t.is(await readFile(outputFile, 'utf8'), 'foobar\n');295+};296+297+test('stdout can be a file URL', testOutputFileUrl, 'stdout', 'noop.js');298+test('stderr can be a file URL', testOutputFileUrl, 'stderr', 'noop-err.js');299+300+const testStdioNonFileUrl = (t, streamName, method) => {301+ t.throws(() => {302+ method('noop.js', {[streamName]: nonFileUrl});303 }, {message: /pathToFileURL/});293-});304+};305 306+test('stdin cannot be a non-file URL', testStdioNonFileUrl, 'stdin', execa);307+test('stdout cannot be a non-file URL', testStdioNonFileUrl, 'stdout', execa);308+test('stderr cannot be a non-file URL', testStdioNonFileUrl, 'stderr', execa);309+test('stdin cannot be a non-file URL - sync', testStdioNonFileUrl, 'stdin', execaSync);310+test('stdout cannot be a non-file URL - sync', testStdioNonFileUrl, 'stdout', execaSync);311+test('stderr cannot be a non-file URL - sync', testStdioNonFileUrl, 'stderr', execaSync);312+313 test('stdin can be an absolute file path', async t => {314 const inputFile = tempfile();315 fs.writeFileSync(inputFile, 'howdy');316 const {stdout} = await execa('stdin.js', {stdin: inputFile});317 t.is(stdout, 'howdy');318 });319 320+const testOutputAbsoluteFile = async (t, streamName, fixtureName) => {321+ const outputFile = tempfile();322+ await execa(fixtureName, ['foobar'], {[streamName]: outputFile});323+ t.is(await readFile(outputFile, 'utf8'), 'foobar\n');324+};325+326+test('stdout can be an absolute file path', testOutputAbsoluteFile, 'stdout', 'noop.js');327+test('stderr can be an absolute file path', testOutputAbsoluteFile, 'stderr', 'noop-err.js');328+329 test('stdin can be a relative file path', async t => {330 const inputFile = tempfile();331 fs.writeFileSync(inputFile, 'howdy');305- const stdin = relative('.', inputFile);306- const {stdout} = await execa('stdin.js', {stdin});332+ const {stdout} = await execa('stdin.js', {stdin: relative('.', inputFile)});333 t.is(stdout, 'howdy');334 });335 310-test('stdin option must start with . when being a relative file path', t => {336+const testOutputRelativeFile = async (t, streamName, fixtureName) => {337+ const outputFile = tempfile();338+ await execa(fixtureName, ['foobar'], {[streamName]: relative('.', outputFile)});339+ t.is(await readFile(outputFile, 'utf8'), 'foobar\n');340+};341+342+test('stdout can be a relative file path', testOutputRelativeFile, 'stdout', 'noop.js');343+test('stderr can be a relative file path', testOutputRelativeFile, 'stderr', 'noop-err.js');344+345+const testStdioValidUrl = (t, streamName, method) => {346 t.throws(() => {312- execa('stdin.js', {stdin: 'foobar'});347+ method('noop.js', {[streamName]: 'foobar'});348 }, {message: /absolute file path/});314-});349+};350 351+test('stdin must start with . when being a relative file path', testStdioValidUrl, 'stdin', execa);352+test('stdout must start with . when being a relative file path', testStdioValidUrl, 'stdout', execa);353+test('stderr must start with . when being a relative file path', testStdioValidUrl, 'stderr', execa);354+test('stdin must start with . when being a relative file path - sync', testStdioValidUrl, 'stdin', execaSync);355+test('stdout must start with . when being a relative file path - sync', testStdioValidUrl, 'stdout', execaSync);356+test('stderr must start with . when being a relative file path - sync', testStdioValidUrl, 'stderr', execaSync);357+358 test('inputFile can be set', async t => {359 const inputFile = tempfile();360 fs.writeFileSync(inputFile, 'howdy');361 const {stdout} = await execa('stdin.js', {inputFile});18 unmodified lines380 execa('stdin.js', {inputFile: '', stdin: 'ignore'});381 }, {message: /`inputFile` and `stdin` options/});382 });383 342-test('stdin file URL errors should be handled', async t => {343- await t.throwsAsync(execa('stdin.js', {stdin: pathToFileURL('unknown')}), {code: 'ENOENT'});344-});384+const testFileUrlError = async (t, streamName) => {385+ await t.throwsAsync(386+ execa('noop.js', {[streamName]: pathToFileURL('./unknown/file')}),387+ {code: 'ENOENT'},388+ );389+};390 346-test('stdin file path errors should be handled', async t => {347- await t.throwsAsync(execa('stdin.js', {stdin: './unknown'}), {code: 'ENOENT'});348-});391+test('stdin file URL errors should be handled', testFileUrlError, 'stdin');392+test('stdout file URL errors should be handled', testFileUrlError, 'stdout');393+test('stderr file URL errors should be handled', testFileUrlError, 'stderr');394 395+const testFileUrlErrorSync = (t, streamName) => {396+ t.throws(() => {397+ execaSync('noop.js', {[streamName]: pathToFileURL('./unknown/file')});398+ }, {code: 'ENOENT'});399+};400+401+test('stdin file URL errors should be handled - sync', testFileUrlErrorSync, 'stdin');402+test('stdout file URL errors should be handled - sync', testFileUrlErrorSync, 'stdout');403+test('stderr file URL errors should be handled - sync', testFileUrlErrorSync, 'stderr');404+405+const testFilePathError = async (t, streamName) => {406+ await t.throwsAsync(407+ execa('noop.js', {[streamName]: './unknown/file'}),408+ {code: 'ENOENT'},409+ );410+};411+412+test('stdin file path errors should be handled', testFilePathError, 'stdin');413+test('stdout file path errors should be handled', testFilePathError, 'stdout');414+test('stderr file path errors should be handled', testFilePathError, 'stderr');415+416+const testFilePathErrorSync = (t, streamName) => {417+ t.throws(() => {418+ execaSync('noop.js', {[streamName]: './unknown/file'});419+ }, {code: 'ENOENT'});420+};421+422+test('stdin file path errors should be handled - sync', testFilePathErrorSync, 'stdin');423+test('stdout file path errors should be handled - sync', testFilePathErrorSync, 'stdout');424+test('stderr file path errors should be handled - sync', testFilePathErrorSync, 'stderr');425+426 test('inputFile errors should be handled', async t => {427 await t.throwsAsync(execa('stdin.js', {inputFile: 'unknown'}), {code: 'ENOENT'});428 });429 56 unmodified lines486 const {stdout} = execaSync('stdin.js', {stdin});487 t.is(stdout, 'howdy');488 });489 490+const testOutputFileUrlSync = (t, streamName, fixtureName) => {491+ const outputFile = tempfile();492+ execaSync(fixtureName, ['foobar'], {[streamName]: pathToFileURL(outputFile)});493+ t.is(fs.readFileSync(outputFile, 'utf8'), 'foobar\n');494+};495+496+test('stdout can be a file URL - sync', testOutputFileUrlSync, 'stdout', 'noop.js');497+test('stderr can be a file URL - sync', testOutputFileUrlSync, 'stderr', 'noop-err.js');498+499 test('stdin can be an absolute file path - sync', t => {500 const inputFile = tempfile();501 fs.writeFileSync(inputFile, 'howdy');502 const {stdout} = execaSync('stdin.js', {stdin: inputFile});503 t.is(stdout, 'howdy');504 });505 506+const testOutputAbsoluteFileSync = (t, streamName, fixtureName) => {507+ const outputFile = tempfile();508+ execaSync(fixtureName, ['foobar'], {[streamName]: outputFile});509+ t.is(fs.readFileSync(outputFile, 'utf8'), 'foobar\n');510+};511+512+test('stdout can be an absolute file path - sync', testOutputAbsoluteFileSync, 'stdout', 'noop.js');513+test('stderr can be an absolute file path - sync', testOutputAbsoluteFileSync, 'stderr', 'noop-err.js');514+515 test('stdin can be a relative file path - sync', t => {516 const inputFile = tempfile();517 fs.writeFileSync(inputFile, 'howdy');518 const stdin = relative('.', inputFile);519 const {stdout} = execaSync('stdin.js', {stdin});520 t.is(stdout, 'howdy');521 });522 429-test('stdin cannot be a non-file URL - sync', async t => {430- await t.throws(() => {431- execaSync('stdin.js', {stdin: new URL('https://example.com')});432- }, {message: /pathToFileURL/});433-});523+const testOutputRelativeFileSync = (t, streamName, fixtureName) => {524+ const outputFile = tempfile();525+ execaSync(fixtureName, ['foobar'], {[streamName]: relative('.', outputFile)});526+ t.is(fs.readFileSync(outputFile, 'utf8'), 'foobar\n');527+};528 529+test('stdout can be a relative file path - sync', testOutputRelativeFileSync, 'stdout', 'noop.js');530+test('stderr can be a relative file path - sync', testOutputRelativeFileSync, 'stderr', 'noop-err.js');531+532 test('inputFile can be set - sync', t => {533 const inputFile = tempfile();534 fs.writeFileSync(inputFile, 'howdy');535 const {stdout} = execaSync('stdin.js', {inputFile});152 unmodified linesmodified:index.d.ts+4 added-2 removed
20 unmodified lines21 | ReadableStream;22 23 export type StdoutStderrOption =24 | StdioOption25+ | URL26+ | string27 | WritableStream;28 29 type EncodingOption =30 | 'utf8'77 unmodified lines108 109 /**110 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).111 110- It can also be a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used.112+ It can also be a file path, a file URL, a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used. If the file path is relative, it must start with `.`.113 114 @default 'pipe'115 */116 readonly stdout?: StdoutStderrOption;117 118 /**119 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).120 119- It can also be a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used.121+ It can also be a file path, a file URL, a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used. If the file path is relative, it must start with `.`.122 123 @default 'pipe'124 */125 readonly stderr?: StdoutStderrOption;890 unmodified linesmodified:index.js+4 added-3 removed
5 unmodified lines6 import stripFinalNewline from 'strip-final-newline';7 import {npmRunPathEnv} from 'npm-run-path';8 import onetime from 'onetime';9 import {makeError} from './lib/error.js';10-import {handleStdioOption, handleInputOption, pipeStdioOption, normalizeStdioNode} from './lib/stdio.js';10+import {handleStdioOption, handleInputSync, handleOutputSync, pipeStdioOptions, normalizeStdioNode} from './lib/stdio.js';11 import {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} from './lib/kill.js';12 import {addPipeMethods} from './lib/pipe.js';13 import {getSpawnedResult, makeAllStream} from './lib/stream.js';14 import {mergePromise, getSpawnedPromise} from './lib/promise.js';142 unmodified lines157 };158 159 const handlePromiseOnce = onetime(handlePromise);160 161- pipeStdioOption(spawned, stdioStreams);161+ pipeStdioOptions(spawned, stdioStreams);162 163 spawned.all = makeAllStream(spawned, parsed.options);164 165 addPipeMethods(spawned);2 unmodified lines168 }169 170 export function execaSync(file, args, options) {171 const parsed = handleArguments(file, args, options);172- handleInputOption(parsed.options);172+ const stdioArray = handleInputSync(parsed.options);173 174 const command = joinCommand(file, args);175 const escapedCommand = getEscapedCommand(file, args);176 logCommand(escapedCommand, parsed.options);15 unmodified lines192 killed: false,193 });194 }195 196+ handleOutputSync(stdioArray, result);197 const stdout = handleOutput(parsed.options, result.stdout, result.error);198 const stderr = handleOutput(parsed.options, result.stderr, result.error);199 200 if (result.error || result.status !== 0 || result.signal !== null) {111 unmodified linesmodified:index.test-d.ts+4 added
174 unmodified lines175 execa('unicorns', {stdout: 'ignore'});176 execa('unicorns', {stdout: 'inherit'});177 execa('unicorns', {stdout: process.stdout});178 execa('unicorns', {stdout: new WritableStream()});179+execa('unicorns', {stdout: new URL('file:///test')});180+execa('unicorns', {stdout: './test'});181 execa('unicorns', {stdout: 1});182 execa('unicorns', {stdout: undefined});183 execa('unicorns', {stderr: 'pipe'});184 execa('unicorns', {stderr: 'overlapped'});1 unmodified line186 execa('unicorns', {stderr: 'ignore'});187 execa('unicorns', {stderr: 'inherit'});188 execa('unicorns', {stderr: process.stderr});189 execa('unicorns', {stderr: new WritableStream()});190+execa('unicorns', {stderr: new URL('file:///test')});191+execa('unicorns', {stderr: './test'});192 execa('unicorns', {stderr: 1});193 execa('unicorns', {stderr: undefined});194 execa('unicorns', {all: true});195 execa('unicorns', {reject: false});179 unmodified linesmodified:readme.md+5 added-3 removed
566 unmodified lines567 It can also be a file path, a file URL, a web stream ([`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream)), an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol) or an [`AsyncIterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols), unless either [`execaSync()`](#execasyncfile-arguments-options), the [`input` option](#input) or the [`inputFile` option](#inputfile) is used. If the file path is relative, it must start with `.`.568 569 #### stdout570 571-Type: `string | number | stream.Writable | WritableStream | undefined`\571+Type: `string | number | stream.Writable | WritableStream | undefined | URL`\572 Default: `pipe`573 574 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).575 576-It can also be a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used.576+It can also be a file path, a file URL, a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used. If the file path is relative, it must start with `.`.577 578 #### stderr579 580-Type: `string | number | stream.Writable | WritableStream | undefined`\580+Type: `string | number | stream.Writable | WritableStream | undefined | URL`\581 Default: `pipe`582 583 Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).584 585+It can also be a file path, a file URL, a web stream ([`WritableStream`](https://developer.mozilla.org/en-US/docs/Web/API/WritableStream)), unless [`execaSync()`](#execasyncfile-arguments-options) is used. If the file path is relative, it must start with `.`.586+587 #### all588 589 Type: `boolean`\590 Default: `false`227 unmodified lines