import type {
CommonOptions,
Options,
SyncOptions,
StricterOptions,
} from '../arguments/options.js';
import type {SyncResult} from '../return/result.js';
import type {ResultPromise} from '../subprocess/subprocess.js';
import type {SubprocessStdioStream} from '../subprocess/stdout.js';
import type {SubprocessStdioArray} from '../subprocess/stdio.js';
import type {WithInputSources} from '../stdio/option.js';
import type {TemplateString} from './template.js';
import type {MergeOptions} from './bind.js';
/**
Same as `execa()` but using script-friendly default options.
When `command` is a template string, it includes both the `file` and its `arguments`.
`$(options)` can be used to return a new instance of this method but with different default `options`. Consecutive calls are merged to previous ones.
This is the preferred method when executing multiple commands in a script file.
@returns A `ResultPromise` that is both:
- the subprocess.
- a `Promise` either resolving with its successful `result`, or rejecting with its `error`.
@throws `ExecaError`
@example
Basic
```
import {$} from 'execa';
const branch = await $`git branch --show-current`;
await $`dep deploy --branch=${branch}`;
```
@example Verbose mode
```
$ node build.js
Building application...
Done building.
Running tests...
Error: the entrypoint is invalid.
$ NODE_DEBUG=execa node build.js
[00:57:44.581] [0] $ npm run build
[00:57:44.653] [0] Building application...
[00:57:44.653] [0] Done building.
[00:57:44.658] [0] ✔ (done in 78ms)
[00:57:44.658] [1] $ npm run test
[00:57:44.740] [1] Running tests...
[00:57:44.740] [1] Error: the entrypoint is invalid.
[00:57:44.747] [1] ✘ Command failed with exit code 1: npm run test
[00:57:44.747] [1] ✘ (done in 89ms)
```
*/
export const $: ExecaScriptMethod<{}>;
/**
`$()` method either exported by Execa, or bound using `$(options)`.
*/
export type ExecaScriptMethod =
& ExecaScriptBind
& ExecaScriptTemplate
& ExecaScriptArrayLong
& ExecaScriptArrayShort
& {sync: ExecaScriptSyncMethod}
& {s: ExecaScriptSyncMethod};
// `$(options)` binding
type ExecaScriptBind =
(options: NewOptionsType)
=> ExecaScriptMethod>;
// `$`command`` template syntax
type ExecaScriptTemplate =
(...templateString: TemplateString)
=> ScriptResultPromise>;
// `$('file', ['arg'], {})` array syntax
type ExecaScriptArrayLong =
(file: string | URL, arguments?: readonly string[], options?: NewOptionsType)
=> ScriptSubprocess>;
// `$('file', {})` array syntax
type ExecaScriptArrayShort =
(file: string | URL, options?: NewOptionsType)
=> ScriptSubprocess>;
// Inferring the options from the return value's expected type, e.g. `const subprocess: ResultPromise = $('file')`, is too complex for TypeScript, so the return value is excluded from that inference.
// This is like the built-in `NoInfer`, which is not available with the minimum supported TypeScript version.
type ScriptSubprocess = [ScriptResultPromise>][OptionsType extends unknown ? 0 : never];
type ScriptResultPromise<
OptionsType extends Options,
SubprocessType = ResultPromise,
> = SubprocessType extends unknown
? Omit & {stdin: SubprocessStdioStream<'0', StricterOptions, Options>>; stdio: SubprocessStdioArray, Options>>}
: never;
// `$` defaults to inherited stdin unless input, inputFile or stdio is provided.
type ScriptOptions = OptionsType extends Options
? Omit & {stdin: ScriptStdin}
: never;
type ScriptStdin<
OptionsType extends Options,
StdinOption,
> = StdinOption extends undefined ? ScriptDefaultStdin : StdinOption;
// With an input source, the `stdin` option is left `undefined`, so its usual default applies.
type ScriptDefaultStdin = WithInputSources;
// 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)`.
*/
export 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, SyncOptions>>;
// `$.sync('file', {})` array syntax
type ExecaScriptSyncArrayShort =
(file: string | URL, options?: NewOptionsType)
=> SyncResult, SyncOptions>>;
export {};