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
Provenance
- Commit
faab26e- Tree
4721e39- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
077749d
5 files changed+191 added−115 removed
modified:types/methods/command.d.ts+39 added-21 removed
12345678910111213141516678914 unmodified lines24252627392829414230313233344435363738394647484950404142434445464748495051525310 unmodified lines6465666770686970717273747576777879808182838485868788899091929315 unmodified linesimport type {Options, SyncOptions} from '../arguments/options.js';import type {SyncResult} from '../return/result.js';import type {ResultPromise} from '../subprocess/subprocess.js';import type {SimpleTemplateString} from './template.js';
type ExecaCommand<OptionsType extends Options> = { <NewOptionsType extends Options = {}>(options: NewOptionsType): ExecaCommand<OptionsType & NewOptionsType>;
(...templateString: SimpleTemplateString): ResultPromise<OptionsType>;
<NewOptionsType extends Options = {}>( command: string, options?: NewOptionsType, ): ResultPromise<OptionsType & NewOptionsType>;};
/**Executes a command. `command` is a string that includes both the `file` and its `arguments`.
This is only intended for very specific cases, such as a REPL. This should be avoided otherwise.14 unmodified lines await execaCommand(commandAndArguments);}```*/export declare const execaCommand: ExecaCommand<{}>;export declare const execaCommand: ExecaCommandMethod<{}>;
type ExecaCommandSync<OptionsType extends SyncOptions> = { <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaCommandSync<OptionsType & NewOptionsType>;type ExecaCommandMethod<OptionsType extends Options> = & ExecaCommandBind<OptionsType> & ExecaCommandTemplate<OptionsType> & ExecaCommandArray<OptionsType>;
(...templateString: SimpleTemplateString): SyncResult<OptionsType>;// `execaCommand(options)` bindingtype ExecaCommandBind<OptionsType extends Options> = <NewOptionsType extends Options = {}>(options: NewOptionsType) => ExecaCommandMethod<OptionsType & NewOptionsType>;
<NewOptionsType extends SyncOptions = {}>( command: string, options?: NewOptionsType, ): SyncResult<OptionsType & NewOptionsType>;};// `execaCommand`command`` template syntaxtype ExecaCommandTemplate<OptionsType extends Options> = (...templateString: SimpleTemplateString) => ResultPromise<OptionsType>;
// `execaCommand('command', {})` array syntaxtype ExecaCommandArray<OptionsType extends Options> = <NewOptionsType extends Options = {}>(command: string, options?: NewOptionsType) => ResultPromise<OptionsType & NewOptionsType>;
/**Same as `execaCommand()` but synchronous.
Returns or throws a subprocess `result`. The `subprocess` is not returned: its methods and properties are not available.10 unmodified lines execaCommandSync(commandAndArguments);}```*/export declare const execaCommandSync: ExecaCommandSync<{}>;export declare const execaCommandSync: ExecaCommandSyncMethod<{}>;
type ExecaCommandSyncMethod<OptionsType extends SyncOptions> = & ExecaCommandSyncBind<OptionsType> & ExecaCommandSyncTemplate<OptionsType> & ExecaCommandSyncArray<OptionsType>;
// `execaCommandSync(options)` bindingtype ExecaCommandSyncBind<OptionsType extends SyncOptions> = <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType) => ExecaCommandSyncMethod<OptionsType & NewOptionsType>;
// `execaCommandSync`command`` template syntaxtype ExecaCommandSyncTemplate<OptionsType extends SyncOptions> = (...templateString: SimpleTemplateString) => SyncResult<OptionsType>;
// `execaCommandSync('command', {})` array syntaxtype ExecaCommandSyncArray<OptionsType extends SyncOptions> = <NewOptionsType extends SyncOptions = {}>(command: string, options?: NewOptionsType) => SyncResult<OptionsType & NewOptionsType>;
/**Split a `command` string into an array. For example, `'npm run build'` returns `['npm', 'run', 'build']` and `'argument otherArgument'` returns `['argument', 'otherArgument']`.
@param command - The file to execute and/or its arguments.15 unmodified linesmodified:types/methods/main-async.d.ts+30 added-18 removed
1 import type {Options} from '../arguments/options.js';2 import type {ResultPromise} from '../subprocess/subprocess.js';3 import type {TemplateString} from './template.js';4 5-type Execa<OptionsType extends Options> = {6- <NewOptionsType extends Options = {}>(options: NewOptionsType): Execa<OptionsType & NewOptionsType>;7-8- (...templateString: TemplateString): ResultPromise<OptionsType>;9-10- <NewOptionsType extends Options = {}>(11- file: string | URL,12- arguments?: readonly string[],13- options?: NewOptionsType,14- ): ResultPromise<OptionsType & NewOptionsType>;15-16- <NewOptionsType extends Options = {}>(17- file: string | URL,18- options?: NewOptionsType,19- ): ResultPromise<OptionsType & NewOptionsType>;20-};21-5 /**6 Executes a command using `file ...arguments`.7 8 When `command` is a template string, it includes both the `file` and its `arguments`.309 unmodified lines318 [00:57:44.747] [1] ✘ Command failed with exit code 1: npm run test319 [00:57:44.747] [1] ✘ (done in 89ms)320 ```321 */339-export declare const execa: Execa<{}>;322+export declare const execa: ExecaMethod<{}>;323+324+/**325+`execa()` method either exported by Execa, or bound using `execa(options)`.326+*/327+type ExecaMethod<OptionsType extends Options> =328+ & ExecaBind<OptionsType>329+ & ExecaTemplate<OptionsType>330+ & ExecaArrayLong<OptionsType>331+ & ExecaArrayShort<OptionsType>;332+333+// `execa(options)` binding334+type ExecaBind<OptionsType extends Options> =335+ <NewOptionsType extends Options = {}>(options: NewOptionsType)336+ => ExecaMethod<OptionsType & NewOptionsType>;337+338+// `execa`command`` template syntax339+type ExecaTemplate<OptionsType extends Options> =340+ (...templateString: TemplateString)341+ => ResultPromise<OptionsType>;342+343+// `execa('file', ['argument'], {})` array syntax344+type ExecaArrayLong<OptionsType extends Options> =345+ <NewOptionsType extends Options = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)346+ => ResultPromise<OptionsType & NewOptionsType>;347+348+// `execa('file', {})` array syntax349+type 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
123456789101112131415161718192021567812 unmodified lines21222324422526272829303132333435363738394041424344454647484950515253import type {SyncOptions} from '../arguments/options.js';import type {SyncResult} from '../return/result.js';import type {TemplateString} from './template.js';
type ExecaSync<OptionsType extends SyncOptions> = { <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaSync<OptionsType & NewOptionsType>;
(...templateString: TemplateString): SyncResult<OptionsType>;
<NewOptionsType extends SyncOptions = {}>( file: string | URL, arguments?: readonly string[], options?: NewOptionsType, ): SyncResult<OptionsType & NewOptionsType>;
<NewOptionsType extends SyncOptions = {}>( file: string | URL, options?: NewOptionsType, ): SyncResult<OptionsType & NewOptionsType>;};
/**Same as `execa()` but synchronous.
Returns or throws a subprocess `result`. The `subprocess` is not returned: its methods and properties are not available.12 unmodified lines// Print command's outputconsole.log(stdout);```*/export declare const execaSync: ExecaSync<{}>;export declare const execaSync: ExecaSyncMethod<{}>;
// For the moment, we purposely do not export `ExecaSyncMethod` and `ExecaScriptSyncMethod`.// This is because synchronous invocation is discouraged.type ExecaSyncMethod<OptionsType extends SyncOptions> = & ExecaSyncBind<OptionsType> & ExecaSyncTemplate<OptionsType> & ExecaSyncArrayLong<OptionsType> & ExecaSyncArrayShort<OptionsType>;
// `execaSync(options)` bindingtype ExecaSyncBind<OptionsType extends SyncOptions> = <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType) => ExecaSyncMethod<OptionsType & NewOptionsType>;
// `execaSync`command`` template syntaxtype ExecaSyncTemplate<OptionsType extends SyncOptions> = (...templateString: TemplateString) => SyncResult<OptionsType>;
// `execaSync('file', ['argument'], {})` array syntaxtype ExecaSyncArrayLong<OptionsType extends SyncOptions> = <NewOptionsType extends SyncOptions = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType) => SyncResult<OptionsType & NewOptionsType>;
// `execaSync('file', {})` array syntaxtype ExecaSyncArrayShort<OptionsType extends SyncOptions> = <NewOptionsType extends SyncOptions = {}>(file: string | URL, options?: NewOptionsType) => SyncResult<OptionsType & NewOptionsType>;modified:types/methods/node.d.ts+30 added-18 removed
1 import type {Options} from '../arguments/options.js';2 import type {ResultPromise} from '../subprocess/subprocess.js';3 import type {TemplateString} from './template.js';4 5-type ExecaNode<OptionsType extends Options> = {6- <NewOptionsType extends Options = {}>(options: NewOptionsType): ExecaNode<OptionsType & NewOptionsType>;7-8- (...templateString: TemplateString): ResultPromise<OptionsType>;9-10- <NewOptionsType extends Options = {}>(11- scriptPath: string | URL,12- arguments?: readonly string[],13- options?: NewOptionsType,14- ): ResultPromise<OptionsType & NewOptionsType>;15-16- <NewOptionsType extends Options = {}>(17- scriptPath: string | URL,18- options?: NewOptionsType,19- ): ResultPromise<OptionsType & NewOptionsType>;20-};21-5 /**6 Same as `execa()` but using the `node: true` option.7 Executes a Node.js file using `node scriptPath ...arguments`.8 18 unmodified lines27 // Or:28 await execa`node file.js argument`;29 ```30 */48-export declare const execaNode: ExecaNode<{}>;31+export declare const execaNode: ExecaNodeMethod<{}>;32+33+/**34+`execaNode()` method either exported by Execa, or bound using `execaNode(options)`.35+*/36+type ExecaNodeMethod<OptionsType extends Options> =37+ & ExecaNodeBind<OptionsType>38+ & ExecaNodeTemplate<OptionsType>39+ & ExecaNodeArrayLong<OptionsType>40+ & ExecaNodeArrayShort<OptionsType>;41+42+// `execaNode(options)` binding43+type ExecaNodeBind<OptionsType extends Options> =44+ <NewOptionsType extends Options = {}>(options: NewOptionsType)45+ => ExecaNodeMethod<OptionsType & NewOptionsType>;46+47+// `execaNode`command`` template syntax48+type ExecaNodeTemplate<OptionsType extends Options> =49+ (...templateString: TemplateString)50+ => ResultPromise<OptionsType>;51+52+// `execaNode('script', ['argument'], {})` array syntax53+type ExecaNodeArrayLong<OptionsType extends Options> =54+ <NewOptionsType extends Options = {}>(scriptPath: string | URL, arguments?: readonly string[], options?: NewOptionsType)55+ => ResultPromise<OptionsType & NewOptionsType>;56+57+// `execaNode('script', {})` array syntax58+type 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 lines7 import type {SyncResult} from '../return/result.js';8 import type {ResultPromise} from '../subprocess/subprocess.js';9 import type {TemplateString} from './template.js';10 11-type ExecaScriptCommon<OptionsType extends CommonOptions> = {12- <NewOptionsType extends CommonOptions = {}>(options: NewOptionsType): ExecaScript<OptionsType & NewOptionsType>;13-14- (...templateString: TemplateString): ResultPromise<StricterOptions<OptionsType, Options>>;15-16- <NewOptionsType extends Options = {}>(17- file: string | URL,18- arguments?: readonly string[],19- options?: NewOptionsType,20- ): ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;21-22- <NewOptionsType extends Options = {}>(23- file: string | URL,24- options?: NewOptionsType,25- ): ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;26-};27-28-type ExecaScriptSync<OptionsType extends CommonOptions> = {29- <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType): ExecaScriptSync<OptionsType & NewOptionsType>;30-31- (...templateString: TemplateString): SyncResult<StricterOptions<OptionsType, SyncOptions>>;32-33- <NewOptionsType extends SyncOptions = {}>(34- file: string | URL,35- arguments?: readonly string[],36- options?: NewOptionsType,37- ): SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;38-39- <NewOptionsType extends SyncOptions = {}>(40- file: string | URL,41- options?: NewOptionsType,42- ): SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;43-};44-45-type ExecaScript<OptionsType extends CommonOptions> = {46- sync: ExecaScriptSync<OptionsType>;47- s: ExecaScriptSync<OptionsType>;48-} & ExecaScriptCommon<OptionsType>;49-11 /**12 Same as `execa()` but using script-friendly default options.13 14 Just like `execa()`, this can use the template string syntax or bind options. It can also be run synchronously using `$.sync()` or `$.s()`.32 unmodified lines47 [00:57:44.747] [1] ✘ Command failed with exit code 1: npm run test48 [00:57:44.747] [1] ✘ (done in 89ms)49 ```50 */90-export const $: ExecaScript<{}>;51+export const $: ExecaScriptMethod<{}>;52+53+/**54+`$()` method either exported by Execa, or bound using `$(options)`.55+*/56+type ExecaScriptMethod<OptionsType extends CommonOptions> =57+ & ExecaScriptBind<OptionsType>58+ & ExecaScriptTemplate<OptionsType>59+ & ExecaScriptArrayLong<OptionsType>60+ & ExecaScriptArrayShort<OptionsType>61+ & {sync: ExecaScriptSyncMethod<OptionsType>}62+ & {s: ExecaScriptSyncMethod<OptionsType>};63+64+// `$(options)` binding65+type ExecaScriptBind<OptionsType extends CommonOptions> =66+ <NewOptionsType extends CommonOptions = {}>(options: NewOptionsType)67+ => ExecaScriptMethod<OptionsType & NewOptionsType>;68+69+// `$`command`` template syntax70+type ExecaScriptTemplate<OptionsType extends CommonOptions> =71+ (...templateString: TemplateString)72+ => ResultPromise<StricterOptions<OptionsType, Options>>;73+74+// `$('file', ['arg'], {})` array syntax75+type ExecaScriptArrayLong<OptionsType extends CommonOptions> =76+ <NewOptionsType extends Options = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)77+ => ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;78+79+// `$('file', {})` array syntax80+type ExecaScriptArrayShort<OptionsType extends CommonOptions> =81+ <NewOptionsType extends Options = {}>(file: string | URL, options?: NewOptionsType)82+ => ResultPromise<StricterOptions<OptionsType & NewOptionsType, Options>>;83+84+// 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+*/89+type ExecaScriptSyncMethod<OptionsType extends CommonOptions> =90+ & ExecaScriptSyncBind<OptionsType>91+ & ExecaScriptSyncTemplate<OptionsType>92+ & ExecaScriptSyncArrayLong<OptionsType>93+ & ExecaScriptSyncArrayShort<OptionsType>;94+95+// `$.sync(options)` binding96+type ExecaScriptSyncBind<OptionsType extends CommonOptions> =97+ <NewOptionsType extends SyncOptions = {}>(options: NewOptionsType)98+ => ExecaScriptSyncMethod<OptionsType & NewOptionsType>;99+100+// $.sync`command` template syntax101+type ExecaScriptSyncTemplate<OptionsType extends CommonOptions> =102+ (...templateString: TemplateString)103+ => SyncResult<StricterOptions<OptionsType, SyncOptions>>;104+105+// `$.sync('file', ['arg'], {})` array syntax106+type ExecaScriptSyncArrayLong<OptionsType extends CommonOptions> =107+ <NewOptionsType extends SyncOptions = {}>(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)108+ => SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;109+110+// `$.sync('file', {})` array syntax111+type ExecaScriptSyncArrayShort<OptionsType extends CommonOptions> =112+ <NewOptionsType extends SyncOptions = {}>(file: string | URL, options?: NewOptionsType)113+ => SyncResult<StricterOptions<OptionsType & NewOptionsType, SyncOptions>>;