Skip to content
Myr

Fix type of `result.all` (#684)

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

authored by ehmicky · committed by GitHub · parent 8062913 · Browse files · 2 files+96 added−82 removed
This commit

State

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

Diff stats

2 files+96 added−82 removed

  • other:+96 added−82 removed

2 files+96 added−82 removed

modified:index.d.ts+11 added-4 removed
135 unmodified lines
136 // `encoding: not buffer`137 : string;138139// Type of `result.all`140type AllOutput<OptionsType extends Options = Options> = IgnoresStreamOutput<'1', OptionsType> extends true141 ? StdioOutput<'2', OptionsType>142 : StdioOutput<'1', OptionsType>;140type AllOutput<OptionsType extends Options = Options> = AllOutputProperty<OptionsType['all'], OptionsType>;141142type AllOutputProperty<143 AllOption extends Options['all'] = Options['all'],144 OptionsType extends Options = Options,145> = AllOption extends true146 ? IgnoresStreamOutput<'1', OptionsType> extends true147 ? StdioOutput<'2', OptionsType>148 : StdioOutput<'1', OptionsType>149 : undefined;150151// Type of `result.stdio`152type StdioArrayOutput<OptionsType extends CommonOptions = CommonOptions> = MapStdioOptions<153OptionsType['stdio'] extends StdioOptionsArray ? OptionsType['stdio'] : ['pipe', 'pipe', 'pipe'],154OptionsType
435 unmodified lines
590 This is `undefined` if either:591 - the `all` option is `false` (default value)592 - both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `'ignore'`, `Stream` or `integer`](https://nodejs.org/api/child_process.html#child_process_options_stdio)593 */587 all?: AllOutput<OptionsType>;594 all: AllOutput<OptionsType>;595});596597export type ExecaReturnValue<OptionsType extends Options = Options> = ExecaCommonReturnValue<false, OptionsType>;598export type ExecaSyncReturnValue<OptionsType extends SyncOptions = SyncOptions> = ExecaCommonReturnValue<true, OptionsType>;
575 unmodified lines
modified:index.test-d.ts+85 added-78 removed
20 unmodified lines
21 type ExecaSyncError,22} from './index.js';2324try {25 const execaPromise = execa('unicorns');25 const execaPromise = execa('unicorns', {all: true});26 execaPromise.cancel();27 expectType<Readable | undefined>(execaPromise.all);2729 const execaBufferPromise = execa('unicorns', {encoding: 'buffer'});28 const execaBufferPromise = execa('unicorns', {encoding: 'buffer', all: true});29 const writeStream = createWriteStream('output.txt');3031 expectAssignable<Function | undefined>(execaPromise.pipeStdout);32 expectAssignable<ExecaChildProcess>(execaPromise.pipeStdout!('file.txt'));
24 unmodified lines
57 expectAssignable<ExecaChildProcess>(execaPromise.pipeAll!(execaBufferPromise));58 expectAssignable<ExecaChildProcess>(execaBufferPromise.pipeAll!(execaPromise));59 expectAssignable<ExecaChildProcess>(execaBufferPromise.pipeAll!(execaBufferPromise));6062 const unicornsResult = await execaPromise;61 expectType<Readable | undefined>(execaPromise.all);62 const noAllPromise = execa('unicorns');63 expectType<Readable | undefined>(noAllPromise.all);64 const noAllResult = await noAllPromise;65 expectType<undefined>(noAllResult.all);6667 const unicornsResult = await execaPromise;68 expectType<string>(unicornsResult.command);69 expectType<string>(unicornsResult.escapedCommand);70 expectType<number | undefined>(unicornsResult.exitCode);71 expectType<boolean>(unicornsResult.failed);
8 unmodified lines
80 expectType<string>(unicornsResult.stdout);81 expectType<string>(unicornsResult.stdio[1]);82 expectType<string>(unicornsResult.stderr);83 expectType<string>(unicornsResult.stdio[2]);80 expectType<string | undefined>(unicornsResult.all);84 expectType<string>(unicornsResult.all);85 expectType<string | undefined>(unicornsResult.stdio[3 as number]);8687 expectType<Readable>(execaBufferPromise.stdout);88 expectType<Readable>(execaBufferPromise.stderr);
1 unmodified line
90 expectType<Uint8Array>(bufferResult.stdout);91 expectType<Uint8Array>(bufferResult.stdio[1]);92 expectType<Uint8Array>(bufferResult.stderr);93 expectType<Uint8Array>(bufferResult.stdio[2]);90 expectType<Uint8Array | undefined>(bufferResult.all);94 expectType<Uint8Array>(bufferResult.all);9592 const noBufferPromise = execa('unicorns', {buffer: false});96 const noBufferPromise = execa('unicorns', {buffer: false, all: true});97 expectType<Readable>(noBufferPromise.stdout);98 expectType<Readable>(noBufferPromise.stderr);99 const noBufferResult = await noBufferPromise;100 expectType<undefined>(noBufferResult.stdout);
1 unmodified line
102 expectType<undefined>(noBufferResult.stderr);103 expectType<undefined>(noBufferResult.stdio[2]);104 expectType<undefined>(noBufferResult.all);105102 const multipleStdoutPromise = execa('unicorns', {stdout: ['inherit', 'pipe'] as ['inherit', 'pipe']});106 const multipleStdoutPromise = execa('unicorns', {stdout: ['inherit', 'pipe'] as ['inherit', 'pipe'], all: true});107 expectType<Readable>(multipleStdoutPromise.stdout);108 expectType<Readable>(multipleStdoutPromise.stderr);109 const multipleStdoutResult = await multipleStdoutPromise;110 expectType<string>(multipleStdoutResult.stdout);111 expectType<string>(multipleStdoutResult.stdio[1]);112 expectType<string>(multipleStdoutResult.stderr);113 expectType<string>(multipleStdoutResult.stdio[2]);110 expectType<string | undefined>(multipleStdoutResult.all);114 expectType<string>(multipleStdoutResult.all);115112 const ignoreBothPromise = execa('unicorns', {stdout: 'ignore', stderr: 'ignore'});116 const ignoreBothPromise = execa('unicorns', {stdout: 'ignore', stderr: 'ignore', all: true});117 expectType<null>(ignoreBothPromise.stdout);118 expectType<null>(ignoreBothPromise.stderr);119 const ignoreBothResult = await ignoreBothPromise;120 expectType<undefined>(ignoreBothResult.stdout);
1 unmodified line
122 expectType<undefined>(ignoreBothResult.stderr);123 expectType<undefined>(ignoreBothResult.stdio[2]);124 expectType<undefined>(ignoreBothResult.all);125122 const ignoreAllPromise = execa('unicorns', {stdio: 'ignore'});126 const ignoreAllPromise = execa('unicorns', {stdio: 'ignore', all: true});127 expectType<null>(ignoreAllPromise.stdout);128 expectType<null>(ignoreAllPromise.stderr);129 const ignoreAllResult = await ignoreAllPromise;130 expectType<undefined>(ignoreAllResult.stdout);
1 unmodified line
132 expectType<undefined>(ignoreAllResult.stderr);133 expectType<undefined>(ignoreAllResult.stdio[2]);134 expectType<undefined>(ignoreAllResult.all);135132 const ignoreStdioArrayPromise = execa('unicorns', {stdio: ['pipe', 'ignore', 'pipe']});136 const ignoreStdioArrayPromise = execa('unicorns', {stdio: ['pipe', 'ignore', 'pipe'], all: true});137 expectType<null>(ignoreStdioArrayPromise.stdout);138 expectType<Readable>(ignoreStdioArrayPromise.stderr);139 const ignoreStdioArrayResult = await ignoreStdioArrayPromise;140 expectType<undefined>(ignoreStdioArrayResult.stdout);141 expectType<undefined>(ignoreStdioArrayResult.stdio[1]);142 expectType<string>(ignoreStdioArrayResult.stderr);143 expectType<string>(ignoreStdioArrayResult.stdio[2]);140 expectType<string | undefined>(ignoreStdioArrayResult.all);144 expectType<string>(ignoreStdioArrayResult.all);145142 const ignoreStdoutPromise = execa('unicorns', {stdout: 'ignore'});146 const ignoreStdoutPromise = execa('unicorns', {stdout: 'ignore', all: true});147 expectType<null>(ignoreStdoutPromise.stdout);148 expectType<Readable>(ignoreStdoutPromise.stderr);149 const ignoreStdoutResult = await ignoreStdoutPromise;150 expectType<undefined>(ignoreStdoutResult.stdout);151 expectType<string>(ignoreStdoutResult.stderr);148 expectType<string | undefined>(ignoreStdoutResult.all);152 expectType<string>(ignoreStdoutResult.all);153150 const ignoreArrayStdoutResult = await execa('unicorns', {stdout: ['ignore'] as ['ignore']});154 const ignoreArrayStdoutResult = await execa('unicorns', {stdout: ['ignore'] as ['ignore'], all: true});155 expectType<undefined>(ignoreArrayStdoutResult.stdout);156 expectType<string>(ignoreArrayStdoutResult.stderr);153 expectType<string | undefined>(ignoreArrayStdoutResult.all);157 expectType<string>(ignoreArrayStdoutResult.all);158155 const ignoreStderrPromise = execa('unicorns', {stderr: 'ignore'});159 const ignoreStderrPromise = execa('unicorns', {stderr: 'ignore', all: true});160 expectType<Readable>(ignoreStderrPromise.stdout);161 expectType<null>(ignoreStderrPromise.stderr);162 const ignoreStderrResult = await ignoreStderrPromise;163 expectType<string>(ignoreStderrResult.stdout);164 expectType<undefined>(ignoreStderrResult.stderr);161 expectType<string | undefined>(ignoreStderrResult.all);165 expectType<string>(ignoreStderrResult.all);166163 const ignoreArrayStderrResult = await execa('unicorns', {stderr: ['ignore'] as ['ignore']});167 const ignoreArrayStderrResult = await execa('unicorns', {stderr: ['ignore'] as ['ignore'], all: true});168 expectType<string>(ignoreArrayStderrResult.stdout);169 expectType<undefined>(ignoreArrayStderrResult.stderr);166 expectType<string | undefined>(ignoreArrayStderrResult.all);170 expectType<string>(ignoreArrayStderrResult.all);171168 const inheritStdoutResult = await execa('unicorns', {stdout: 'inherit'});172 const inheritStdoutResult = await execa('unicorns', {stdout: 'inherit', all: true});173 expectType<undefined>(inheritStdoutResult.stdout);174 expectType<string>(inheritStdoutResult.stderr);171 expectType<string | undefined>(inheritStdoutResult.all);175 expectType<string>(inheritStdoutResult.all);176173 const inheritArrayStdoutResult = await execa('unicorns', {stdout: ['inherit'] as ['inherit']});177 const inheritArrayStdoutResult = await execa('unicorns', {stdout: ['inherit'] as ['inherit'], all: true});178 expectType<undefined>(inheritArrayStdoutResult.stdout);179 expectType<string>(inheritArrayStdoutResult.stderr);176 expectType<string | undefined>(inheritArrayStdoutResult.all);180 expectType<string>(inheritArrayStdoutResult.all);181178 const inheritStderrResult = await execa('unicorns', {stderr: 'inherit'});182 const inheritStderrResult = await execa('unicorns', {stderr: 'inherit', all: true});183 expectType<string>(inheritStderrResult.stdout);184 expectType<undefined>(inheritStderrResult.stderr);181 expectType<string | undefined>(inheritStderrResult.all);185 expectType<string>(inheritStderrResult.all);186183 const inheritArrayStderrResult = await execa('unicorns', {stderr: ['inherit'] as ['inherit']});187 const inheritArrayStderrResult = await execa('unicorns', {stderr: ['inherit'] as ['inherit'], all: true});188 expectType<string>(inheritArrayStderrResult.stdout);189 expectType<undefined>(inheritArrayStderrResult.stderr);186 expectType<string | undefined>(inheritArrayStderrResult.all);190 expectType<string>(inheritArrayStderrResult.all);191188 const ipcStdoutResult = await execa('unicorns', {stdout: 'ipc'});192 const ipcStdoutResult = await execa('unicorns', {stdout: 'ipc', all: true});193 expectType<undefined>(ipcStdoutResult.stdout);194 expectType<string>(ipcStdoutResult.stderr);191 expectType<string | undefined>(ipcStdoutResult.all);195 expectType<string>(ipcStdoutResult.all);196193 const ipcArrayStdoutResult = await execa('unicorns', {stdout: ['ipc'] as ['ipc']});197 const ipcArrayStdoutResult = await execa('unicorns', {stdout: ['ipc'] as ['ipc'], all: true});198 expectType<undefined>(ipcArrayStdoutResult.stdout);199 expectType<string>(ipcArrayStdoutResult.stderr);196 expectType<string | undefined>(ipcArrayStdoutResult.all);200 expectType<string>(ipcArrayStdoutResult.all);201198 const ipcStderrResult = await execa('unicorns', {stderr: 'ipc'});202 const ipcStderrResult = await execa('unicorns', {stderr: 'ipc', all: true});203 expectType<string>(ipcStderrResult.stdout);204 expectType<undefined>(ipcStderrResult.stderr);201 expectType<string | undefined>(ipcStderrResult.all);205 expectType<string>(ipcStderrResult.all);206203 const ipcArrayStderrResult = await execa('unicorns', {stderr: ['ipc'] as ['ipc']});207 const ipcArrayStderrResult = await execa('unicorns', {stderr: ['ipc'] as ['ipc'], all: true});208 expectType<string>(ipcArrayStderrResult.stdout);209 expectType<undefined>(ipcArrayStderrResult.stderr);206 expectType<string | undefined>(ipcArrayStderrResult.all);210 expectType<string>(ipcArrayStderrResult.all);211208 const numberStdoutResult = await execa('unicorns', {stdout: 1});212 const numberStdoutResult = await execa('unicorns', {stdout: 1, all: true});213 expectType<undefined>(numberStdoutResult.stdout);214 expectType<string>(numberStdoutResult.stderr);211 expectType<string | undefined>(numberStdoutResult.all);215 expectType<string>(numberStdoutResult.all);216213 const numberArrayStdoutResult = await execa('unicorns', {stdout: [1] as [1]});217 const numberArrayStdoutResult = await execa('unicorns', {stdout: [1] as [1], all: true});218 expectType<undefined>(numberArrayStdoutResult.stdout);219 expectType<string>(numberArrayStdoutResult.stderr);216 expectType<string | undefined>(numberArrayStdoutResult.all);220 expectType<string>(numberArrayStdoutResult.all);221218 const numberStderrResult = await execa('unicorns', {stderr: 1});222 const numberStderrResult = await execa('unicorns', {stderr: 1, all: true});223 expectType<string>(numberStderrResult.stdout);224 expectType<undefined>(numberStderrResult.stderr);221 expectType<string | undefined>(numberStderrResult.all);225 expectType<string>(numberStderrResult.all);226223 const numberArrayStderrResult = await execa('unicorns', {stderr: [1] as [1]});227 const numberArrayStderrResult = await execa('unicorns', {stderr: [1] as [1], all: true});228 expectType<string>(numberArrayStderrResult.stdout);229 expectType<undefined>(numberArrayStderrResult.stderr);226 expectType<string | undefined>(numberArrayStderrResult.all);230 expectType<string>(numberArrayStderrResult.all);231228 const streamStdoutResult = await execa('unicorns', {stdout: process.stdout});232 const streamStdoutResult = await execa('unicorns', {stdout: process.stdout, all: true});233 expectType<undefined>(streamStdoutResult.stdout);234 expectType<string>(streamStdoutResult.stderr);231 expectType<string | undefined>(streamStdoutResult.all);235 expectType<string>(streamStdoutResult.all);236233 const streamArrayStdoutResult = await execa('unicorns', {stdout: [process.stdout] as [typeof process.stdout]});237 const streamArrayStdoutResult = await execa('unicorns', {stdout: [process.stdout] as [typeof process.stdout], all: true});238 expectType<undefined>(streamArrayStdoutResult.stdout);239 expectType<string>(streamArrayStdoutResult.stderr);236 expectType<string | undefined>(streamArrayStdoutResult.all);240 expectType<string>(streamArrayStdoutResult.all);241238 const streamStderrResult = await execa('unicorns', {stderr: process.stdout});242 const streamStderrResult = await execa('unicorns', {stderr: process.stdout, all: true});243 expectType<string>(streamStderrResult.stdout);244 expectType<undefined>(streamStderrResult.stderr);241 expectType<string | undefined>(streamStderrResult.all);245 expectType<string>(streamStderrResult.all);246243 const streamArrayStderrResult = await execa('unicorns', {stderr: [process.stdout] as [typeof process.stdout]});247 const streamArrayStderrResult = await execa('unicorns', {stderr: [process.stdout] as [typeof process.stdout], all: true});248 expectType<string>(streamArrayStderrResult.stdout);249 expectType<undefined>(streamArrayStderrResult.stderr);246 expectType<string | undefined>(streamArrayStderrResult.all);250 expectType<string>(streamArrayStderrResult.all);251252 const fd3Result = await execa('unicorns', {stdio: ['pipe', 'pipe', 'pipe', 'pipe']});253 expectType<string>(fd3Result.stdio[3]);254
27 unmodified lines
282 expectType<string | undefined>(execaError.originalMessage);283284 expectType<undefined>(execaError.stdio[0]);285282 const execaStringError = error as ExecaError<{}>;286 const noAllError = error as ExecaError<{}>;287 expectType<undefined>(noAllError.all);288289 const execaStringError = error as ExecaError<{all: true}>;290 expectType<string>(execaStringError.stdout);291 expectType<string>(execaStringError.stdio[1]);292 expectType<string>(execaStringError.stderr);293 expectType<string>(execaStringError.stdio[2]);287 expectType<string | undefined>(execaStringError.all);294 expectType<string>(execaStringError.all);295289 const execaBufferError = error as ExecaError<{encoding: 'buffer'}>;296 const execaBufferError = error as ExecaError<{encoding: 'buffer'; all: true}>;297 expectType<Uint8Array>(execaBufferError.stdout);298 expectType<Uint8Array>(execaBufferError.stdio[1]);299 expectType<Uint8Array>(execaBufferError.stderr);300 expectType<Uint8Array>(execaBufferError.stdio[2]);294 expectType<Uint8Array | undefined>(execaBufferError.all);301 expectType<Uint8Array>(execaBufferError.all);302296 const noBufferError = error as ExecaError<{buffer: false}>;303 const noBufferError = error as ExecaError<{buffer: false; all: true}>;304 expectType<undefined>(noBufferError.stdout);305 expectType<undefined>(noBufferError.stdio[1]);306 expectType<undefined>(noBufferError.stderr);307 expectType<undefined>(noBufferError.stdio[2]);308 expectType<undefined>(noBufferError.all);309303 const ignoreStdoutError = error as ExecaError<{stdout: 'ignore'}>;310 const ignoreStdoutError = error as ExecaError<{stdout: 'ignore'; all: true}>;311 expectType<undefined>(ignoreStdoutError.stdout);312 expectType<undefined>(ignoreStdoutError.stdio[1]);313 expectType<string>(ignoreStdoutError.stderr);314 expectType<string>(ignoreStdoutError.stdio[2]);308 expectType<string | undefined>(ignoreStdoutError.all);315 expectType<string>(ignoreStdoutError.all);316310 const ignoreStderrError = error as ExecaError<{stderr: 'ignore'}>;317 const ignoreStderrError = error as ExecaError<{stderr: 'ignore'; all: true}>;318 expectType<string>(ignoreStderrError.stdout);319 expectType<undefined>(ignoreStderrError.stderr);313 expectType<string | undefined>(ignoreStderrError.all);320 expectType<string>(ignoreStderrError.all);321315 const inheritStdoutError = error as ExecaError<{stdout: 'inherit'}>;322 const inheritStdoutError = error as ExecaError<{stdout: 'inherit'; all: true}>;323 expectType<undefined>(inheritStdoutError.stdout);324 expectType<string>(inheritStdoutError.stderr);318 expectType<string | undefined>(inheritStdoutError.all);325 expectType<string>(inheritStdoutError.all);326320 const inheritStderrError = error as ExecaError<{stderr: 'inherit'}>;327 const inheritStderrError = error as ExecaError<{stderr: 'inherit'; all: true}>;328 expectType<string>(inheritStderrError.stdout);329 expectType<undefined>(inheritStderrError.stderr);323 expectType<string | undefined>(inheritStderrError.all);330 expectType<string>(inheritStderrError.all);331325 const ipcStdoutError = error as ExecaError<{stdout: 'ipc'}>;332 const ipcStdoutError = error as ExecaError<{stdout: 'ipc'; all: true}>;333 expectType<undefined>(ipcStdoutError.stdout);334 expectType<string>(ipcStdoutError.stderr);328 expectType<string | undefined>(ipcStdoutError.all);335 expectType<string>(ipcStdoutError.all);336330 const ipcStderrError = error as ExecaError<{stderr: 'ipc'}>;337 const ipcStderrError = error as ExecaError<{stderr: 'ipc'; all: true}>;338 expectType<string>(ipcStderrError.stdout);339 expectType<undefined>(ipcStderrError.stderr);333 expectType<string | undefined>(ipcStderrError.all);340 expectType<string>(ipcStderrError.all);341335 const numberStdoutError = error as ExecaError<{stdout: 1}>;342 const numberStdoutError = error as ExecaError<{stdout: 1; all: true}>;343 expectType<undefined>(numberStdoutError.stdout);344 expectType<string>(numberStdoutError.stderr);338 expectType<string | undefined>(numberStdoutError.all);345 expectType<string>(numberStdoutError.all);346340 const numberStderrError = error as ExecaError<{stderr: 1}>;347 const numberStderrError = error as ExecaError<{stderr: 1; all: true}>;348 expectType<string>(numberStderrError.stdout);349 expectType<undefined>(numberStderrError.stderr);343 expectType<string | undefined>(numberStderrError.all);350 expectType<string>(numberStderrError.all);351345 const streamStdoutError = error as ExecaError<{stdout: typeof process.stdout}>;352 const streamStdoutError = error as ExecaError<{stdout: typeof process.stdout; all: true}>;353 expectType<undefined>(streamStdoutError.stdout);354 expectType<string>(streamStdoutError.stderr);348 expectType<string | undefined>(streamStdoutError.all);355 expectType<string>(streamStdoutError.all);356350 const streamStderrError = error as ExecaError<{stderr: typeof process.stdout}>;357 const streamStderrError = error as ExecaError<{stderr: typeof process.stdout; all: true}>;358 expectType<string>(streamStderrError.stdout);359 expectType<undefined>(streamStderrError.stderr);353 expectType<string | undefined>(streamStderrError.all);360 expectType<string>(streamStderrError.all);361}362363try {364 const unicornsResult = execaSync('unicorns');
686 unmodified lines