diff --git a/types/methods/command.d.ts b/types/methods/command.d.ts index b1927fef80..55dd132cd6 100644 --- a/types/methods/command.d.ts +++ b/types/methods/command.d.ts @@ -3,17 +3,6 @@ import type {SyncResult} from '../return/result.js'; import type {ResultPromise} from '../subprocess/subprocess.js'; import type {SimpleTemplateString} from './template.js'; -type ExecaCommand = { - (options: NewOptionsType): ExecaCommand; - - (...templateString: SimpleTemplateString): ResultPromise; - - ( - command: string, - options?: NewOptionsType, - ): ResultPromise; -}; - /** Executes a command. `command` is a string that includes both the `file` and its `arguments`. @@ -36,18 +25,27 @@ for await (const commandAndArguments of getReplLine()) { } ``` */ -export declare const execaCommand: ExecaCommand<{}>; +export declare const execaCommand: ExecaCommandMethod<{}>; + +type ExecaCommandMethod = + & ExecaCommandBind + & ExecaCommandTemplate + & ExecaCommandArray; -type ExecaCommandSync = { - (options: NewOptionsType): ExecaCommandSync; +// `execaCommand(options)` binding +type ExecaCommandBind = + (options: NewOptionsType) + => ExecaCommandMethod; - (...templateString: SimpleTemplateString): SyncResult; +// `execaCommand`command`` template syntax +type ExecaCommandTemplate = + (...templateString: SimpleTemplateString) + => ResultPromise; - ( - command: string, - options?: NewOptionsType, - ): SyncResult; -}; +// `execaCommand('command', {})` array syntax +type ExecaCommandArray = + (command: string, options?: NewOptionsType) + => ResultPromise; /** Same as `execaCommand()` but synchronous. @@ -67,7 +65,27 @@ for (const commandAndArguments of getReplLine()) { } ``` */ -export declare const execaCommandSync: ExecaCommandSync<{}>; +export declare const execaCommandSync: ExecaCommandSyncMethod<{}>; + +type ExecaCommandSyncMethod = + & ExecaCommandSyncBind + & ExecaCommandSyncTemplate + & ExecaCommandSyncArray; + +// `execaCommandSync(options)` binding +type ExecaCommandSyncBind = + (options: NewOptionsType) + => ExecaCommandSyncMethod; + +// `execaCommandSync`command`` template syntax +type ExecaCommandSyncTemplate = + (...templateString: SimpleTemplateString) + => SyncResult; + +// `execaCommandSync('command', {})` array syntax +type ExecaCommandSyncArray = + (command: string, options?: NewOptionsType) + => SyncResult; /** Split a `command` string into an array. For example, `'npm run build'` returns `['npm', 'run', 'build']` and `'argument otherArgument'` returns `['argument', 'otherArgument']`. diff --git a/types/methods/main-async.d.ts b/types/methods/main-async.d.ts index 5375cb8722..148e848d35 100644 --- a/types/methods/main-async.d.ts +++ b/types/methods/main-async.d.ts @@ -2,23 +2,6 @@ import type {Options} from '../arguments/options.js'; import type {ResultPromise} from '../subprocess/subprocess.js'; import type {TemplateString} from './template.js'; -type Execa = { - (options: NewOptionsType): Execa; - - (...templateString: TemplateString): ResultPromise; - - ( - file: string | URL, - arguments?: readonly string[], - options?: NewOptionsType, - ): ResultPromise; - - ( - file: string | URL, - options?: NewOptionsType, - ): ResultPromise; -}; - /** Executes a command using `file ...arguments`. @@ -336,4 +319,33 @@ $ NODE_DEBUG=execa node build.js [00:57:44.747] [1] ✘ (done in 89ms) ``` */ -export declare const execa: Execa<{}>; +export declare const execa: ExecaMethod<{}>; + +/** +`execa()` method either exported by Execa, or bound using `execa(options)`. +*/ +type ExecaMethod = + & ExecaBind + & ExecaTemplate + & ExecaArrayLong + & ExecaArrayShort; + +// `execa(options)` binding +type ExecaBind = + (options: NewOptionsType) + => ExecaMethod; + +// `execa`command`` template syntax +type ExecaTemplate = + (...templateString: TemplateString) + => ResultPromise; + +// `execa('file', ['argument'], {})` array syntax +type ExecaArrayLong = + (file: string | URL, arguments?: readonly string[], options?: NewOptionsType) + => ResultPromise; + +// `execa('file', {})` array syntax +type ExecaArrayShort = + (file: string | URL, options?: NewOptionsType) + => ResultPromise; diff --git a/types/methods/main-sync.d.ts b/types/methods/main-sync.d.ts index 1e29656b5c..b40d0c8f29 100644 --- a/types/methods/main-sync.d.ts +++ b/types/methods/main-sync.d.ts @@ -2,23 +2,6 @@ import type {SyncOptions} from '../arguments/options.js'; import type {SyncResult} from '../return/result.js'; import type {TemplateString} from './template.js'; -type ExecaSync = { - (options: NewOptionsType): ExecaSync; - - (...templateString: TemplateString): SyncResult; - - ( - file: string | URL, - arguments?: readonly string[], - options?: NewOptionsType, - ): SyncResult; - - ( - file: string | URL, - options?: NewOptionsType, - ): SyncResult; -}; - /** Same as `execa()` but synchronous. @@ -39,4 +22,32 @@ const {stdout} = execaSync`npm run build`; console.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 = + & ExecaSyncBind + & ExecaSyncTemplate + & ExecaSyncArrayLong + & ExecaSyncArrayShort; + +// `execaSync(options)` binding +type ExecaSyncBind = + (options: NewOptionsType) + => ExecaSyncMethod; + +// `execaSync`command`` template syntax +type ExecaSyncTemplate = + (...templateString: TemplateString) + => SyncResult; + +// `execaSync('file', ['argument'], {})` array syntax +type ExecaSyncArrayLong = + (file: string | URL, arguments?: readonly string[], options?: NewOptionsType) + => SyncResult; + +// `execaSync('file', {})` array syntax +type ExecaSyncArrayShort = + (file: string | URL, options?: NewOptionsType) + => SyncResult; diff --git a/types/methods/node.d.ts b/types/methods/node.d.ts index 6e3b0b2083..b92f654995 100644 --- a/types/methods/node.d.ts +++ b/types/methods/node.d.ts @@ -2,23 +2,6 @@ import type {Options} from '../arguments/options.js'; import type {ResultPromise} from '../subprocess/subprocess.js'; import type {TemplateString} from './template.js'; -type ExecaNode = { - (options: NewOptionsType): ExecaNode; - - (...templateString: TemplateString): ResultPromise; - - ( - scriptPath: string | URL, - arguments?: readonly string[], - options?: NewOptionsType, - ): ResultPromise; - - ( - scriptPath: string | URL, - options?: NewOptionsType, - ): ResultPromise; -}; - /** Same as `execa()` but using the `node: true` option. Executes a Node.js file using `node scriptPath ...arguments`. @@ -45,4 +28,33 @@ await execa({node: true})`file.js argument`; await execa`node file.js argument`; ``` */ -export declare const execaNode: ExecaNode<{}>; +export declare const execaNode: ExecaNodeMethod<{}>; + +/** +`execaNode()` method either exported by Execa, or bound using `execaNode(options)`. +*/ +type ExecaNodeMethod = + & ExecaNodeBind + & ExecaNodeTemplate + & ExecaNodeArrayLong + & ExecaNodeArrayShort; + +// `execaNode(options)` binding +type ExecaNodeBind = + (options: NewOptionsType) + => ExecaNodeMethod; + +// `execaNode`command`` template syntax +type ExecaNodeTemplate = + (...templateString: TemplateString) + => ResultPromise; + +// `execaNode('script', ['argument'], {})` array syntax +type ExecaNodeArrayLong = + (scriptPath: string | URL, arguments?: readonly string[], options?: NewOptionsType) + => ResultPromise; + +// `execaNode('script', {})` array syntax +type ExecaNodeArrayShort = + (scriptPath: string | URL, options?: NewOptionsType) + => ResultPromise; diff --git a/types/methods/script.d.ts b/types/methods/script.d.ts index f3932df7e3..c9ba4f1c89 100644 --- a/types/methods/script.d.ts +++ b/types/methods/script.d.ts @@ -8,45 +8,6 @@ import type {SyncResult} from '../return/result.js'; import type {ResultPromise} from '../subprocess/subprocess.js'; import type {TemplateString} from './template.js'; -type ExecaScriptCommon = { - (options: NewOptionsType): ExecaScript; - - (...templateString: TemplateString): ResultPromise>; - - ( - file: string | URL, - arguments?: readonly string[], - options?: NewOptionsType, - ): ResultPromise>; - - ( - file: string | URL, - options?: NewOptionsType, - ): ResultPromise>; -}; - -type ExecaScriptSync = { - (options: NewOptionsType): ExecaScriptSync; - - (...templateString: TemplateString): SyncResult>; - - ( - file: string | URL, - arguments?: readonly string[], - options?: NewOptionsType, - ): SyncResult>; - - ( - file: string | URL, - options?: NewOptionsType, - ): SyncResult>; -}; - -type ExecaScript = { - sync: ExecaScriptSync; - s: ExecaScriptSync; -} & ExecaScriptCommon; - /** Same as `execa()` but using script-friendly default options. @@ -87,4 +48,66 @@ $ NODE_DEBUG=execa node build.js [00:57:44.747] [1] ✘ (done in 89ms) ``` */ -export const $: ExecaScript<{}>; +export const $: ExecaScriptMethod<{}>; + +/** +`$()` method either exported by Execa, or bound using `$(options)`. +*/ +type ExecaScriptMethod = + & ExecaScriptBind + & ExecaScriptTemplate + & ExecaScriptArrayLong + & ExecaScriptArrayShort + & {sync: ExecaScriptSyncMethod} + & {s: ExecaScriptSyncMethod}; + +// `$(options)` binding +type ExecaScriptBind = + (options: NewOptionsType) + => ExecaScriptMethod; + +// `$`command`` template syntax +type ExecaScriptTemplate = + (...templateString: TemplateString) + => ResultPromise>; + +// `$('file', ['arg'], {})` array syntax +type ExecaScriptArrayLong = + (file: string | URL, arguments?: readonly string[], options?: NewOptionsType) + => ResultPromise>; + +// `$('file', {})` array syntax +type ExecaScriptArrayShort = + (file: string | URL, options?: NewOptionsType) + => ResultPromise>; + +// We must intersect the overloaded methods with & instead of using a simple object as a workaround for a TypeScript bug +// See https://github.com/microsoft/TypeScript/issues/58765 +/** +`$.sync()` method either exported by Execa, or bound using `$.sync(options)`. +*/ +type ExecaScriptSyncMethod = + & ExecaScriptSyncBind + & ExecaScriptSyncTemplate + & ExecaScriptSyncArrayLong + & ExecaScriptSyncArrayShort; + +// `$.sync(options)` binding +type ExecaScriptSyncBind = + (options: NewOptionsType) + => ExecaScriptSyncMethod; + +// $.sync`command` template syntax +type ExecaScriptSyncTemplate = + (...templateString: TemplateString) + => SyncResult>; + +// `$.sync('file', ['arg'], {})` array syntax +type ExecaScriptSyncArrayLong = + (file: string | URL, arguments?: readonly string[], options?: NewOptionsType) + => SyncResult>; + +// `$.sync('file', {})` array syntax +type ExecaScriptSyncArrayShort = + (file: string | URL, options?: NewOptionsType) + => SyncResult>;