Skip to content
Myr

Refactor types (#685)

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

authored by ehmicky · committed by GitHub · parent 938d4b1 · Browse files · 2 files+70 added−37 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+70 added−37 removed

  • other:+70 added−37 removed

2 files+70 added−37 removed

modified:index.d.ts+60 added-37 removed
73 unmodified lines
74 | undefined;75type DefaultEncodingOption = 'utf8';76type BufferEncodingOption = 'buffer';7778type TupleItem<79 Tuple extends readonly unknown[],80 Index extends string,81> = Tuple[Index extends keyof Tuple ? Index : number];8278// Whether `result.stdout|stderr|all` is `undefined`, excluding the `buffer` option79type IgnoresStreamResult<80 StreamIndex extends string,81 OptionsType extends CommonOptions = CommonOptions,82 // `result.stdin` is always `undefined`83> = StreamIndex extends '0' ? true84 // When using `stdout|stderr: 'inherit'`, or `'ignore'`, etc. , `result.std*` is `undefined`90 : OptionsType[TupleItem<StdioOptionNames, StreamIndex>] extends NoOutputStdioOption ? true91 // Same but with `stdio: 'ignore'`92 : OptionsType['stdio'] extends NoOutputStdioOption ? true93 // Same but with `stdio: ['ignore', 'ignore', 'ignore', ...]`94 : OptionsType['stdio'] extends StdioOptionsArray95 ? TupleItem<OptionsType['stdio'], StreamIndex> extends StdioOptionsArray[number]96 ? IgnoresStdioResult<TupleItem<OptionsType['stdio'], StreamIndex>>97 : false98 : false;85 : IgnoresNormalPropertyResult<StreamIndex, OptionsType> extends true ? true86 // Otherwise87 : IgnoresStdioPropertyResult<StreamIndex, OptionsType['stdio']>;8889type IgnoresNormalPropertyResult<90 StreamIndex extends string,91 OptionsType extends CommonOptions = CommonOptions,92> = StreamIndex extends keyof StdioOptionNames93 ? StdioOptionNames[StreamIndex] extends keyof OptionsType94 ? OptionsType[StdioOptionNames[StreamIndex]] extends NoOutputStdioOption95 ? true96 : false97 : false98 : false;99100type StdioOptionNames = ['stdin', 'stdout', 'stderr'];101102type IgnoresStdioPropertyResult<103 StreamIndex extends string,104 StdioOptionType extends StdioOptions | undefined,105 // Same but with `stdio: 'ignore'`106> = StdioOptionType extends NoOutputStdioOption ? true107// Same but with `stdio: ['ignore', 'ignore', 'ignore', ...]`108 : StdioOptionType extends StdioOptionsArray109 ? StreamIndex extends keyof StdioOptionType110 ? StdioOptionType[StreamIndex] extends StdioOption111 ? IgnoresStdioResult<StdioOptionType[StreamIndex]>112 : false113 : false114 : false;115116// Whether `result.stdio[*]` is `undefined`103type IgnoresStdioResult<104 StdioOption extends StdioOptionsArray[number],105> = StdioOption extends NoOutputStdioOption106 ? true117type IgnoresStdioResult<StdioOptionType extends StdioOption> =118 StdioOptionType extends NoOutputStdioOption ? true119 // `result.stdio[3+]` is `undefined` when it is an input stream108 : StdioOption extends StdinOption109 ? StdioOption extends StdoutStderrOption110 ? false111 : true112 : false;120 : StdioOptionType extends StdinOption121 ? StdioOptionType extends StdoutStderrOption122123 ? false124 : true125 : false;126127// Whether `result.stdout|stderr|all` is `undefined`128type IgnoresStreamOutput<129 StreamIndex extends string,130 OptionsType extends CommonOptions = CommonOptions,118> = OptionsType extends {buffer: false} ? true119 : IgnoresStreamResult<StreamIndex, OptionsType> extends true ? true : false;131> = HasBuffer<OptionsType> extends false132 ? true133 : IgnoresStreamResult<StreamIndex, OptionsType>;134135type HasBuffer<OptionsType extends CommonOptions> = OptionsType extends Options136 ? HasBufferOption<OptionsType['buffer']>137 : true;138139type HasBufferOption<BufferOption extends Options['buffer']> = BufferOption extends false ? false : true;140141// Type of `result.stdout|stderr`142type StdioOutput<143 StreamIndex extends string,144 OptionsType extends CommonOptions = CommonOptions,125> = IgnoresStreamOutput<StreamIndex, OptionsType> extends true145> = StdioOutputResult<IgnoresStreamOutput<StreamIndex, OptionsType>, OptionsType>;146147type StdioOutputResult<148 StreamOutputIgnored extends boolean,149 OptionsType extends CommonOptions = CommonOptions,150> = StreamOutputIgnored extends true151 ? undefined152 : StreamResult<OptionsType>;153129type StreamResult<OptionsType extends CommonOptions = CommonOptions> =130 // Default value for `encoding`, when `OptionsType` is `{}`131 unknown extends OptionsType['encoding'] ? string132 // Any value for `encoding`, when `OptionsType` is `Options`133 : EncodingOption extends OptionsType['encoding'] ? Uint8Array | string134 // `encoding: buffer`135 : OptionsType['encoding'] extends 'buffer' ? Uint8Array136 // `encoding: not buffer`137 : string;154type StreamResult<OptionsType extends CommonOptions = CommonOptions> = StreamEncoding<OptionsType['encoding']>;155156type StreamEncoding<Encoding extends CommonOptions['encoding']> = Encoding extends 'buffer' ? Uint8Array : string;157158// Type of `result.all`159type AllOutput<OptionsType extends Options = Options> = AllOutputProperty<OptionsType['all'], OptionsType>;160161type AllOutputProperty<
23 unmodified lines
185186type StricterOptions<187 WideOptions extends CommonOptions,188 StrictOptions extends CommonOptions,170> = keyof WideOptions extends never ? {} : WideOptions & StrictOptions;189> = WideOptions extends StrictOptions ? WideOptions : StrictOptions;190191type CommonOptions<IsSync extends boolean = boolean> = {192 /**193 Prefer locally installed binaries when looking for a binary to execute.
459 unmodified lines
653654type StreamUnlessIgnored<655 StreamIndex extends string,656 OptionsType extends Options = Options,638> = IgnoresStreamResult<StreamIndex, OptionsType> extends true ? null : Readable;657> = ChildProcessStream<IgnoresStreamResult<StreamIndex, OptionsType>>;658659type ChildProcessStream<StreamResultIgnored extends boolean> = StreamResultIgnored extends true660 ? null661 : Readable;662663export type ExecaChildPromise<OptionsType extends Options = Options> = {664 stdout: StreamUnlessIgnored<'1', OptionsType>;665666 stderr: StreamUnlessIgnored<'2', OptionsType>;
530 unmodified lines
modified:index.test-d.ts+10 added
19 unmodified lines
20 type ExecaSyncReturnValue,21 type ExecaSyncError,22} from './index.js';2324expectType<Readable | null>({} as ExecaChildProcess['stdout']);25expectType<Readable | null>({} as ExecaChildProcess['stderr']);26expectType<string | Uint8Array | undefined>({} as ExecaReturnValue['stdout']);27expectType<string | Uint8Array | undefined>({} as ExecaReturnValue['stderr']);28expectType<string | Uint8Array | undefined>({} as ExecaReturnValue['all']);29expectType<[undefined, string | Uint8Array | undefined, string | Uint8Array | undefined]>({} as ExecaReturnValue['stdio']);30expectType<string | Uint8Array | undefined>({} as ExecaSyncReturnValue['stdout']);31expectType<string | Uint8Array | undefined>({} as ExecaSyncReturnValue['stderr']);32expectType<[undefined, string | Uint8Array | undefined, string | Uint8Array | undefined]>({} as ExecaSyncReturnValue['stdio']);3334try {35 const execaPromise = execa('unicorns', {all: true});36 execaPromise.cancel();37
1023 unmodified lines