time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

index.d.ts (28188B)


      1 import {type Buffer} from 'node:buffer';
      2 import {type ChildProcess} from 'node:child_process';
      3 import {type Stream, type Readable as ReadableStream, type Writable as WritableStream} from 'node:stream';
      4 
      5 export type StdioOption =
      6 	| 'pipe'
      7 	| 'overlapped'
      8 	| 'ipc'
      9 	| 'ignore'
     10 	| 'inherit'
     11 	| Stream
     12 	| number
     13 	| undefined;
     14 
     15 export type CommonOptions<EncodingType> = {
     16 	/**
     17 	Kill the spawned process when the parent process exits unless either:
     18 		- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached)
     19 		- the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit
     20 
     21 	@default true
     22 	*/
     23 	readonly cleanup?: boolean;
     24 
     25 	/**
     26 	Prefer locally installed binaries when looking for a binary to execute.
     27 
     28 	If you `$ npm install foo`, you can then `execa('foo')`.
     29 
     30 	@default `true` with `$`, `false` otherwise
     31 	*/
     32 	readonly preferLocal?: boolean;
     33 
     34 	/**
     35 	Preferred path to find locally installed binaries in (use with `preferLocal`).
     36 
     37 	@default process.cwd()
     38 	*/
     39 	readonly localDir?: string | URL;
     40 
     41 	/**
     42 	Path to the Node.js executable to use in child processes.
     43 
     44 	This can be either an absolute path or a path relative to the `cwd` option.
     45 
     46 	Requires `preferLocal` to be `true`.
     47 
     48 	For example, this can be used together with [`get-node`](https://github.com/ehmicky/get-node) to run a specific Node.js version in a child process.
     49 
     50 	@default process.execPath
     51 	*/
     52 	readonly execPath?: string;
     53 
     54 	/**
     55 	Buffer the output from the spawned process. When set to `false`, you must read the output of `stdout` and `stderr` (or `all` if the `all` option is `true`). Otherwise the returned promise will not be resolved/rejected.
     56 
     57 	If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data.
     58 
     59 	@default true
     60 	*/
     61 	readonly buffer?: boolean;
     62 
     63 	/**
     64 	Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
     65 
     66 	@default `inherit` with `$`, `pipe` otherwise
     67 	*/
     68 	readonly stdin?: StdioOption;
     69 
     70 	/**
     71 	Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
     72 
     73 	@default 'pipe'
     74 	*/
     75 	readonly stdout?: StdioOption;
     76 
     77 	/**
     78 	Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio).
     79 
     80 	@default 'pipe'
     81 	*/
     82 	readonly stderr?: StdioOption;
     83 
     84 	/**
     85 	Setting this to `false` resolves the promise with the error instead of rejecting it.
     86 
     87 	@default true
     88 	*/
     89 	readonly reject?: boolean;
     90 
     91 	/**
     92 	Add an `.all` property on the promise and the resolved value. The property contains the output of the process with `stdout` and `stderr` interleaved.
     93 
     94 	@default false
     95 	*/
     96 	readonly all?: boolean;
     97 
     98 	/**
     99 	Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output.
    100 
    101 	@default true
    102 	*/
    103 	readonly stripFinalNewline?: boolean;
    104 
    105 	/**
    106 	Set to `false` if you don't want to extend the environment variables when providing the `env` property.
    107 
    108 	@default true
    109 	*/
    110 	readonly extendEnv?: boolean;
    111 
    112 	/**
    113 	Current working directory of the child process.
    114 
    115 	@default process.cwd()
    116 	*/
    117 	readonly cwd?: string | URL;
    118 
    119 	/**
    120 	Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this.
    121 
    122 	@default process.env
    123 	*/
    124 	readonly env?: NodeJS.ProcessEnv;
    125 
    126 	/**
    127 	Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified.
    128 	*/
    129 	readonly argv0?: string;
    130 
    131 	/**
    132 	Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration.
    133 
    134 	@default 'pipe'
    135 	*/
    136 	readonly stdio?: 'pipe' | 'overlapped' | 'ignore' | 'inherit' | readonly StdioOption[];
    137 
    138 	/**
    139 	Specify the kind of serialization used for sending messages between processes when using the `stdio: 'ipc'` option or `execaNode()`:
    140 		- `json`: Uses `JSON.stringify()` and `JSON.parse()`.
    141 		- `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value)
    142 
    143 	[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization)
    144 
    145 	@default 'json'
    146 	*/
    147 	readonly serialization?: 'json' | 'advanced';
    148 
    149 	/**
    150 	Prepare child to run independently of its parent process. Specific behavior [depends on the platform](https://nodejs.org/api/child_process.html#child_process_options_detached).
    151 
    152 	@default false
    153 	*/
    154 	readonly detached?: boolean;
    155 
    156 	/**
    157 	Sets the user identity of the process.
    158 	*/
    159 	readonly uid?: number;
    160 
    161 	/**
    162 	Sets the group identity of the process.
    163 	*/
    164 	readonly gid?: number;
    165 
    166 	/**
    167 	If `true`, runs `command` inside of a shell. Uses `/bin/sh` on UNIX and `cmd.exe` on Windows. A different shell can be specified as a string. The shell should understand the `-c` switch on UNIX or `/d /s /c` on Windows.
    168 
    169 	We recommend against using this option since it is:
    170 	- not cross-platform, encouraging shell-specific syntax.
    171 	- slower, because of the additional shell interpretation.
    172 	- unsafe, potentially allowing command injection.
    173 
    174 	@default false
    175 	*/
    176 	readonly shell?: boolean | string;
    177 
    178 	/**
    179 	Specify the character encoding used to decode the `stdout` and `stderr` output. If set to `null`, then `stdout` and `stderr` will be a `Buffer` instead of a string.
    180 
    181 	@default 'utf8'
    182 	*/
    183 	readonly encoding?: EncodingType;
    184 
    185 	/**
    186 	If `timeout` is greater than `0`, the parent will send the signal identified by the `killSignal` property (the default is `SIGTERM`) if the child runs longer than `timeout` milliseconds.
    187 
    188 	@default 0
    189 	*/
    190 	readonly timeout?: number;
    191 
    192 	/**
    193 	Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 100 MB.
    194 
    195 	@default 100_000_000
    196 	*/
    197 	readonly maxBuffer?: number;
    198 
    199 	/**
    200 	Signal value to be used when the spawned process will be killed.
    201 
    202 	@default 'SIGTERM'
    203 	*/
    204 	readonly killSignal?: string | number;
    205 
    206 	/**
    207 	You can abort the spawned process using [`AbortController`](https://developer.mozilla.org/en-US/docs/Web/API/AbortController).
    208 
    209 	When `AbortController.abort()` is called, [`.isCanceled`](https://github.com/sindresorhus/execa#iscanceled) becomes `false`.
    210 
    211 	*Requires Node.js 16 or later.*
    212 
    213 	@example
    214 	```
    215 	import {execa} from 'execa';
    216 
    217 	const abortController = new AbortController();
    218 	const subprocess = execa('node', [], {signal: abortController.signal});
    219 
    220 	setTimeout(() => {
    221 		abortController.abort();
    222 	}, 1000);
    223 
    224 	try {
    225 		await subprocess;
    226 	} catch (error) {
    227 		console.log(subprocess.killed); // true
    228 		console.log(error.isCanceled); // true
    229 	}
    230 	```
    231 	*/
    232 	readonly signal?: AbortSignal;
    233 
    234 	/**
    235 	If `true`, no quoting or escaping of arguments is done on Windows. Ignored on other platforms. This is set to `true` automatically when the `shell` option is `true`.
    236 
    237 	@default false
    238 	*/
    239 	readonly windowsVerbatimArguments?: boolean;
    240 
    241 	/**
    242 	On Windows, do not create a new console window. Please note this also prevents `CTRL-C` [from working](https://github.com/nodejs/node/issues/29837) on Windows.
    243 
    244 	@default true
    245 	*/
    246 	readonly windowsHide?: boolean;
    247 
    248 	/**
    249 	Print each command on `stderr` before executing it.
    250 
    251 	This can also be enabled by setting the `NODE_DEBUG=execa` environment variable in the current process.
    252 
    253 	@default false
    254 	*/
    255 	readonly verbose?: boolean;
    256 };
    257 
    258 export type Options<EncodingType = string> = {
    259 	/**
    260 	Write some input to the `stdin` of your binary.
    261 
    262 	If the input is a file, use the `inputFile` option instead.
    263 	*/
    264 	readonly input?: string | Buffer | ReadableStream;
    265 
    266 	/**
    267 	Use a file as input to the the `stdin` of your binary.
    268 
    269 	If the input is not a file, use the `input` option instead.
    270 	*/
    271 	readonly inputFile?: string;
    272 } & CommonOptions<EncodingType>;
    273 
    274 export type SyncOptions<EncodingType = string> = {
    275 	/**
    276 	Write some input to the `stdin` of your binary.
    277 
    278 	If the input is a file, use the `inputFile` option instead.
    279 	*/
    280 	readonly input?: string | Buffer;
    281 
    282 	/**
    283 	Use a file as input to the the `stdin` of your binary.
    284 
    285 	If the input is not a file, use the `input` option instead.
    286 	*/
    287 	readonly inputFile?: string;
    288 } & CommonOptions<EncodingType>;
    289 
    290 export type NodeOptions<EncodingType = string> = {
    291 	/**
    292 	The Node.js executable to use.
    293 
    294 	@default process.execPath
    295 	*/
    296 	readonly nodePath?: string;
    297 
    298 	/**
    299 	List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable.
    300 
    301 	@default process.execArgv
    302 	*/
    303 	readonly nodeOptions?: string[];
    304 } & Options<EncodingType>;
    305 
    306 type StdoutStderrAll = string | Buffer | undefined;
    307 
    308 export type ExecaReturnBase<StdoutStderrType extends StdoutStderrAll> = {
    309 	/**
    310 	The file and arguments that were run, for logging purposes.
    311 
    312 	This is not escaped and should not be executed directly as a process, including using `execa()` or `execaCommand()`.
    313 	*/
    314 	command: string;
    315 
    316 	/**
    317 	Same as `command` but escaped.
    318 
    319 	This is meant to be copy and pasted into a shell, for debugging purposes.
    320 	Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`.
    321 	*/
    322 	escapedCommand: string;
    323 
    324 	/**
    325 	The numeric exit code of the process that was run.
    326 	*/
    327 	exitCode: number;
    328 
    329 	/**
    330 	The output of the process on stdout.
    331 	*/
    332 	stdout: StdoutStderrType;
    333 
    334 	/**
    335 	The output of the process on stderr.
    336 	*/
    337 	stderr: StdoutStderrType;
    338 
    339 	/**
    340 	Whether the process failed to run.
    341 	*/
    342 	failed: boolean;
    343 
    344 	/**
    345 	Whether the process timed out.
    346 	*/
    347 	timedOut: boolean;
    348 
    349 	/**
    350 	Whether the process was killed.
    351 	*/
    352 	killed: boolean;
    353 
    354 	/**
    355 	The name of the signal that was used to terminate the process. For example, `SIGFPE`.
    356 
    357 	If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`.
    358 	*/
    359 	signal?: string;
    360 
    361 	/**
    362 	A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`.
    363 
    364 	If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. It is also `undefined` when the signal is very uncommon which should seldomly happen.
    365 	*/
    366 	signalDescription?: string;
    367 
    368 	/**
    369 	The `cwd` of the command if provided in the command options. Otherwise it is `process.cwd()`.
    370 	*/
    371 	cwd: string;
    372 };
    373 
    374 export type ExecaSyncReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
    375 } & ExecaReturnBase<StdoutStderrType>;
    376 
    377 /**
    378 Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.
    379 
    380 The child process fails when:
    381 - its exit code is not `0`
    382 - it was killed with a signal
    383 - timing out
    384 - being canceled
    385 - there's not enough memory or there are already too many child processes
    386 */
    387 export type ExecaReturnValue<StdoutStderrType extends StdoutStderrAll = string> = {
    388 	/**
    389 	The output of the process with `stdout` and `stderr` interleaved.
    390 
    391 	This is `undefined` if either:
    392 	- the `all` option is `false` (default value)
    393 	- `execaSync()` was used
    394 	*/
    395 	all?: StdoutStderrType;
    396 
    397 	/**
    398 	Whether the process was canceled.
    399 
    400 	You can cancel the spawned process using the [`signal`](https://github.com/sindresorhus/execa#signal-1) option.
    401 	*/
    402 	isCanceled: boolean;
    403 } & ExecaSyncReturnValue<StdoutStderrType>;
    404 
    405 export type ExecaSyncError<StdoutStderrType extends StdoutStderrAll = string> = {
    406 	/**
    407 	Error message when the child process failed to run. In addition to the underlying error message, it also contains some information related to why the child process errored.
    408 
    409 	The child process stderr then stdout are appended to the end, separated with newlines and not interleaved.
    410 	*/
    411 	message: string;
    412 
    413 	/**
    414 	This is the same as the `message` property except it does not include the child process stdout/stderr.
    415 	*/
    416 	shortMessage: string;
    417 
    418 	/**
    419 	Original error message. This is the same as the `message` property except it includes neither the child process stdout/stderr nor some additional information added by Execa.
    420 
    421 	This is `undefined` unless the child process exited due to an `error` event or a timeout.
    422 	*/
    423 	originalMessage?: string;
    424 } & Error & ExecaReturnBase<StdoutStderrType>;
    425 
    426 export type ExecaError<StdoutStderrType extends StdoutStderrAll = string> = {
    427 	/**
    428 	The output of the process with `stdout` and `stderr` interleaved.
    429 
    430 	This is `undefined` if either:
    431 	- the `all` option is `false` (default value)
    432 	- `execaSync()` was used
    433 	*/
    434 	all?: StdoutStderrType;
    435 
    436 	/**
    437 	Whether the process was canceled.
    438 	*/
    439 	isCanceled: boolean;
    440 } & ExecaSyncError<StdoutStderrType>;
    441 
    442 export type KillOptions = {
    443 	/**
    444 	Milliseconds to wait for the child process to terminate before sending `SIGKILL`.
    445 
    446 	Can be disabled with `false`.
    447 
    448 	@default 5000
    449 	*/
    450 	forceKillAfterTimeout?: number | false;
    451 };
    452 
    453 export type ExecaChildPromise<StdoutStderrType extends StdoutStderrAll> = {
    454 	/**
    455 	Stream combining/interleaving [`stdout`](https://nodejs.org/api/child_process.html#child_process_subprocess_stdout) and [`stderr`](https://nodejs.org/api/child_process.html#child_process_subprocess_stderr).
    456 
    457 	This is `undefined` if either:
    458 		- the `all` option is `false` (the default value)
    459 		- both `stdout` and `stderr` options are set to [`'inherit'`, `'ipc'`, `Stream` or `integer`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio)
    460 	*/
    461 	all?: ReadableStream;
    462 
    463 	catch<ResultType = never>(
    464 		onRejected?: (reason: ExecaError<StdoutStderrType>) => ResultType | PromiseLike<ResultType>
    465 	): Promise<ExecaReturnValue<StdoutStderrType> | ResultType>;
    466 
    467 	/**
    468 	Same as the original [`child_process#kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal), except if `signal` is `SIGTERM` (the default value) and the child process is not terminated after 5 seconds, force it by sending `SIGKILL`. Note that this graceful termination does not work on Windows, because Windows [doesn't support signals](https://nodejs.org/api/process.html#process_signal_events) (`SIGKILL` and `SIGTERM` has the same effect of force-killing the process immediately.) If you want to achieve graceful termination on Windows, you have to use other means, such as [`taskkill`](https://github.com/sindresorhus/taskkill).
    469 	*/
    470 	kill(signal?: string, options?: KillOptions): void;
    471 
    472 	/**
    473 	Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This used to be preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. But now this is deprecated and you should either use `.kill()` or the `signal` option when creating the child process.
    474 	*/
    475 	cancel(): void;
    476 
    477 	/**
    478 	[Pipe](https://nodejs.org/api/stream.html#readablepipedestination-options) the child process's `stdout` to `target`, which can be:
    479 	- Another `execa()` return value
    480 	- A writable stream
    481 	- A file path string
    482 
    483 	If the `target` is another `execa()` return value, it is returned. Otherwise, the original `execa()` return value is returned. This allows chaining `pipeStdout()` then `await`ing the final result.
    484 
    485 	The `stdout` option] must be kept as `pipe`, its default value.
    486 	*/
    487 	pipeStdout?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
    488 	pipeStdout?(target: WritableStream | string): ExecaChildProcess<StdoutStderrType>;
    489 
    490 	/**
    491 	Like `pipeStdout()` but piping the child process's `stderr` instead.
    492 
    493 	The `stderr` option must be kept as `pipe`, its default value.
    494 	*/
    495 	pipeStderr?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
    496 	pipeStderr?(target: WritableStream | string): ExecaChildProcess<StdoutStderrType>;
    497 
    498 	/**
    499 	Combines both `pipeStdout()` and `pipeStderr()`.
    500 
    501 	Either the `stdout` option or the `stderr` option must be kept as `pipe`, their default value. Also, the `all` option must be set to `true`.
    502 	*/
    503 	pipeAll?<Target extends ExecaChildPromise<StdoutStderrAll>>(target: Target): Target;
    504 	pipeAll?(target: WritableStream | string): ExecaChildProcess<StdoutStderrType>;
    505 };
    506 
    507 export type ExecaChildProcess<StdoutStderrType extends StdoutStderrAll = string> = ChildProcess &
    508 ExecaChildPromise<StdoutStderrType> &
    509 Promise<ExecaReturnValue<StdoutStderrType>>;
    510 
    511 /**
    512 Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a `childProcess`.
    513 
    514 Arguments are automatically escaped. They can contain any character, including spaces.
    515 
    516 This is the preferred method when executing single commands.
    517 
    518 @param file - The program/script to execute.
    519 @param arguments - Arguments to pass to `file` on execution.
    520 @returns An `ExecaChildProcess` that is both:
    521 	- a `Promise` resolving or rejecting with a `childProcessResult`.
    522 	- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.
    523 @throws A `childProcessResult` error
    524 
    525 @example <caption>Promise interface</caption>
    526 ```
    527 import {execa} from 'execa';
    528 
    529 const {stdout} = await execa('echo', ['unicorns']);
    530 console.log(stdout);
    531 //=> 'unicorns'
    532 ```
    533 
    534 @example <caption>Redirect output to a file</caption>
    535 ```
    536 import {execa} from 'execa';
    537 
    538 // Similar to `echo unicorns > stdout.txt` in Bash
    539 await execa('echo', ['unicorns']).pipeStdout('stdout.txt');
    540 
    541 // Similar to `echo unicorns 2> stdout.txt` in Bash
    542 await execa('echo', ['unicorns']).pipeStderr('stderr.txt');
    543 
    544 // Similar to `echo unicorns &> stdout.txt` in Bash
    545 await execa('echo', ['unicorns'], {all: true}).pipeAll('all.txt');
    546 ```
    547 
    548 @example <caption>Redirect input from a file</caption>
    549 ```
    550 import {execa} from 'execa';
    551 
    552 // Similar to `cat < stdin.txt` in Bash
    553 const {stdout} = await execa('cat', {inputFile: 'stdin.txt'});
    554 console.log(stdout);
    555 //=> 'unicorns'
    556 ```
    557 
    558 @example <caption>Save and pipe output from a child process</caption>
    559 ```
    560 import {execa} from 'execa';
    561 
    562 const {stdout} = await execa('echo', ['unicorns']).pipeStdout(process.stdout);
    563 // Prints `unicorns`
    564 console.log(stdout);
    565 // Also returns 'unicorns'
    566 ```
    567 
    568 @example <caption>Pipe multiple processes</caption>
    569 ```
    570 import {execa} from 'execa';
    571 
    572 // Similar to `echo unicorns | cat` in Bash
    573 const {stdout} = await execa('echo', ['unicorns']).pipeStdout(execa('cat'));
    574 console.log(stdout);
    575 //=> 'unicorns'
    576 ```
    577 
    578 @example <caption>Handling errors</caption>
    579 ```
    580 import {execa} from 'execa';
    581 
    582 // Catching an error
    583 try {
    584 	await execa('unknown', ['command']);
    585 } catch (error) {
    586 	console.log(error);
    587 	/*
    588 	{
    589 		message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',
    590 		errno: -2,
    591 		code: 'ENOENT',
    592 		syscall: 'spawn unknown',
    593 		path: 'unknown',
    594 		spawnargs: ['command'],
    595 		originalMessage: 'spawn unknown ENOENT',
    596 		shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT',
    597 		command: 'unknown command',
    598 		escapedCommand: 'unknown command',
    599 		stdout: '',
    600 		stderr: '',
    601 		failed: true,
    602 		timedOut: false,
    603 		isCanceled: false,
    604 		killed: false,
    605 		cwd: '/path/to/cwd'
    606 	}
    607 	\*\/
    608 }
    609 ```
    610 
    611 @example <caption>Graceful termination</caption>
    612 ```
    613 const subprocess = execa('node');
    614 
    615 setTimeout(() => {
    616 	subprocess.kill('SIGTERM', {
    617 		forceKillAfterTimeout: 2000
    618 	});
    619 }, 1000);
    620 ```
    621 */
    622 export function execa(
    623 	file: string,
    624 	arguments?: readonly string[],
    625 	options?: Options
    626 ): ExecaChildProcess;
    627 export function execa(
    628 	file: string,
    629 	arguments?: readonly string[],
    630 	options?: Options<null>
    631 ): ExecaChildProcess<Buffer>;
    632 export function execa(file: string, options?: Options): ExecaChildProcess;
    633 export function execa(file: string, options?: Options<null>): ExecaChildProcess<Buffer>;
    634 
    635 /**
    636 Same as `execa()` but synchronous.
    637 
    638 @param file - The program/script to execute.
    639 @param arguments - Arguments to pass to `file` on execution.
    640 @returns A `childProcessResult` object
    641 @throws A `childProcessResult` error
    642 
    643 @example <caption>Promise interface</caption>
    644 ```
    645 import {execa} from 'execa';
    646 
    647 const {stdout} = execaSync('echo', ['unicorns']);
    648 console.log(stdout);
    649 //=> 'unicorns'
    650 ```
    651 
    652 @example <caption>Redirect input from a file</caption>
    653 ```
    654 import {execa} from 'execa';
    655 
    656 // Similar to `cat < stdin.txt` in Bash
    657 const {stdout} = execaSync('cat', {inputFile: 'stdin.txt'});
    658 console.log(stdout);
    659 //=> 'unicorns'
    660 ```
    661 
    662 @example <caption>Handling errors</caption>
    663 ```
    664 import {execa} from 'execa';
    665 
    666 // Catching an error
    667 try {
    668 	execaSync('unknown', ['command']);
    669 } catch (error) {
    670 	console.log(error);
    671 	/*
    672 	{
    673 		message: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',
    674 		errno: -2,
    675 		code: 'ENOENT',
    676 		syscall: 'spawnSync unknown',
    677 		path: 'unknown',
    678 		spawnargs: ['command'],
    679 		originalMessage: 'spawnSync unknown ENOENT',
    680 		shortMessage: 'Command failed with ENOENT: unknown command spawnSync unknown ENOENT',
    681 		command: 'unknown command',
    682 		escapedCommand: 'unknown command',
    683 		stdout: '',
    684 		stderr: '',
    685 		failed: true,
    686 		timedOut: false,
    687 		isCanceled: false,
    688 		killed: false,
    689 		cwd: '/path/to/cwd'
    690 	}
    691 	\*\/
    692 }
    693 ```
    694 */
    695 export function execaSync(
    696 	file: string,
    697 	arguments?: readonly string[],
    698 	options?: SyncOptions
    699 ): ExecaSyncReturnValue;
    700 export function execaSync(
    701 	file: string,
    702 	arguments?: readonly string[],
    703 	options?: SyncOptions<null>
    704 ): ExecaSyncReturnValue<Buffer>;
    705 export function execaSync(file: string, options?: SyncOptions): ExecaSyncReturnValue;
    706 export function execaSync(
    707 	file: string,
    708 	options?: SyncOptions<null>
    709 ): ExecaSyncReturnValue<Buffer>;
    710 
    711 /**
    712 Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`.
    713 
    714 Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.
    715 
    716 This is the preferred method when executing a user-supplied `command` string, such as in a REPL.
    717 
    718 @param command - The program/script to execute and its arguments.
    719 @returns An `ExecaChildProcess` that is both:
    720 	- a `Promise` resolving or rejecting with a `childProcessResult`.
    721 	- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.
    722 @throws A `childProcessResult` error
    723 
    724 @example
    725 ```
    726 import {execaCommand} from 'execa';
    727 
    728 const {stdout} = await execaCommand('echo unicorns');
    729 console.log(stdout);
    730 //=> 'unicorns'
    731 ```
    732 */
    733 export function execaCommand(command: string, options?: Options): ExecaChildProcess;
    734 export function execaCommand(command: string, options?: Options<null>): ExecaChildProcess<Buffer>;
    735 
    736 /**
    737 Same as `execaCommand()` but synchronous.
    738 
    739 @param command - The program/script to execute and its arguments.
    740 @returns A `childProcessResult` object
    741 @throws A `childProcessResult` error
    742 
    743 @example
    744 ```
    745 import {execaCommandSync} from 'execa';
    746 
    747 const {stdout} = execaCommandSync('echo unicorns');
    748 console.log(stdout);
    749 //=> 'unicorns'
    750 ```
    751 */
    752 export function execaCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue;
    753 export function execaCommandSync(command: string, options?: SyncOptions<null>): ExecaSyncReturnValue<Buffer>;
    754 
    755 type TemplateExpression =
    756 	| string
    757 	| number
    758 	| ExecaReturnValue<string | Buffer>
    759 	| ExecaSyncReturnValue<string | Buffer>
    760 	| Array<string | number | ExecaReturnValue<string | Buffer> | ExecaSyncReturnValue<string | Buffer>>;
    761 
    762 type Execa$<StdoutStderrType extends StdoutStderrAll = string> = {
    763 	/**
    764 	Returns a new instance of `$` but with different default `options`. Consecutive calls are merged to previous ones.
    765 
    766 	This can be used to either:
    767 		- Set options for a specific command: `` $(options)`command` ``
    768 		- Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand` ``
    769 
    770 	@param options - Options to set
    771 	@returns A new instance of `$` with those `options` set
    772 
    773 	@example
    774 	```
    775 	import {$} from 'execa';
    776 
    777 	const $$ = $({stdio: 'inherit'});
    778 
    779 	await $$`echo unicorns`;
    780 	//=> 'unicorns'
    781 
    782 	await $$`echo rainbows`;
    783 	//=> 'rainbows'
    784 	```
    785 	*/
    786 	(options: Options<undefined>): Execa$<StdoutStderrType>;
    787 	(options: Options): Execa$;
    788 	(options: Options<null>): Execa$<Buffer>;
    789 	(
    790 		templates: TemplateStringsArray,
    791 		...expressions: TemplateExpression[]
    792 	): ExecaChildProcess<StdoutStderrType>;
    793 
    794 	/**
    795 	Same as $\`command\` but synchronous.
    796 
    797 	@returns A `childProcessResult` object
    798 	@throws A `childProcessResult` error
    799 
    800 	@example <caption>Basic</caption>
    801 	```
    802 	import {$} from 'execa';
    803 
    804 	const branch = $.sync`git branch --show-current`;
    805 	$.sync`dep deploy --branch=${branch}`;
    806 	```
    807 
    808 	@example <caption>Multiple arguments</caption>
    809 	```
    810 	import {$} from 'execa';
    811 
    812 	const args = ['unicorns', '&', 'rainbows!'];
    813 	const {stdout} = $.sync`echo ${args}`;
    814 	console.log(stdout);
    815 	//=> 'unicorns & rainbows!'
    816 	```
    817 
    818 	@example <caption>With options</caption>
    819 	```
    820 	import {$} from 'execa';
    821 
    822 	$.sync({stdio: 'inherit'})`echo unicorns`;
    823 	//=> 'unicorns'
    824 	```
    825 
    826 	@example <caption>Shared options</caption>
    827 	```
    828 	import {$} from 'execa';
    829 
    830 	const $$ = $({stdio: 'inherit'});
    831 
    832 	$$.sync`echo unicorns`;
    833 	//=> 'unicorns'
    834 
    835 	$$.sync`echo rainbows`;
    836 	//=> 'rainbows'
    837 	```
    838 	*/
    839 	sync(
    840 		templates: TemplateStringsArray,
    841 		...expressions: TemplateExpression[]
    842 	): ExecaSyncReturnValue<StdoutStderrType>;
    843 };
    844 
    845 /**
    846 Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`.
    847 
    848 Arguments are automatically escaped. They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``.
    849 
    850 This is the preferred method when executing multiple commands in a script file.
    851 
    852 The `command` string can inject any `${value}` with the following types: string, number, `childProcess` or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${childProcess}`, the process's `stdout` is used.
    853 
    854 @returns An `ExecaChildProcess` that is both:
    855 	- a `Promise` resolving or rejecting with a `childProcessResult`.
    856 	- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.
    857 @throws A `childProcessResult` error
    858 
    859 @example <caption>Basic</caption>
    860 ```
    861 import {$} from 'execa';
    862 
    863 const branch = await $`git branch --show-current`;
    864 await $`dep deploy --branch=${branch}`;
    865 ```
    866 
    867 @example <caption>Multiple arguments</caption>
    868 ```
    869 import {$} from 'execa';
    870 
    871 const args = ['unicorns', '&', 'rainbows!'];
    872 const {stdout} = await $`echo ${args}`;
    873 console.log(stdout);
    874 //=> 'unicorns & rainbows!'
    875 ```
    876 
    877 @example <caption>With options</caption>
    878 ```
    879 import {$} from 'execa';
    880 
    881 await $({stdio: 'inherit'})`echo unicorns`;
    882 //=> 'unicorns'
    883 ```
    884 
    885 @example <caption>Shared options</caption>
    886 ```
    887 import {$} from 'execa';
    888 
    889 const $$ = $({stdio: 'inherit'});
    890 
    891 await $$`echo unicorns`;
    892 //=> 'unicorns'
    893 
    894 await $$`echo rainbows`;
    895 //=> 'rainbows'
    896 ```
    897 */
    898 export const $: Execa$;
    899 
    900 /**
    901 Execute a Node.js script as a child process.
    902 
    903 Arguments are automatically escaped. They can contain any character, including spaces.
    904 
    905 This is the preferred method when executing Node.js files.
    906 
    907 Like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options):
    908   - the current Node version and options are used. This can be overridden using the `nodePath` and `nodeOptions` options.
    909   - the `shell` option cannot be used
    910   - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to `stdio`
    911 
    912 @param scriptPath - Node.js script to execute.
    913 @param arguments - Arguments to pass to `scriptPath` on execution.
    914 @returns An `ExecaChildProcess` that is both:
    915 	- a `Promise` resolving or rejecting with a `childProcessResult`.
    916 	- a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.
    917 @throws A `childProcessResult` error
    918 
    919 @example
    920 ```
    921 import {execa} from 'execa';
    922 
    923 await execaNode('scriptPath', ['argument']);
    924 ```
    925 */
    926 export function execaNode(
    927 	scriptPath: string,
    928 	arguments?: readonly string[],
    929 	options?: NodeOptions
    930 ): ExecaChildProcess;
    931 export function execaNode(
    932 	scriptPath: string,
    933 	arguments?: readonly string[],
    934 	options?: NodeOptions<null>
    935 ): ExecaChildProcess<Buffer>;
    936 export function execaNode(scriptPath: string, options?: NodeOptions): ExecaChildProcess;
    937 export function execaNode(scriptPath: string, options?: NodeOptions<null>): ExecaChildProcess<Buffer>;