Skip to content
Myr

Refactor types of Execa methods (#1114)

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

authored by ehmicky · committed by GitHub · parent 077749d · Browse files · 5 files+191 added−115 removed
This commit

State

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

Diff stats

5 files+191 added−115 removed

  • other:+191 added−115 removed

5 files+191 added−115 removed

modified:types/methods/command.d.ts+39 added-21 removed
modified:types/methods/main-async.d.ts+30 added-18 removed
1import type {Options} from '../arguments/options.js';2import type {ResultPromise} from '../subprocess/subprocess.js';3import type {TemplateString} from './template.js';45type Execa<OptionsType extends Options> = {6 <NewOptionsType extends Options = {}>(options: NewOptionsType): Execa<OptionsType & NewOptionsType>;78 (...templateString: TemplateString): ResultPromise<OptionsType>;910 <NewOptionsType extends Options = {}>(11 file: string | URL,12 arguments?: readonly string[],13 options?: NewOptionsType,14 ): ResultPromise<OptionsType & NewOptionsType>;1516 <NewOptionsType extends Options = {}>(17 file: string | URL,18 options?: NewOptionsType,19 ): ResultPromise<OptionsType & NewOptionsType>;20};215/**6Executes a command using `file ...arguments`.78When `command` is a template string, it includes both the `file` and its `arguments`.
309 unmodified lines
318[00:57:44.747] [1] ✘ Command failed with exit code 1: npm run test319[00:57:44.747] [1] ✘ (done in 89ms)320```321*/339export declare const execa: Execa<{}>;322export declare const execa: ExecaMethod<{}>;323324/**325`execa()` method either exported by Execa, or bound using `execa(options)`.326*/327type ExecaMethod<OptionsType extends Options> =328 & ExecaBind<OptionsType>329 & ExecaTemplate<OptionsType>330 & ExecaArrayLong<OptionsType>331 & ExecaArrayShort<OptionsType>;332333// `execa(options)` binding334type ExecaBind<OptionsType extends Options> =335 <NewOptionsType extends Options = {}>(options: NewOptionsType)336 => ExecaMethod<OptionsType & NewOptionsType>;337338// `execa`command`` template syntax339type ExecaTemplate<OptionsType extends Options> =340 (...templateString: TemplateString)341 => ResultPromise<OptionsType>;342343// `execa('file', ['argument'], {})` array syntax344type ExecaArrayLong<OptionsType extends Options> =345 <NewOptionsType extends Options = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)346 => ResultPromise<OptionsType & NewOptionsType>;347348// `execa('file', {})` array syntax349type ExecaArrayShort<OptionsType extends Options> =350 <NewOptionsType extends Options = {}>(file: string | URL, options?: NewOptionsType)351 => ResultPromise<OptionsType & NewOptionsType>;
modified:types/methods/main-sync.d.ts+29 added-18 removed
modified:types/methods/node.d.ts+30 added-18 removed
1import type {Options} from '../arguments/options.js';2import type {ResultPromise} from '../subprocess/subprocess.js';3import type {TemplateString} from './template.js';45type ExecaNode<OptionsType extends Options> = {6 <NewOptionsType extends Options = {}>(options: NewOptionsType): ExecaNode<OptionsType & NewOptionsType>;78 (...templateString: TemplateString): ResultPromise<OptionsType>;910 <NewOptionsType extends Options = {}>(11 scriptPath: string | URL,12 arguments?: readonly string[],13 options?: NewOptionsType,14 ): ResultPromise<OptionsType & NewOptionsType>;1516 <NewOptionsType extends Options = {}>(17 scriptPath: string | URL,18 options?: NewOptionsType,19 ): ResultPromise<OptionsType & NewOptionsType>;20};215/**6Same as `execa()` but using the `node: true` option.7Executes a Node.js file using `node scriptPath ...arguments`.8
18 unmodified lines
27// Or:28await execa`node file.js argument`;29```30*/48export declare const execaNode: ExecaNode<{}>;31export declare const execaNode: ExecaNodeMethod<{}>;3233/**34`execaNode()` method either exported by Execa, or bound using `execaNode(options)`.35*/36type ExecaNodeMethod<OptionsType extends Options> =37 & ExecaNodeBind<OptionsType>38 & ExecaNodeTemplate<OptionsType>39 & ExecaNodeArrayLong<OptionsType>40 & ExecaNodeArrayShort<OptionsType>;4142// `execaNode(options)` binding43type ExecaNodeBind<OptionsType extends Options> =44 <NewOptionsType extends Options = {}>(options: NewOptionsType)45 => ExecaNodeMethod<OptionsType & NewOptionsType>;4647// `execaNode`command`` template syntax48type ExecaNodeTemplate<OptionsType extends Options> =49 (...templateString: TemplateString)50 => ResultPromise<OptionsType>;5152// `execaNode('script', ['argument'], {})` array syntax53type ExecaNodeArrayLong<OptionsType extends Options> =54 <NewOptionsType extends Options = {}>(scriptPath: string | URL, arguments?: readonly string[], options?: NewOptionsType)55 => ResultPromise<OptionsType & NewOptionsType>;5657// `execaNode('script', {})` array syntax58type ExecaNodeArrayShort<OptionsType extends Options> =59 <NewOptionsType extends Options = {}>(scriptPath: string | URL, options?: NewOptionsType)60 => ResultPromise<OptionsType & NewOptionsType>;
modified:types/methods/script.d.ts+63 added-40 removed
6 unmodified lines
7import type {SyncResult} from '../return/result.js';8import type {ResultPromise} from '../subprocess/subprocess.js';9import type {TemplateString} from './template.js';1011type ExecaScriptCommon<OptionsType extends CommonOptions> = {12 <NewOptionsType extends CommonOptions = {}>(options: NewOptionsType): ExecaScript<OptionsType & NewOptionsType>;1314 (...templateString: TemplateString): ResultPromise<StricterOptions<OptionsType, Options>>;1516 <NewOptionsType extends Options = {}>(17 file: string | URL,18 arguments?: readonly string[],19 options?: NewOptionsType,20 ): ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;2122 <NewOptionsType extends Options = {}>(23 file: string | URL,24 options?: NewOptionsType,25 ): ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;26};2728type ExecaScriptSync<OptionsType extends CommonOptions> = {29 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaScriptSync<OptionsType & NewOptionsType>;3031 (...templateString: TemplateString): SyncResult<StricterOptions<OptionsType, SyncOptions>>;3233 <NewOptionsType extends SyncOptions = {}>(34 file: string | URL,35 arguments?: readonly string[],36 options?: NewOptionsType,37 ): SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;3839 <NewOptionsType extends SyncOptions = {}>(40 file: string | URL,41 options?: NewOptionsType,42 ): SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;43};4445type ExecaScript<OptionsType extends CommonOptions> = {46 sync: ExecaScriptSync<OptionsType>;47 s: ExecaScriptSync<OptionsType>;48} & ExecaScriptCommon<OptionsType>;4911/**12Same as `execa()` but using script-friendly default options.1314Just like `execa()`, this can use the template string syntax or bind options. It can also be run synchronously using `$.sync()` or `$.s()`.
32 unmodified lines
47[00:57:44.747] [1] ✘ Command failed with exit code 1: npm run test48[00:57:44.747] [1] ✘ (done in 89ms)49```50*/90export const $: ExecaScript<{}>;51export const $: ExecaScriptMethod<{}>;5253/**54`$()` method either exported by Execa, or bound using `$(options)`.55*/56type ExecaScriptMethod<OptionsType extends CommonOptions> =57 & ExecaScriptBind<OptionsType>58 & ExecaScriptTemplate<OptionsType>59 & ExecaScriptArrayLong<OptionsType>60 & ExecaScriptArrayShort<OptionsType>61 & {sync: ExecaScriptSyncMethod<OptionsType>}62 & {s: ExecaScriptSyncMethod<OptionsType>};6364// `$(options)` binding65type ExecaScriptBind<OptionsType extends CommonOptions> =66 <NewOptionsType extends CommonOptions = {}>(options: NewOptionsType)67 => ExecaScriptMethod<OptionsType & NewOptionsType>;6869// `$`command`` template syntax70type ExecaScriptTemplate<OptionsType extends CommonOptions> =71 (...templateString: TemplateString)72 => ResultPromise<StricterOptions<OptionsType, Options>>;7374// `$('file', ['arg'], {})` array syntax75type ExecaScriptArrayLong<OptionsType extends CommonOptions> =76 <NewOptionsType extends Options = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)77 => ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;7879// `$('file', {})` array syntax80type ExecaScriptArrayShort<OptionsType extends CommonOptions> =81 <NewOptionsType extends Options = {}>(file: string | URL, options?: NewOptionsType)82 => ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;8384// We must intersect the overloaded methods with & instead of using a simple object as a workaround for a TypeScript bug85// See https://github.com/microsoft/TypeScript/issues/5876586/**87`$.sync()` method either exported by Execa, or bound using `$.sync(options)`.88*/89type ExecaScriptSyncMethod<OptionsType extends CommonOptions> =90 & ExecaScriptSyncBind<OptionsType>91 & ExecaScriptSyncTemplate<OptionsType>92 & ExecaScriptSyncArrayLong<OptionsType>93 & ExecaScriptSyncArrayShort<OptionsType>;9495// `$.sync(options)` binding96type ExecaScriptSyncBind<OptionsType extends CommonOptions> =97 <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType)98 => ExecaScriptSyncMethod<OptionsType & NewOptionsType>;99100// $.sync`command` template syntax101type ExecaScriptSyncTemplate<OptionsType extends CommonOptions> =102 (...templateString: TemplateString)103 => SyncResult<StricterOptions<OptionsType, SyncOptions>>;104105// `$.sync('file', ['arg'], {})` array syntax106type ExecaScriptSyncArrayLong<OptionsType extends CommonOptions> =107 <NewOptionsType extends SyncOptions = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)108 => SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;109110// `$.sync('file', {})` array syntax111type ExecaScriptSyncArrayShort<OptionsType extends CommonOptions> =112 <NewOptionsType extends SyncOptions = {}>(file: string | URL, options?: NewOptionsType)113 => SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;