Skip to content
Myr

Add `.pipe(command, args, options)` shortcut (#864)

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

authored by ehmicky · committed by GitHub · parent 4bd0fe3 · Browse files · 6 files+294 added−50 removed
This commit

State

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

Diff stats

6 files+294 added−50 removed

  • tests:+125 added−3 removed
  • other:+169 added−47 removed

6 files+294 added−50 removed

modified:lib/pipe/validate.js+17 added-5 removed
modified:test/pipe/template.js+123 added-1 removed
1import {spawn} from 'node:child_process';2import {pathToFileURL} from 'node:url';3import test from 'ava';4import {$, execa} from '../../index.js';4import {setFixtureDir} from '../helpers/fixtures-dir.js';5import {setFixtureDir, FIXTURES_DIR} from '../helpers/fixtures-dir.js';6import {foobarString} from '../helpers/input.js';78setFixtureDir();9
30 unmodified lines
40 .pipe`stdin.js`;41 t.is(stdout, foobarString);42});4344test('$.pipe("file")', async t => {45 const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js');46 t.is(stdout, foobarString);47});4849test('execa.$.pipe("file")`', async t => {50 const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js');51 t.is(stdout, foobarString);52});5354test('$.pipe.pipe("file")', async t => {55 const {stdout} = await $`noop.js ${foobarString}`56 .pipe`stdin.js`57 .pipe('stdin.js');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`));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});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});73 t.is(stdout, foobarString);74});7576test('$.pipe.pipe("file", args, options)', async t => {77 const {stdout} = await $`noop.js ${foobarString}`78 .pipe`stdin.js`79 .pipe('node', ['stdin.js'], {cwd: FIXTURES_DIR});80 t.is(stdout, foobarString);81});8283test('$.pipe(childProcess, pipeOptions)', async t => {84 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe($({stdin: 'pipe'})`stdin.js`, {from: 'stderr'});85 t.is(stdout, foobarString);86});
26 unmodified lines
113 .pipe({from: 'stderr'})`stdin.js`;114 t.is(stdout, foobarString);115});116117test('$.pipe("file", pipeOptions)', async t => {118 const {stdout} = await $`noop-fd.js 2 ${foobarString}`.pipe('stdin.js', {from: 'stderr'});119 t.is(stdout, foobarString);120});121122test('execa.$.pipe("file", pipeOptions)', async t => {123 const {stdout} = await execa('noop-fd.js', ['2', foobarString]).pipe('stdin.js', {from: 'stderr'});124 t.is(stdout, foobarString);125});126127test('$.pipe.pipe("file", pipeOptions)', async t => {128 const {stdout} = await $`noop-fd.js 2 ${foobarString}`129 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`130 .pipe('stdin.js', {from: 'stderr'});131 t.is(stdout, foobarString);132});133134test('$.pipe(options)`command`', async t => {135 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})`stdin.js`;136 t.is(stdout, `${foobarString}\n`);137});
9 unmodified lines
147 .pipe({stripFinalNewline: false})`stdin.js`;148 t.is(stdout, `${foobarString}\n`);149});150151test('$.pipe("file", options)', async t => {152 const {stdout} = await $`noop.js ${foobarString}`.pipe('stdin.js', {stripFinalNewline: false});153 t.is(stdout, `${foobarString}\n`);154});155156test('execa.$.pipe("file", options)', async t => {157 const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stripFinalNewline: false});158 t.is(stdout, `${foobarString}\n`);159});160161test('$.pipe.pipe("file", options)', async t => {162 const {stdout} = await $`noop.js ${foobarString}`163 .pipe({})`stdin.js`164 .pipe('stdin.js', {stripFinalNewline: false});165 t.is(stdout, `${foobarString}\n`);166});167168test('$.pipe(pipeAndProcessOptions)`command`', async t => {169 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;170 t.is(stdout, `${foobarString}\n`);171});
9 unmodified lines
181 .pipe({from: 'stderr', stripFinalNewline: false})`stdin.js`;182 t.is(stdout, `${foobarString}\n`);183});184185test('$.pipe("file", pipeAndProcessOptions)', async t => {186 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`.pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});187 t.is(stdout, `${foobarString}\n`);188});189190test('execa.$.pipe("file", pipeAndProcessOptions)', async t => {191 const {stdout} = await execa('noop-fd.js', ['2', `${foobarString}\n`]).pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});192 t.is(stdout, `${foobarString}\n`);193});194195test('$.pipe.pipe("file", pipeAndProcessOptions)', async t => {196 const {stdout} = await $`noop-fd.js 2 ${foobarString}\n`197 .pipe({from: 'stderr'})`noop-stdin-fd.js 2`198 .pipe('stdin.js', {from: 'stderr', stripFinalNewline: false});199 t.is(stdout, `${foobarString}\n`);200});201202test('$.pipe(options)(secondOptions)`command`', async t => {203 const {stdout} = await $`noop.js ${foobarString}`.pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;204 t.is(stdout, foobarString);205});
9 unmodified lines
215 .pipe({stripFinalNewline: false})({stripFinalNewline: true})`stdin.js`;216 t.is(stdout, foobarString);217});218219test('$.pipe`command` forces "stdin: pipe"', async t => {220 const {stdout} = await $`noop.js ${foobarString}`.pipe({stdin: 'ignore'})`stdin.js`;221 t.is(stdout, foobarString);222});223224test('execa.pipe("file") forces "stdin: "pipe"', async t => {225 const {stdout} = await execa('noop.js', [foobarString]).pipe('stdin.js', {stdin: 'ignore'});226 t.is(stdout, foobarString);227});228229test('execa.pipe(childProcess) does not force "stdin: pipe"', async t => {230 await t.throwsAsync(231 execa('noop.js', [foobarString]).pipe(execa('stdin.js', {stdin: 'ignore'})),232 {message: /stdin must be available/},233 );234});235236test('$.pipe(options)(childProcess) fails', async t => {237 await t.throwsAsync(238 $`empty.js`.pipe({stdout: 'pipe'})($`empty.js`),239 {message: /Please use \.pipe/},
6 unmodified lines
246 {message: /Please use \.pipe/},247 );248});249250test('$.pipe(options)("file") fails', async t => {251 await t.throwsAsync(252 $`empty.js`.pipe({stdout: 'pipe'})('empty.js'),253 {message: /Please use \.pipe/},254 );255});256257test('execa.$.pipe(options)("file") fails', async t => {258 await t.throwsAsync(259 execa('empty.js').pipe({stdout: 'pipe'})('empty.js'),260 {message: /Please use \.pipe/},261 );262});263264const testInvalidPipe = async (t, ...args) => {265 await t.throwsAsync(266 $`empty.js`.pipe(...args),267 {message: /must be a template string/},
5 unmodified lines
modified:test/pipe/validate.js+2 added-2 removed
162 unmodified lines
163});164165test('Source stream is aborted when second argument is invalid', async t => {166 const source = execa('noop.js', [foobarString]);167 const pipePromise = source.pipe('');167 const pipePromise = source.pipe(false);168169 await assertPipeError(t, pipePromise, 'an Execa child process');170 t.like(await source, {stdout: ''});171});172173test('Both arguments might be invalid', async t => {174 const source = execa('empty.js', {stdout: 'ignore'});175 const pipePromise = source.pipe('');175 const pipePromise = source.pipe(false);176177 await assertPipeError(t, pipePromise, 'an Execa child process');178 t.like(await source, {stdout: undefined});179});
30 unmodified lines
modified:index.d.ts+34 added-11 removed
834 unmodified lines
835};836837type PipableProcess = {838 /**839 Like `.pipe(secondChildProcess)` but using a `command` template string instead. This follows the same syntax as `$`. `options` can be used to specify both pipe options and regular options.839 [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process' `stdout` to a second Execa child process' `stdin`. This resolves with that second process' result. If either process is rejected, this is rejected with that process' error instead.840841 This follows the same syntax as `execa(file, arguments?, options?)` except both regular options and pipe-specific options can be specified.842843 This can be called multiple times to chain a series of processes.844845 Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.846847 This is usually the preferred method to pipe processes.848 */841 pipe(templates: TemplateStringsArray, ...expressions: TemplateExpression[]): Promise<ExecaReturnValue<{}>> & PipableProcess;849 pipe<OptionsType extends Options & PipeOptions = {}>(850 file: string | URL,851 arguments?: readonly string[],852 options?: OptionsType,853 ): Promise<ExecaReturnValue<OptionsType>> & PipableProcess;854 pipe<OptionsType extends Options & PipeOptions = {}>(855 file: string | URL,856 options?: OptionsType,857 ): Promise<ExecaReturnValue<OptionsType>> & PipableProcess;858859 /**860 Like `.pipe(file, arguments?, options?)` but using a `command` template string instead. This follows the same syntax as `$`.861862 This is the preferred method to pipe processes when using `$`.863 */864 pipe(templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):865 Promise<ExecaReturnValue<{}>> & PipableProcess;866 pipe<OptionsType extends Options & PipeOptions = {}>(options: OptionsType):843 (templates: TemplateStringsArray, ...expressions: TemplateExpression[])867 (templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[])868 => Promise<ExecaReturnValue<OptionsType>> & PipableProcess;869870 /**847 [Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process' `stdout` to a second Execa child process' `stdin`. This resolves with that second process' result. If either process is rejected, this is rejected with that process' error instead.871 Like `.pipe(file, arguments?, options?)` but using the return value of another `execa()` call instead.872849 This can be called multiple times to chain a series of processes.850851 Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.873 This is the most advanced method to pipe processes. It is useful in specific cases, such as piping multiple child processes to the same process.874 */853 pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions): Promise<Awaited<Destination>> & PipableProcess;875 pipe<Destination extends ExecaChildProcess>(destination: Destination, options?: PipeOptions):876 Promise<Awaited<Destination>> & PipableProcess;877};878879export type ExecaChildPromise<OptionsType extends Options = Options> = {880 stdin: StreamUnlessIgnored<'0', OptionsType>;
297 unmodified lines
1178 */1179 <NewOptionsType extends CommonOptions = {}>1180 (options: NewOptionsType): Execa$<OptionsType & NewOptionsType>;11811159 (templates: TemplateStringsArray, ...expressions: TemplateExpression[]):1182 (templates: TemplateStringsArray, ...expressions: readonly TemplateExpression[]):1183 ExecaChildProcess<StricterOptions<OptionsType, Options>> & PipableProcess;11841185 /**1186 Same as $\`command\` but synchronous.
45 unmodified lines
1232 ```1233 */1234 sync(1235 templates: TemplateStringsArray,1213 ...expressions: TemplateExpression[]1236 ...expressions: readonly TemplateExpression[]1237 ): ExecaSyncReturnValue<StricterOptions<OptionsType, SyncOptions>>;12381239 /**1240 Same as $\`command\` but synchronous.
45 unmodified lines
1286 ```1287 */1288 s(1289 templates: TemplateStringsArray,1267 ...expressions: TemplateExpression[]1290 ...expressions: readonly TemplateExpression[]1291 ): ExecaSyncReturnValue<StricterOptions<OptionsType, SyncOptions>>;1292};12931294/**
84 unmodified lines
modified:index.test-d.ts+92 added-22 removed
19 unmodified lines
20 type ExecaSyncReturnValue,21 type ExecaSyncError,22} from './index.js';2324const fileUrl = new URL('file:///test');2526type AnySyncChunk = string | Uint8Array | undefined;27type AnyChunk = AnySyncChunk | string[] | Uint8Array[] | unknown[];28expectType<Writable | null>({} as ExecaChildProcess['stdin']);29expectType<Readable | null>({} as ExecaChildProcess['stdout']);
57 unmodified lines
87 const bufferResult = await execaBufferPromise;8889 const scriptPromise = $`unicorns`;9089 expectType<typeof bufferResult>(await execaPromise.pipe(execaBufferPromise));90 expectType<typeof bufferResult>(await scriptPromise.pipe(execaBufferPromise));91 expectNotType<typeof bufferResult>(await execaPromise.pipe(execaPromise));92 expectNotType<typeof bufferResult>(await scriptPromise.pipe(execaPromise));93 expectType<ExecaReturnValue<{}>>(await execaPromise.pipe`stdin`);94 expectType<ExecaReturnValue<{}>>(await scriptPromise.pipe`stdin`);95 expectType<typeof bufferResult>(await execaPromise.pipe(execaPromise).pipe(execaBufferPromise));96 expectType<typeof bufferResult>(await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise));97 expectType<ExecaReturnValue<{}>>(await execaPromise.pipe`stdin`.pipe`stdin`);98 expectType<ExecaReturnValue<{}>>(await scriptPromise.pipe`stdin`.pipe`stdin`);99 expectType<ExecaReturnValue<{}>>(await execaPromise.pipe(execaPromise).pipe`stdin`);100 expectType<ExecaReturnValue<{}>>(await scriptPromise.pipe(execaPromise).pipe`stdin`);101 expectType<typeof bufferResult>(await execaPromise.pipe`stdin`.pipe(execaBufferPromise));102 expectType<typeof bufferResult>(await scriptPromise.pipe`stdin`.pipe(execaBufferPromise));91 const pipeOptions = {from: 'stderr', all: true} as const;9293 type BufferExecaReturnValue = typeof bufferResult;94 type EmptyExecaReturnValue = ExecaReturnValue<{}>;95 type ShortcutExecaReturnValue = ExecaReturnValue<typeof pipeOptions>;9697 expectType<BufferExecaReturnValue>(await execaPromise.pipe(execaBufferPromise));98 expectType<BufferExecaReturnValue>(await scriptPromise.pipe(execaBufferPromise));99 expectNotType<BufferExecaReturnValue>(await execaPromise.pipe(execaPromise));100 expectNotType<BufferExecaReturnValue>(await scriptPromise.pipe(execaPromise));101 expectType<EmptyExecaReturnValue>(await execaPromise.pipe`stdin`);102 expectType<EmptyExecaReturnValue>(await scriptPromise.pipe`stdin`);103 expectType<ShortcutExecaReturnValue>(await execaPromise.pipe('stdin', pipeOptions));104 expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe('stdin', pipeOptions));105 expectType<BufferExecaReturnValue>(await execaPromise.pipe(execaPromise).pipe(execaBufferPromise));106 expectType<BufferExecaReturnValue>(await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise));107 expectType<EmptyExecaReturnValue>(await execaPromise.pipe(execaPromise).pipe`stdin`);108 expectType<EmptyExecaReturnValue>(await scriptPromise.pipe(execaPromise).pipe`stdin`);109 expectType<ShortcutExecaReturnValue>(await execaPromise.pipe(execaPromise).pipe('stdin', pipeOptions));110 expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe(execaPromise).pipe('stdin', pipeOptions));111 expectType<BufferExecaReturnValue>(await execaPromise.pipe`stdin`.pipe(execaBufferPromise));112 expectType<BufferExecaReturnValue>(await scriptPromise.pipe`stdin`.pipe(execaBufferPromise));113 expectType<EmptyExecaReturnValue>(await execaPromise.pipe`stdin`.pipe`stdin`);114 expectType<EmptyExecaReturnValue>(await scriptPromise.pipe`stdin`.pipe`stdin`);115 expectType<ShortcutExecaReturnValue>(await execaPromise.pipe`stdin`.pipe('stdin', pipeOptions));116 expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe`stdin`.pipe('stdin', pipeOptions));117 expectType<BufferExecaReturnValue>(await execaPromise.pipe('pipe').pipe(execaBufferPromise));118 expectType<BufferExecaReturnValue>(await scriptPromise.pipe('pipe').pipe(execaBufferPromise));119 expectType<EmptyExecaReturnValue>(await execaPromise.pipe('pipe').pipe`stdin`);120 expectType<EmptyExecaReturnValue>(await scriptPromise.pipe('pipe').pipe`stdin`);121 expectType<ShortcutExecaReturnValue>(await execaPromise.pipe('pipe').pipe('stdin', pipeOptions));122 expectType<ShortcutExecaReturnValue>(await scriptPromise.pipe('pipe').pipe('stdin', pipeOptions));123 await execaPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});124 await scriptPromise.pipe(execaPromise).pipe(execaBufferPromise, {from: 'stdout'});105 await execaPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;106 await scriptPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;107 await execaPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});108 await scriptPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});125 await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;126 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe`stdin`;127 await execaPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe('stdin');128 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'}).pipe('stdin');129 await execaPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});130 await scriptPromise.pipe`stdin`.pipe(execaBufferPromise, {from: 'stdout'});131 await execaPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;132 await scriptPromise.pipe`stdin`.pipe({from: 'stdout'})`stdin`;133 await execaPromise.pipe`stdin`.pipe('stdin', {from: 'stdout'});134 await scriptPromise.pipe`stdin`.pipe('stdin', {from: 'stdout'});135 expectError(execaPromise.pipe(execaBufferPromise).stdout);136 expectError(scriptPromise.pipe(execaBufferPromise).stdout);137 expectError(execaPromise.pipe`stdin`.stdout);138 expectError(scriptPromise.pipe`stdin`.stdout);139 expectError(execaPromise.pipe('stdin').stdout);140 expectError(scriptPromise.pipe('stdin').stdout);141 expectError(execaPromise.pipe(createWriteStream('output.txt')));142 expectError(scriptPromise.pipe(createWriteStream('output.txt')));117 expectError(execaPromise.pipe('output.txt'));118 expectError(scriptPromise.pipe('output.txt'));143 expectError(execaPromise.pipe(false));144 expectError(scriptPromise.pipe(false));145 await execaPromise.pipe(execaBufferPromise, {});146 await scriptPromise.pipe(execaBufferPromise, {});147 await execaPromise.pipe({})`stdin`;148 await scriptPromise.pipe({})`stdin`;149 await execaPromise.pipe('stdin', {});150 await scriptPromise.pipe('stdin', {});151 expectError(execaPromise.pipe(execaBufferPromise, 'stdout'));152 expectError(scriptPromise.pipe(execaBufferPromise, 'stdout'));153 expectError(execaPromise.pipe('stdout')`stdin`);154 expectError(scriptPromise.pipe('stdout')`stdin`);155 await execaPromise.pipe(execaBufferPromise, {from: 'stdout'});156 await scriptPromise.pipe(execaBufferPromise, {from: 'stdout'});157 await execaPromise.pipe({from: 'stdout'})`stdin`;158 await scriptPromise.pipe({from: 'stdout'})`stdin`;159 await execaPromise.pipe('stdin', {from: 'stdout'});160 await scriptPromise.pipe('stdin', {from: 'stdout'});161 await execaPromise.pipe(execaBufferPromise, {from: 'stderr'});162 await scriptPromise.pipe(execaBufferPromise, {from: 'stderr'});163 await execaPromise.pipe({from: 'stderr'})`stdin`;164 await scriptPromise.pipe({from: 'stderr'})`stdin`;165 await execaPromise.pipe('stdin', {from: 'stderr'});166 await scriptPromise.pipe('stdin', {from: 'stderr'});167 await execaPromise.pipe(execaBufferPromise, {from: 'all'});168 await scriptPromise.pipe(execaBufferPromise, {from: 'all'});169 await execaPromise.pipe({from: 'all'})`stdin`;170 await scriptPromise.pipe({from: 'all'})`stdin`;171 await execaPromise.pipe('stdin', {from: 'all'});172 await scriptPromise.pipe('stdin', {from: 'all'});173 await execaPromise.pipe(execaBufferPromise, {from: 3});174 await scriptPromise.pipe(execaBufferPromise, {from: 3});175 await execaPromise.pipe({from: 3})`stdin`;176 await scriptPromise.pipe({from: 3})`stdin`;177 await execaPromise.pipe('stdin', {from: 3});178 await scriptPromise.pipe('stdin', {from: 3});179 expectError(execaPromise.pipe(execaBufferPromise, {from: 'other'}));180 expectError(scriptPromise.pipe(execaBufferPromise, {from: 'other'}));181 expectError(execaPromise.pipe({from: 'other'})`stdin`);182 expectError(scriptPromise.pipe({from: 'other'})`stdin`);183 expectError(execaPromise.pipe('stdin', {from: 'other'}));184 expectError(scriptPromise.pipe('stdin', {from: 'other'}));185 await execaPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});186 await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: new AbortController().signal});187 await execaPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;188 await scriptPromise.pipe({unpipeSignal: new AbortController().signal})`stdin`;189 await execaPromise.pipe('stdin', {unpipeSignal: new AbortController().signal});190 await scriptPromise.pipe('stdin', {unpipeSignal: new AbortController().signal});191 expectError(await execaPromise.pipe(execaBufferPromise, {unpipeSignal: true}));192 expectError(await scriptPromise.pipe(execaBufferPromise, {unpipeSignal: true}));193 expectError(await execaPromise.pipe({unpipeSignal: true})`stdin`);194 expectError(await scriptPromise.pipe({unpipeSignal: true})`stdin`);195 expectError(await execaPromise.pipe('stdin', {unpipeSignal: true}));196 expectError(await scriptPromise.pipe('stdin', {unpipeSignal: true}));197 expectError(await execaPromise.pipe({})({}));198 expectError(await scriptPromise.pipe({})({}));199 expectError(await execaPromise.pipe({})(execaPromise));200 expectError(await scriptPromise.pipe({})(execaPromise));201 expectError(await execaPromise.pipe({})('stdin'));202 expectError(await scriptPromise.pipe({})('stdin'));203204 expectType<EmptyExecaReturnValue>(await execaPromise.pipe('stdin'));205 await execaPromise.pipe('stdin');206 await execaPromise.pipe(fileUrl);207 await execaPromise.pipe('stdin', []);208 await execaPromise.pipe('stdin', ['foo', 'bar']);209 await execaPromise.pipe('stdin', ['foo', 'bar'], {});210 await execaPromise.pipe('stdin', ['foo', 'bar'], {from: 'stderr', all: true});211 await execaPromise.pipe('stdin', {from: 'stderr'});212 await execaPromise.pipe('stdin', {all: true});213 expectError(await execaPromise.pipe(['foo', 'bar']));214 expectError(await execaPromise.pipe('stdin', 'foo'));215 expectError(await execaPromise.pipe('stdin', [false]));216 expectError(await execaPromise.pipe('stdin', [], false));217 expectError(await execaPromise.pipe('stdin', {other: true}));218 expectError(await execaPromise.pipe('stdin', [], {other: true}));219 expectError(await execaPromise.pipe('stdin', {from: 'other'}));220 expectError(await execaPromise.pipe('stdin', [], {from: 'other'}));221222 const pipeResult = await execaPromise.pipe`stdin`;223 expectType<string>(pipeResult.stdout);224 const ignorePipeResult = await execaPromise.pipe({stdout: 'ignore'})`stdin`;225 expectType<undefined>(ignorePipeResult.stdout);
2 unmodified lines
228 expectType<string>(scriptPipeResult.stdout);229 const ignoreScriptPipeResult = await scriptPromise.pipe({stdout: 'ignore'})`stdin`;230 expectType<undefined>(ignoreScriptPipeResult.stdout);231232 const shortcutPipeResult = await execaPromise.pipe('stdin');233 expectType<string>(shortcutPipeResult.stdout);234 const ignoreShortcutPipeResult = await execaPromise.pipe('stdin', {stdout: 'ignore'});235 expectType<undefined>(ignoreShortcutPipeResult.stdout);236237 const scriptShortcutPipeResult = await scriptPromise.pipe('stdin');238 expectType<string>(scriptShortcutPipeResult.stdout);239 const ignoreShortcutScriptPipeResult = await scriptPromise.pipe('stdin', {stdout: 'ignore'});240 expectType<undefined>(ignoreShortcutScriptPipeResult.stdout);241242 expectType<Readable>(execaPromise.all);243 const noAllPromise = execa('unicorns');244 expectType<undefined>(noAllPromise.all);245 const noAllResult = await noAllPromise;
625 unmodified lines
871const asyncStringGenerator = async function * () {872 yield '';873};874803const fileUrl = new URL('file:///test');804875expectAssignable<Options>({cleanup: false});876expectNotAssignable<SyncOptions>({cleanup: false});877expectAssignable<SyncOptions>({preferLocal: false});878
683 unmodified lines
modified:readme.md+26 added-9 removed
192 unmodified lines
193import {execa} from 'execa';194195// Similar to `npm run build | sort | head -n2` in Bash196const {stdout, pipedFrom} = await execa('npm', ['run', 'build'])197 .pipe(execa('sort'))198 .pipe(execa('head', ['-n2']));197 .pipe('sort')198 .pipe('head', ['-n2']);199console.log(stdout); // Result of `head -n2`200console.log(pipedFrom[0]); // Result of `sort`201console.log(pipedFrom[0].pipedFrom[0]); // Result of `npm run build`202```
113 unmodified lines
316Same as [`execa()`](#execacommandcommand-options), [`execaCommand()`](#execacommand-command-options), [$\`command\`](#command) but synchronous.317318Cannot use the following options: [`all`](#all-2), [`cleanup`](#cleanup), [`buffer`](#buffer), [`detached`](#detached), [`ipc`](#ipc), [`serialization`](#serialization), [`signal`](#signal) and [`lines`](#lines). Also, the [`stdin`](#stdin), [`stdout`](#stdout-1), [`stderr`](#stderr-1), [`stdio`](#stdio-1) and [`input`](#input) options cannot be an array, an iterable or a web stream. Node.js streams [must have a file descriptor](#redirect-a-nodejs-stream-fromto-stdinstdoutstderr) unless the `input` option is used.319320Returns or throws a [`childProcessResult`](#childProcessResult). The [`childProcess`](#childprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipesecondchildprocess-pipeoptions) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.320Returns or throws a [`childProcessResult`](#childProcessResult). The [`childProcess`](#childprocess) is not returned: its methods and properties are not available. This includes [`.kill()`](https://nodejs.org/api/child_process.html#subprocesskillsignal), [`.pid`](https://nodejs.org/api/child_process.html#subprocesspid), [`.pipe()`](#pipefile-arguments-options) and the [`.stdin`/`.stdout`/`.stderr`](https://nodejs.org/api/child_process.html#subprocessstdout) streams.321322### Shell syntax323324For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell` option](#shell) is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.
13 unmodified lines
338This is `undefined` if either:339- the [`all` option](#all-2) is `false` (the default value)340- both [`stdout`](#stdout-1) and [`stderr`](#stderr-1) options are set to [`'inherit'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)341342#### pipe(secondChildProcess, pipeOptions?)342#### pipe(file, arguments?, options?)343344`secondChildProcess`: [`execa()` return value](#pipe-multiple-processes)\345`pipeOptions`: [`PipeOptions`](#pipeoptions)\344`file`: `string | URL`\345`arguments`: `string[]`\346`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\347_Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)348349[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process' `stdout` to a second Execa child process' `stdin`. This resolves with that second process' [result](#childprocessresult). If either process is rejected, this is rejected with that process' [error](#childprocessresult) instead.350351This follows the same syntax as [`execa(file, arguments?, options?)`](#execafile-arguments-options) except both [regular options](#options-1) and [pipe-specific options](#pipeoptions) can be specified.352353This can be called multiple times to chain a series of processes.354355Multiple child processes can be piped to the same process. Conversely, the same child process can be piped to multiple other processes.356357This is usually the preferred method to pipe processes.358359#### pipe`command`360#### pipe(options)`command`361362`command`: `string`\363`options`: [`Options`](#options-1) and [`PipeOptions`](#pipeoptions)\364_Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)365361Like [`.pipe(secondChildProcess)`](#pipesecondchildprocess-pipeoptions) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as [`$`](#command). `options` can be used to specify both [pipe options](#pipeoptions) and [regular options](#options-1).366Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using a [`command` template string](docs/scripts.md#piping-stdout-to-another-command) instead. This follows the same syntax as [`$`](#command).367368This is the preferred method to pipe processes when using [`$`](#command).369370#### pipe(secondChildProcess, pipeOptions?)371372`secondChildProcess`: [`execa()` return value](#childprocess)\373`pipeOptions`: [`PipeOptions`](#pipeoptions)\374_Returns_: [`Promise<ChildProcessResult>`](#childprocessresult)375376Like [`.pipe(file, arguments?, options?)`](#pipefile-arguments-options) but using the [return value](#childprocess) of another `execa()` call instead.377378This is the most advanced method to pipe processes. It is useful in specific cases, such as piping multiple child processes to the same process.379380##### pipeOptions381382Type: `object`383
11 unmodified lines
395Type: [`AbortSignal`](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal)396397Unpipe the child process when the signal aborts.398382The [`.pipe()`](#pipesecondchildprocess-pipeoptions) method will be rejected with a cancellation error.399The [`.pipe()`](#pipefile-arguments-options) method will be rejected with a cancellation error.400401#### kill(signal, error?)402#### kill(error?)403
160 unmodified lines
564Type: [`ChildProcessResult[]`](#childprocessresult)565566Results of the other processes that were [piped](#pipe-multiple-processes) into this child process. This is useful to inspect a series of child processes piped with each other.567551This array is initially empty and is populated each time the [`.pipe()`](#pipesecondchildprocess-pipeoptions) method resolves.568This array is initially empty and is populated each time the [`.pipe()`](#pipefile-arguments-options) method resolves.569570### options571572Type: `object`
468 unmodified lines