Comparing version 5.1.1 to 6.0.0
860
index.d.ts
@@ -1,564 +0,552 @@ | ||
/// <reference types="node"/> | ||
import {ChildProcess} from 'child_process'; | ||
import {Stream, Readable as ReadableStream} from 'stream'; | ||
import {Buffer} from 'node:buffer'; | ||
import {ChildProcess} from 'node:child_process'; | ||
import {Stream, Readable as ReadableStream} from 'node:stream'; | ||
declare namespace execa { | ||
type StdioOption = | ||
| 'pipe' | ||
| 'ipc' | ||
| 'ignore' | ||
| 'inherit' | ||
| Stream | ||
| number | ||
| undefined; | ||
export type StdioOption = | ||
| 'pipe' | ||
| 'ipc' | ||
| 'ignore' | ||
| 'inherit' | ||
| Stream | ||
| number | ||
| undefined; | ||
interface CommonOptions<EncodingType> { | ||
/** | ||
Kill the spawned process when the parent process exits unless either: | ||
- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached) | ||
- the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit | ||
export interface CommonOptions<EncodingType> { | ||
/** | ||
Kill the spawned process when the parent process exits unless either: | ||
- the spawned process is [`detached`](https://nodejs.org/api/child_process.html#child_process_options_detached) | ||
- the parent process is terminated abruptly, for example, with `SIGKILL` as opposed to `SIGTERM` or a normal exit | ||
@default true | ||
*/ | ||
readonly cleanup?: boolean; | ||
@default true | ||
*/ | ||
readonly cleanup?: boolean; | ||
/** | ||
Prefer locally installed binaries when looking for a binary to execute. | ||
/** | ||
Prefer locally installed binaries when looking for a binary to execute. | ||
If you `$ npm install foo`, you can then `execa('foo')`. | ||
If you `$ npm install foo`, you can then `execa('foo')`. | ||
@default false | ||
*/ | ||
readonly preferLocal?: boolean; | ||
@default false | ||
*/ | ||
readonly preferLocal?: boolean; | ||
/** | ||
Preferred path to find locally installed binaries in (use with `preferLocal`). | ||
/** | ||
Preferred path to find locally installed binaries in (use with `preferLocal`). | ||
@default process.cwd() | ||
*/ | ||
readonly localDir?: string; | ||
@default process.cwd() | ||
*/ | ||
readonly localDir?: string; | ||
/** | ||
Path to the Node.js executable to use in child processes. | ||
/** | ||
Path to the Node.js executable to use in child processes. | ||
This can be either an absolute path or a path relative to the `cwd` option. | ||
This can be either an absolute path or a path relative to the `cwd` option. | ||
Requires `preferLocal` to be `true`. | ||
Requires `preferLocal` to be `true`. | ||
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. | ||
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. | ||
@default process.execPath | ||
*/ | ||
readonly execPath?: string; | ||
@default process.execPath | ||
*/ | ||
readonly execPath?: string; | ||
/** | ||
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. | ||
/** | ||
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. | ||
If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data. | ||
If the spawned process fails, `error.stdout`, `error.stderr`, and `error.all` will contain the buffered data. | ||
@default true | ||
*/ | ||
readonly buffer?: boolean; | ||
@default true | ||
*/ | ||
readonly buffer?: boolean; | ||
/** | ||
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). | ||
/** | ||
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). | ||
@default 'pipe' | ||
*/ | ||
readonly stdin?: StdioOption; | ||
@default 'pipe' | ||
*/ | ||
readonly stdin?: StdioOption; | ||
/** | ||
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). | ||
/** | ||
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). | ||
@default 'pipe' | ||
*/ | ||
readonly stdout?: StdioOption; | ||
@default 'pipe' | ||
*/ | ||
readonly stdout?: StdioOption; | ||
/** | ||
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). | ||
/** | ||
Same options as [`stdio`](https://nodejs.org/dist/latest-v6.x/docs/api/child_process.html#child_process_options_stdio). | ||
@default 'pipe' | ||
*/ | ||
readonly stderr?: StdioOption; | ||
@default 'pipe' | ||
*/ | ||
readonly stderr?: StdioOption; | ||
/** | ||
Setting this to `false` resolves the promise with the error instead of rejecting it. | ||
/** | ||
Setting this to `false` resolves the promise with the error instead of rejecting it. | ||
@default true | ||
*/ | ||
readonly reject?: boolean; | ||
@default true | ||
*/ | ||
readonly reject?: boolean; | ||
/** | ||
Add an `.all` property on the promise and the resolved value. The property contains the output of the process with `stdout` and `stderr` interleaved. | ||
/** | ||
Add an `.all` property on the promise and the resolved value. The property contains the output of the process with `stdout` and `stderr` interleaved. | ||
@default false | ||
*/ | ||
readonly all?: boolean; | ||
@default false | ||
*/ | ||
readonly all?: boolean; | ||
/** | ||
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output. | ||
/** | ||
Strip the final [newline character](https://en.wikipedia.org/wiki/Newline) from the output. | ||
@default true | ||
*/ | ||
readonly stripFinalNewline?: boolean; | ||
@default true | ||
*/ | ||
readonly stripFinalNewline?: boolean; | ||
/** | ||
Set to `false` if you don't want to extend the environment variables when providing the `env` property. | ||
/** | ||
Set to `false` if you don't want to extend the environment variables when providing the `env` property. | ||
@default true | ||
*/ | ||
readonly extendEnv?: boolean; | ||
@default true | ||
*/ | ||
readonly extendEnv?: boolean; | ||
/** | ||
Current working directory of the child process. | ||
/** | ||
Current working directory of the child process. | ||
@default process.cwd() | ||
*/ | ||
readonly cwd?: string; | ||
@default process.cwd() | ||
*/ | ||
readonly cwd?: string; | ||
/** | ||
Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this. | ||
/** | ||
Environment key-value pairs. Extends automatically from `process.env`. Set `extendEnv` to `false` if you don't want this. | ||
@default process.env | ||
*/ | ||
readonly env?: NodeJS.ProcessEnv; | ||
@default process.env | ||
*/ | ||
readonly env?: NodeJS.ProcessEnv; | ||
/** | ||
Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified. | ||
*/ | ||
readonly argv0?: string; | ||
/** | ||
Explicitly set the value of `argv[0]` sent to the child process. This will be set to `command` or `file` if not specified. | ||
*/ | ||
readonly argv0?: string; | ||
/** | ||
Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration. | ||
/** | ||
Child's [stdio](https://nodejs.org/api/child_process.html#child_process_options_stdio) configuration. | ||
@default 'pipe' | ||
*/ | ||
readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[]; | ||
@default 'pipe' | ||
*/ | ||
readonly stdio?: 'pipe' | 'ignore' | 'inherit' | readonly StdioOption[]; | ||
/** | ||
Specify the kind of serialization used for sending messages between processes when using the `stdio: 'ipc'` option or `execa.node()`: | ||
- `json`: Uses `JSON.stringify()` and `JSON.parse()`. | ||
- `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value) | ||
/** | ||
Specify the kind of serialization used for sending messages between processes when using the `stdio: 'ipc'` option or `execaNode()`: | ||
- `json`: Uses `JSON.stringify()` and `JSON.parse()`. | ||
- `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value) | ||
Requires Node.js `13.2.0` or later. | ||
Requires Node.js `13.2.0` or later. | ||
[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization) | ||
[More info.](https://nodejs.org/api/child_process.html#child_process_advanced_serialization) | ||
@default 'json' | ||
*/ | ||
readonly serialization?: 'json' | 'advanced'; | ||
@default 'json' | ||
*/ | ||
readonly serialization?: 'json' | 'advanced'; | ||
/** | ||
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). | ||
/** | ||
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). | ||
@default false | ||
*/ | ||
readonly detached?: boolean; | ||
@default false | ||
*/ | ||
readonly detached?: boolean; | ||
/** | ||
Sets the user identity of the process. | ||
*/ | ||
readonly uid?: number; | ||
/** | ||
Sets the user identity of the process. | ||
*/ | ||
readonly uid?: number; | ||
/** | ||
Sets the group identity of the process. | ||
*/ | ||
readonly gid?: number; | ||
/** | ||
Sets the group identity of the process. | ||
*/ | ||
readonly gid?: number; | ||
/** | ||
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. | ||
/** | ||
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. | ||
We recommend against using this option since it is: | ||
- not cross-platform, encouraging shell-specific syntax. | ||
- slower, because of the additional shell interpretation. | ||
- unsafe, potentially allowing command injection. | ||
We recommend against using this option since it is: | ||
- not cross-platform, encouraging shell-specific syntax. | ||
- slower, because of the additional shell interpretation. | ||
- unsafe, potentially allowing command injection. | ||
@default false | ||
*/ | ||
readonly shell?: boolean | string; | ||
@default false | ||
*/ | ||
readonly shell?: boolean | string; | ||
/** | ||
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. | ||
/** | ||
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. | ||
@default 'utf8' | ||
*/ | ||
readonly encoding?: EncodingType; | ||
@default 'utf8' | ||
*/ | ||
readonly encoding?: EncodingType; | ||
/** | ||
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. | ||
/** | ||
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. | ||
@default 0 | ||
*/ | ||
readonly timeout?: number; | ||
@default 0 | ||
*/ | ||
readonly timeout?: number; | ||
/** | ||
Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 100 MB. | ||
/** | ||
Largest amount of data in bytes allowed on `stdout` or `stderr`. Default: 100 MB. | ||
@default 100_000_000 | ||
*/ | ||
readonly maxBuffer?: number; | ||
@default 100_000_000 | ||
*/ | ||
readonly maxBuffer?: number; | ||
/** | ||
Signal value to be used when the spawned process will be killed. | ||
/** | ||
Signal value to be used when the spawned process will be killed. | ||
@default 'SIGTERM' | ||
*/ | ||
readonly killSignal?: string | number; | ||
@default 'SIGTERM' | ||
*/ | ||
readonly killSignal?: string | number; | ||
/** | ||
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`. | ||
/** | ||
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`. | ||
@default false | ||
*/ | ||
readonly windowsVerbatimArguments?: boolean; | ||
@default false | ||
*/ | ||
readonly windowsVerbatimArguments?: boolean; | ||
/** | ||
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. | ||
/** | ||
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. | ||
@default true | ||
*/ | ||
readonly windowsHide?: boolean; | ||
} | ||
@default true | ||
*/ | ||
readonly windowsHide?: boolean; | ||
} | ||
interface Options<EncodingType = string> extends CommonOptions<EncodingType> { | ||
/** | ||
Write some input to the `stdin` of your binary. | ||
*/ | ||
readonly input?: string | Buffer | ReadableStream; | ||
} | ||
export interface Options<EncodingType = string> extends CommonOptions<EncodingType> { | ||
/** | ||
Write some input to the `stdin` of your binary. | ||
*/ | ||
readonly input?: string | Buffer | ReadableStream; | ||
} | ||
interface SyncOptions<EncodingType = string> extends CommonOptions<EncodingType> { | ||
/** | ||
Write some input to the `stdin` of your binary. | ||
*/ | ||
readonly input?: string | Buffer; | ||
} | ||
export interface SyncOptions<EncodingType = string> extends CommonOptions<EncodingType> { | ||
/** | ||
Write some input to the `stdin` of your binary. | ||
*/ | ||
readonly input?: string | Buffer; | ||
} | ||
interface NodeOptions<EncodingType = string> extends Options<EncodingType> { | ||
/** | ||
The Node.js executable to use. | ||
export interface NodeOptions<EncodingType = string> extends Options<EncodingType> { | ||
/** | ||
The Node.js executable to use. | ||
@default process.execPath | ||
*/ | ||
readonly nodePath?: string; | ||
@default process.execPath | ||
*/ | ||
readonly nodePath?: string; | ||
/** | ||
List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable. | ||
/** | ||
List of [CLI options](https://nodejs.org/api/cli.html#cli_options) passed to the Node.js executable. | ||
@default process.execArgv | ||
*/ | ||
readonly nodeOptions?: string[]; | ||
} | ||
@default process.execArgv | ||
*/ | ||
readonly nodeOptions?: string[]; | ||
} | ||
interface ExecaReturnBase<StdoutStderrType> { | ||
/** | ||
The file and arguments that were run, for logging purposes. | ||
export interface ExecaReturnBase<StdoutStderrType> { | ||
/** | ||
The file and arguments that were run, for logging purposes. | ||
This is not escaped and should not be executed directly as a process, including using `execa()` or `execa.command()`. | ||
*/ | ||
command: string; | ||
This is not escaped and should not be executed directly as a process, including using `execa()` or `execaCommand()`. | ||
*/ | ||
command: string; | ||
/** | ||
Same as `command` but escaped. | ||
/** | ||
Same as `command` but escaped. | ||
This is meant to be copy and pasted into a shell, for debugging purposes. | ||
Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execa.command()`. | ||
*/ | ||
escapedCommand: string; | ||
This is meant to be copy and pasted into a shell, for debugging purposes. | ||
Since the escaping is fairly basic, this should not be executed directly as a process, including using `execa()` or `execaCommand()`. | ||
*/ | ||
escapedCommand: string; | ||
/** | ||
The numeric exit code of the process that was run. | ||
*/ | ||
exitCode: number; | ||
/** | ||
The numeric exit code of the process that was run. | ||
*/ | ||
exitCode: number; | ||
/** | ||
The output of the process on stdout. | ||
*/ | ||
stdout: StdoutStderrType; | ||
/** | ||
The output of the process on stdout. | ||
*/ | ||
stdout: StdoutStderrType; | ||
/** | ||
The output of the process on stderr. | ||
*/ | ||
stderr: StdoutStderrType; | ||
/** | ||
The output of the process on stderr. | ||
*/ | ||
stderr: StdoutStderrType; | ||
/** | ||
Whether the process failed to run. | ||
*/ | ||
failed: boolean; | ||
/** | ||
Whether the process failed to run. | ||
*/ | ||
failed: boolean; | ||
/** | ||
Whether the process timed out. | ||
*/ | ||
timedOut: boolean; | ||
/** | ||
Whether the process timed out. | ||
*/ | ||
timedOut: boolean; | ||
/** | ||
Whether the process was killed. | ||
*/ | ||
killed: boolean; | ||
/** | ||
Whether the process was killed. | ||
*/ | ||
killed: boolean; | ||
/** | ||
The name of the signal that was used to terminate the process. For example, `SIGFPE`. | ||
/** | ||
The name of the signal that was used to terminate the process. For example, `SIGFPE`. | ||
If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. | ||
*/ | ||
signal?: string; | ||
If a signal terminated the process, this property is defined and included in the error message. Otherwise it is `undefined`. | ||
*/ | ||
signal?: string; | ||
/** | ||
A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`. | ||
/** | ||
A human-friendly description of the signal that was used to terminate the process. For example, `Floating point arithmetic error`. | ||
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. | ||
*/ | ||
signalDescription?: string; | ||
} | ||
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. | ||
*/ | ||
signalDescription?: string; | ||
} | ||
interface ExecaSyncReturnValue<StdoutErrorType = string> | ||
extends ExecaReturnBase<StdoutErrorType> { | ||
} | ||
export interface ExecaSyncReturnValue<StdoutErrorType = string> | ||
extends ExecaReturnBase<StdoutErrorType> { | ||
} | ||
/** | ||
Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance. | ||
The child process fails when: | ||
- its exit code is not `0` | ||
- it was killed with a signal | ||
- timing out | ||
- being canceled | ||
- there's not enough memory or there are already too many child processes | ||
*/ | ||
export interface ExecaReturnValue<StdoutErrorType = string> | ||
extends ExecaSyncReturnValue<StdoutErrorType> { | ||
/** | ||
Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance. | ||
The output of the process with `stdout` and `stderr` interleaved. | ||
The child process fails when: | ||
- its exit code is not `0` | ||
- it was killed with a signal | ||
- timing out | ||
- being canceled | ||
- there's not enough memory or there are already too many child processes | ||
This is `undefined` if either: | ||
- the `all` option is `false` (default value) | ||
- `execaSync()` was used | ||
*/ | ||
interface ExecaReturnValue<StdoutErrorType = string> | ||
extends ExecaSyncReturnValue<StdoutErrorType> { | ||
/** | ||
The output of the process with `stdout` and `stderr` interleaved. | ||
all?: StdoutErrorType; | ||
This is `undefined` if either: | ||
- the `all` option is `false` (default value) | ||
- `execa.sync()` was used | ||
*/ | ||
all?: StdoutErrorType; | ||
/** | ||
Whether the process was canceled. | ||
*/ | ||
isCanceled: boolean; | ||
} | ||
/** | ||
Whether the process was canceled. | ||
*/ | ||
isCanceled: boolean; | ||
} | ||
export interface ExecaSyncError<StdoutErrorType = string> | ||
extends Error, | ||
ExecaReturnBase<StdoutErrorType> { | ||
/** | ||
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. | ||
interface ExecaSyncError<StdoutErrorType = string> | ||
extends Error, | ||
ExecaReturnBase<StdoutErrorType> { | ||
/** | ||
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. | ||
The child process stderr then stdout are appended to the end, separated with newlines and not interleaved. | ||
*/ | ||
message: string; | ||
The child process stderr then stdout are appended to the end, separated with newlines and not interleaved. | ||
*/ | ||
message: string; | ||
/** | ||
This is the same as the `message` property except it does not include the child process stdout/stderr. | ||
*/ | ||
shortMessage: string; | ||
/** | ||
This is the same as the `message` property except it does not include the child process stdout/stderr. | ||
*/ | ||
shortMessage: string; | ||
/** | ||
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. | ||
/** | ||
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. | ||
This is `undefined` unless the child process exited due to an `error` event or a timeout. | ||
*/ | ||
originalMessage?: string; | ||
} | ||
This is `undefined` unless the child process exited due to an `error` event or a timeout. | ||
*/ | ||
originalMessage?: string; | ||
} | ||
export interface ExecaError<StdoutErrorType = string> | ||
extends ExecaSyncError<StdoutErrorType> { | ||
/** | ||
The output of the process with `stdout` and `stderr` interleaved. | ||
interface ExecaError<StdoutErrorType = string> | ||
extends ExecaSyncError<StdoutErrorType> { | ||
/** | ||
The output of the process with `stdout` and `stderr` interleaved. | ||
This is `undefined` if either: | ||
- the `all` option is `false` (default value) | ||
- `execaSync()` was used | ||
*/ | ||
all?: StdoutErrorType; | ||
This is `undefined` if either: | ||
- the `all` option is `false` (default value) | ||
- `execa.sync()` was used | ||
*/ | ||
all?: StdoutErrorType; | ||
/** | ||
Whether the process was canceled. | ||
*/ | ||
isCanceled: boolean; | ||
} | ||
/** | ||
Whether the process was canceled. | ||
*/ | ||
isCanceled: boolean; | ||
} | ||
export interface KillOptions { | ||
/** | ||
Milliseconds to wait for the child process to terminate before sending `SIGKILL`. | ||
interface KillOptions { | ||
/** | ||
Milliseconds to wait for the child process to terminate before sending `SIGKILL`. | ||
Can be disabled with `false`. | ||
Can be disabled with `false`. | ||
@default 5000 | ||
*/ | ||
forceKillAfterTimeout?: number | false; | ||
} | ||
@default 5000 | ||
*/ | ||
forceKillAfterTimeout?: number | false; | ||
} | ||
export interface ExecaChildPromise<StdoutErrorType> { | ||
/** | ||
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). | ||
interface ExecaChildPromise<StdoutErrorType> { | ||
/** | ||
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). | ||
This is `undefined` if either: | ||
- the `all` option is `false` (the default value) | ||
- 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) | ||
*/ | ||
all?: ReadableStream; | ||
This is `undefined` if either: | ||
- the `all` option is `false` (the default value) | ||
- 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) | ||
*/ | ||
all?: ReadableStream; | ||
catch<ResultType = never>( | ||
onRejected?: (reason: ExecaError<StdoutErrorType>) => ResultType | PromiseLike<ResultType> | ||
): Promise<ExecaReturnValue<StdoutErrorType> | ResultType>; | ||
catch<ResultType = never>( | ||
onRejected?: (reason: ExecaError<StdoutErrorType>) => ResultType | PromiseLike<ResultType> | ||
): Promise<ExecaReturnValue<StdoutErrorType> | ResultType>; | ||
/** | ||
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`. | ||
*/ | ||
kill(signal?: string, options?: KillOptions): void; | ||
/** | ||
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`. | ||
*/ | ||
kill(signal?: string, options?: KillOptions): void; | ||
/** | ||
Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This is preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. | ||
*/ | ||
cancel(): void; | ||
} | ||
type ExecaChildProcess<StdoutErrorType = string> = ChildProcess & | ||
ExecaChildPromise<StdoutErrorType> & | ||
Promise<ExecaReturnValue<StdoutErrorType>>; | ||
/** | ||
Similar to [`childProcess.kill()`](https://nodejs.org/api/child_process.html#child_process_subprocess_kill_signal). This is preferred when cancelling the child process execution as the error is more descriptive and [`childProcessResult.isCanceled`](#iscanceled) is set to `true`. | ||
*/ | ||
cancel(): void; | ||
} | ||
declare const execa: { | ||
/** | ||
Execute a file. | ||
export type ExecaChildProcess<StdoutErrorType = string> = ChildProcess & | ||
ExecaChildPromise<StdoutErrorType> & | ||
Promise<ExecaReturnValue<StdoutErrorType>>; | ||
Think of this as a mix of `child_process.execFile` and `child_process.spawn`. | ||
/** | ||
Execute a file. | ||
@param file - The program/script to execute. | ||
@param arguments - Arguments to pass to `file` on execution. | ||
@returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. | ||
Think of this as a mix of `child_process.execFile` and `child_process.spawn`. | ||
@example | ||
``` | ||
import execa = require('execa'); | ||
@param file - The program/script to execute. | ||
@param arguments - Arguments to pass to `file` on execution. | ||
@returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. | ||
(async () => { | ||
const {stdout} = await execa('echo', ['unicorns']); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
@example | ||
``` | ||
import {execa} from 'execa'; | ||
// Cancelling a spawned process | ||
const {stdout} = await execa('echo', ['unicorns']); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
const subprocess = execa('node'); | ||
// Cancelling a spawned process | ||
setTimeout(() => { | ||
subprocess.cancel() | ||
}, 1000); | ||
const subprocess = execa('node'); | ||
try { | ||
await subprocess; | ||
} catch (error) { | ||
console.log(subprocess.killed); // true | ||
console.log(error.isCanceled); // true | ||
} | ||
})(); | ||
setTimeout(() => { | ||
subprocess.cancel() | ||
}, 1000); | ||
// Pipe the child process stdout to the current stdout | ||
execa('echo', ['unicorns']).stdout.pipe(process.stdout); | ||
``` | ||
*/ | ||
( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: execa.Options | ||
): execa.ExecaChildProcess; | ||
( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: execa.Options<null> | ||
): execa.ExecaChildProcess<Buffer>; | ||
(file: string, options?: execa.Options): execa.ExecaChildProcess; | ||
(file: string, options?: execa.Options<null>): execa.ExecaChildProcess< | ||
Buffer | ||
>; | ||
try { | ||
await subprocess; | ||
} catch (error) { | ||
console.log(subprocess.killed); // true | ||
console.log(error.isCanceled); // true | ||
} | ||
/** | ||
Execute a file synchronously. | ||
// Pipe the child process stdout to the current stdout | ||
execa('echo', ['unicorns']).stdout.pipe(process.stdout); | ||
``` | ||
*/ | ||
export function execa( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: Options | ||
): ExecaChildProcess; | ||
export function execa( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: Options<null> | ||
): ExecaChildProcess<Buffer>; | ||
export function execa(file: string, options?: Options): ExecaChildProcess; | ||
export function execa(file: string, options?: Options<null>): ExecaChildProcess<Buffer>; | ||
This method throws an `Error` if the command fails. | ||
/** | ||
Execute a file synchronously. | ||
@param file - The program/script to execute. | ||
@param arguments - Arguments to pass to `file` on execution. | ||
@returns A result `Object` with `stdout` and `stderr` properties. | ||
*/ | ||
sync( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: execa.SyncOptions | ||
): execa.ExecaSyncReturnValue; | ||
sync( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: execa.SyncOptions<null> | ||
): execa.ExecaSyncReturnValue<Buffer>; | ||
sync(file: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue; | ||
sync( | ||
file: string, | ||
options?: execa.SyncOptions<null> | ||
): execa.ExecaSyncReturnValue<Buffer>; | ||
This method throws an `Error` if the command fails. | ||
/** | ||
Same as `execa()` except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execa.command('echo unicorns')`. | ||
@param file - The program/script to execute. | ||
@param arguments - Arguments to pass to `file` on execution. | ||
@returns A result `Object` with `stdout` and `stderr` properties. | ||
*/ | ||
export function execaSync( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: SyncOptions | ||
): ExecaSyncReturnValue; | ||
export function execaSync( | ||
file: string, | ||
arguments?: readonly string[], | ||
options?: SyncOptions<null> | ||
): ExecaSyncReturnValue<Buffer>; | ||
export function execaSync(file: string, options?: SyncOptions): ExecaSyncReturnValue; | ||
export function execaSync( | ||
file: string, | ||
options?: SyncOptions<null> | ||
): ExecaSyncReturnValue<Buffer>; | ||
If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if `command` is not a constant but a variable, for example with `__dirname` or `process.cwd()`. Except for spaces, no escaping/quoting is needed. | ||
/** | ||
Same as `execa()` except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execaCommand('echo unicorns')`. | ||
The `shell` option must be used if the `command` uses shell-specific features (for example, `&&` or `||`), as opposed to being a simple `file` followed by its `arguments`. | ||
If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if `command` is not a constant but a variable, for example with `__dirname` or `process.cwd()`. Except for spaces, no escaping/quoting is needed. | ||
@param command - The program/script to execute and its arguments. | ||
@returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. | ||
The `shell` option must be used if the `command` uses shell-specific features (for example, `&&` or `||`), as opposed to being a simple `file` followed by its `arguments`. | ||
@example | ||
``` | ||
import execa = require('execa'); | ||
@param command - The program/script to execute and its arguments. | ||
@returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. | ||
(async () => { | ||
const {stdout} = await execa.command('echo unicorns'); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
})(); | ||
``` | ||
*/ | ||
command(command: string, options?: execa.Options): execa.ExecaChildProcess; | ||
command(command: string, options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>; | ||
@example | ||
``` | ||
import {execaCommand} from 'execa'; | ||
/** | ||
Same as `execa.command()` but synchronous. | ||
const {stdout} = await execaCommand('echo unicorns'); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
``` | ||
*/ | ||
export function execaCommand(command: string, options?: Options): ExecaChildProcess; | ||
export function execaCommand(command: string, options?: Options<null>): ExecaChildProcess<Buffer>; | ||
@param command - The program/script to execute and its arguments. | ||
@returns A result `Object` with `stdout` and `stderr` properties. | ||
*/ | ||
commandSync(command: string, options?: execa.SyncOptions): execa.ExecaSyncReturnValue; | ||
commandSync(command: string, options?: execa.SyncOptions<null>): execa.ExecaSyncReturnValue<Buffer>; | ||
/** | ||
Same as `execaCommand()` but synchronous. | ||
/** | ||
Execute a Node.js script as a child process. | ||
@param command - The program/script to execute and its arguments. | ||
@returns A result `Object` with `stdout` and `stderr` properties. | ||
*/ | ||
export function execaCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue; | ||
export function execaCommandSync(command: string, options?: SyncOptions<null>): ExecaSyncReturnValue<Buffer>; | ||
Same as `execa('node', [scriptPath, ...arguments], options)` except (like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)): | ||
- the current Node version and options are used. This can be overridden using the `nodePath` and `nodeArguments` options. | ||
- the `shell` option cannot be used | ||
- an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio) | ||
/** | ||
Execute a Node.js script as a child process. | ||
@param scriptPath - Node.js script to execute. | ||
@param arguments - Arguments to pass to `scriptPath` on execution. | ||
@returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. | ||
*/ | ||
node( | ||
scriptPath: string, | ||
arguments?: readonly string[], | ||
options?: execa.NodeOptions | ||
): execa.ExecaChildProcess; | ||
node( | ||
scriptPath: string, | ||
arguments?: readonly string[], | ||
options?: execa.Options<null> | ||
): execa.ExecaChildProcess<Buffer>; | ||
node(scriptPath: string, options?: execa.Options): execa.ExecaChildProcess; | ||
node(scriptPath: string, options?: execa.Options<null>): execa.ExecaChildProcess<Buffer>; | ||
}; | ||
Same as `execa('node', [scriptPath, ...arguments], options)` except (like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options)): | ||
- the current Node version and options are used. This can be overridden using the `nodePath` and `nodeArguments` options. | ||
- the `shell` option cannot be used | ||
- an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio) | ||
export = execa; | ||
@param scriptPath - Node.js script to execute. | ||
@param arguments - Arguments to pass to `scriptPath` on execution. | ||
@returns A [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess), which is enhanced to also be a `Promise` for a result `Object` with `stdout` and `stderr` properties. | ||
*/ | ||
export function execaNode( | ||
scriptPath: string, | ||
arguments?: readonly string[], | ||
options?: NodeOptions | ||
): ExecaChildProcess; | ||
export function execaNode( | ||
scriptPath: string, | ||
arguments?: readonly string[], | ||
options?: Options<null> | ||
): ExecaChildProcess<Buffer>; | ||
export function execaNode(scriptPath: string, options?: Options): ExecaChildProcess; | ||
export function execaNode(scriptPath: string, options?: Options<null>): ExecaChildProcess<Buffer>; |
79
index.js
@@ -1,14 +0,15 @@ | ||
'use strict'; | ||
const path = require('path'); | ||
const childProcess = require('child_process'); | ||
const crossSpawn = require('cross-spawn'); | ||
const stripFinalNewline = require('strip-final-newline'); | ||
const npmRunPath = require('npm-run-path'); | ||
const onetime = require('onetime'); | ||
const makeError = require('./lib/error'); | ||
const normalizeStdio = require('./lib/stdio'); | ||
const {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} = require('./lib/kill'); | ||
const {handleInput, getSpawnedResult, makeAllStream, validateInputSync} = require('./lib/stream'); | ||
const {mergePromise, getSpawnedPromise} = require('./lib/promise'); | ||
const {joinCommand, parseCommand, getEscapedCommand} = require('./lib/command'); | ||
import {Buffer} from 'node:buffer'; | ||
import path from 'node:path'; | ||
import childProcess from 'node:child_process'; | ||
import process from 'node:process'; | ||
import crossSpawn from 'cross-spawn'; | ||
import stripFinalNewline from 'strip-final-newline'; | ||
import {npmRunPathEnv} from 'npm-run-path'; | ||
import onetime from 'onetime'; | ||
import {makeError} from './lib/error.js'; | ||
import {normalizeStdio, normalizeStdioNode} from './lib/stdio.js'; | ||
import {spawnedKill, spawnedCancel, setupTimeout, validateTimeout, setExitHandler} from './lib/kill.js'; | ||
import {handleInput, getSpawnedResult, makeAllStream, validateInputSync} from './lib/stream.js'; | ||
import {mergePromise, getSpawnedPromise} from './lib/promise.js'; | ||
import {joinCommand, parseCommand, getEscapedCommand} from './lib/command.js'; | ||
@@ -21,3 +22,3 @@ const DEFAULT_MAX_BUFFER = 1000 * 1000 * 100; | ||
if (preferLocal) { | ||
return npmRunPath.env({env, cwd: localDir, execPath}); | ||
return npmRunPathEnv({env, cwd: localDir, execPath}); | ||
} | ||
@@ -47,3 +48,3 @@ | ||
windowsHide: true, | ||
...options | ||
...options, | ||
}; | ||
@@ -65,3 +66,3 @@ | ||
if (typeof value !== 'string' && !Buffer.isBuffer(value)) { | ||
// When `execa.sync()` errors, we normalize it to '' to mimic `execa()` | ||
// When `execaSync()` errors, we normalize it to '' to mimic `execa()` | ||
return error === undefined ? undefined : ''; | ||
@@ -77,3 +78,3 @@ } | ||
const execa = (file, args, options) => { | ||
export function execa(file, args, options) { | ||
const parsed = handleArguments(file, args, options); | ||
@@ -101,3 +102,3 @@ const command = joinCommand(file, args); | ||
isCanceled: false, | ||
killed: false | ||
killed: false, | ||
})); | ||
@@ -135,3 +136,3 @@ return mergePromise(dummySpawned, errorPromise); | ||
isCanceled: context.isCanceled, | ||
killed: spawned.killed | ||
killed: spawned.killed, | ||
}); | ||
@@ -156,3 +157,3 @@ | ||
isCanceled: false, | ||
killed: false | ||
killed: false, | ||
}; | ||
@@ -168,7 +169,5 @@ }; | ||
return mergePromise(spawned, handlePromiseOnce); | ||
}; | ||
} | ||
module.exports = execa; | ||
module.exports.sync = (file, args, options) => { | ||
export function execaSync(file, args, options) { | ||
const parsed = handleArguments(file, args, options); | ||
@@ -194,3 +193,3 @@ const command = joinCommand(file, args); | ||
isCanceled: false, | ||
killed: false | ||
killed: false, | ||
}); | ||
@@ -214,3 +213,3 @@ } | ||
isCanceled: false, | ||
killed: result.signal !== null | ||
killed: result.signal !== null, | ||
}); | ||
@@ -234,17 +233,17 @@ | ||
isCanceled: false, | ||
killed: false | ||
killed: false, | ||
}; | ||
}; | ||
} | ||
module.exports.command = (command, options) => { | ||
export function execaCommand(command, options) { | ||
const [file, ...args] = parseCommand(command); | ||
return execa(file, args, options); | ||
}; | ||
} | ||
module.exports.commandSync = (command, options) => { | ||
export function execaCommandSync(command, options) { | ||
const [file, ...args] = parseCommand(command); | ||
return execa.sync(file, args, options); | ||
}; | ||
return execaSync(file, args, options); | ||
} | ||
module.exports.node = (scriptPath, args, options = {}) => { | ||
export function execaNode(scriptPath, args, options = {}) { | ||
if (args && !Array.isArray(args) && typeof args === 'object') { | ||
@@ -255,3 +254,3 @@ options = args; | ||
const stdio = normalizeStdio.node(options); | ||
const stdio = normalizeStdioNode(options); | ||
const defaultExecArgv = process.execArgv.filter(arg => !arg.startsWith('--inspect')); | ||
@@ -261,3 +260,3 @@ | ||
nodePath = process.execPath, | ||
nodeOptions = defaultExecArgv | ||
nodeOptions = defaultExecArgv, | ||
} = options; | ||
@@ -270,3 +269,3 @@ | ||
scriptPath, | ||
...(Array.isArray(args) ? args : []) | ||
...(Array.isArray(args) ? args : []), | ||
], | ||
@@ -279,5 +278,5 @@ { | ||
stdio, | ||
shell: false | ||
} | ||
shell: false, | ||
}, | ||
); | ||
}; | ||
} |
@@ -1,2 +0,1 @@ | ||
'use strict'; | ||
const normalizeArgs = (file, args = []) => { | ||
@@ -21,14 +20,10 @@ if (!Array.isArray(args)) { | ||
const joinCommand = (file, args) => { | ||
return normalizeArgs(file, args).join(' '); | ||
}; | ||
export const joinCommand = (file, args) => normalizeArgs(file, args).join(' '); | ||
const getEscapedCommand = (file, args) => { | ||
return normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' '); | ||
}; | ||
export const getEscapedCommand = (file, args) => normalizeArgs(file, args).map(arg => escapeArg(arg)).join(' '); | ||
const SPACES_REGEXP = / +/g; | ||
// Handle `execa.command()` | ||
const parseCommand = command => { | ||
// Handle `execaCommand()` | ||
export const parseCommand = command => { | ||
const tokens = []; | ||
@@ -48,7 +43,1 @@ for (const token of command.trim().split(SPACES_REGEXP)) { | ||
}; | ||
module.exports = { | ||
joinCommand, | ||
getEscapedCommand, | ||
parseCommand | ||
}; |
@@ -1,3 +0,2 @@ | ||
'use strict'; | ||
const {signalsByName} = require('human-signals'); | ||
import {signalsByName} from 'human-signals'; | ||
@@ -28,3 +27,3 @@ const getErrorPrefix = ({timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled}) => { | ||
const makeError = ({ | ||
export const makeError = ({ | ||
stdout, | ||
@@ -41,3 +40,3 @@ stderr, | ||
killed, | ||
parsed: {options: {timeout}} | ||
parsed: {options: {timeout}}, | ||
}) => { | ||
@@ -89,3 +88,1 @@ // `signal` and `exitCode` emitted on `spawned.on('exit')` event can be `null`. | ||
}; | ||
module.exports = makeError; |
@@ -1,4 +0,3 @@ | ||
'use strict'; | ||
const os = require('os'); | ||
const onExit = require('signal-exit'); | ||
import os from 'node:os'; | ||
import onExit from 'signal-exit'; | ||
@@ -8,3 +7,3 @@ const DEFAULT_FORCE_KILL_TIMEOUT = 1000 * 5; | ||
// Monkey-patches `childProcess.kill()` to add `forceKillAfterTimeout` behavior | ||
const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => { | ||
export const spawnedKill = (kill, signal = 'SIGTERM', options = {}) => { | ||
const killResult = kill(signal); | ||
@@ -34,10 +33,6 @@ setKillTimeout(kill, signal, options, killResult); | ||
const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => { | ||
return isSigterm(signal) && forceKillAfterTimeout !== false && killResult; | ||
}; | ||
const shouldForceKill = (signal, {forceKillAfterTimeout}, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult; | ||
const isSigterm = signal => { | ||
return signal === os.constants.signals.SIGTERM || | ||
(typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM'); | ||
}; | ||
const isSigterm = signal => signal === os.constants.signals.SIGTERM | ||
|| (typeof signal === 'string' && signal.toUpperCase() === 'SIGTERM'); | ||
@@ -57,3 +52,3 @@ const getForceKillAfterTimeout = ({forceKillAfterTimeout = true}) => { | ||
// `childProcess.cancel()` | ||
const spawnedCancel = (spawned, context) => { | ||
export const spawnedCancel = (spawned, context) => { | ||
const killResult = spawned.kill(); | ||
@@ -72,3 +67,3 @@ | ||
// `timeout` option handling | ||
const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => { | ||
export const setupTimeout = (spawned, {timeout, killSignal = 'SIGTERM'}, spawnedPromise) => { | ||
if (timeout === 0 || timeout === undefined) { | ||
@@ -92,3 +87,3 @@ return spawnedPromise; | ||
const validateTimeout = ({timeout}) => { | ||
export const validateTimeout = ({timeout}) => { | ||
if (timeout !== undefined && (!Number.isFinite(timeout) || timeout < 0)) { | ||
@@ -100,3 +95,3 @@ throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`); | ||
// `cleanup` option handling | ||
const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => { | ||
export const setExitHandler = async (spawned, {cleanup, detached}, timedPromise) => { | ||
if (!cleanup || detached) { | ||
@@ -114,9 +109,1 @@ return timedPromise; | ||
}; | ||
module.exports = { | ||
spawnedKill, | ||
spawnedCancel, | ||
setupTimeout, | ||
validateTimeout, | ||
setExitHandler | ||
}; |
@@ -1,16 +0,14 @@ | ||
'use strict'; | ||
const nativePromisePrototype = (async () => {})().constructor.prototype; | ||
const descriptors = ['then', 'catch', 'finally'].map(property => [ | ||
property, | ||
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property) | ||
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property), | ||
]); | ||
// The return value is a mixin of `childProcess` and `Promise` | ||
const mergePromise = (spawned, promise) => { | ||
export const mergePromise = (spawned, promise) => { | ||
for (const [property, descriptor] of descriptors) { | ||
// Starting the main `promise` is deferred to avoid consuming streams | ||
const value = typeof promise === 'function' ? | ||
(...args) => Reflect.apply(descriptor.value, promise(), args) : | ||
descriptor.value.bind(promise); | ||
const value = typeof promise === 'function' | ||
? (...args) => Reflect.apply(descriptor.value, promise(), args) | ||
: descriptor.value.bind(promise); | ||
@@ -24,24 +22,16 @@ Reflect.defineProperty(spawned, property, {...descriptor, value}); | ||
// Use promises instead of `child_process` events | ||
const getSpawnedPromise = spawned => { | ||
return new Promise((resolve, reject) => { | ||
spawned.on('exit', (exitCode, signal) => { | ||
resolve({exitCode, signal}); | ||
}); | ||
export const getSpawnedPromise = spawned => new Promise((resolve, reject) => { | ||
spawned.on('exit', (exitCode, signal) => { | ||
resolve({exitCode, signal}); | ||
}); | ||
spawned.on('error', error => { | ||
spawned.on('error', error => { | ||
reject(error); | ||
}); | ||
if (spawned.stdin) { | ||
spawned.stdin.on('error', error => { | ||
reject(error); | ||
}); | ||
if (spawned.stdin) { | ||
spawned.stdin.on('error', error => { | ||
reject(error); | ||
}); | ||
} | ||
}); | ||
}; | ||
module.exports = { | ||
mergePromise, | ||
getSpawnedPromise | ||
}; | ||
} | ||
}); |
@@ -1,2 +0,1 @@ | ||
'use strict'; | ||
const aliases = ['stdin', 'stdout', 'stderr']; | ||
@@ -6,3 +5,3 @@ | ||
const normalizeStdio = options => { | ||
export const normalizeStdio = options => { | ||
if (!options) { | ||
@@ -34,6 +33,4 @@ return; | ||
module.exports = normalizeStdio; | ||
// `ipc` is pushed unless it is already present | ||
module.exports.node = options => { | ||
export const normalizeStdioNode = options => { | ||
const stdio = normalizeStdio(options); | ||
@@ -40,0 +37,0 @@ |
@@ -1,8 +0,7 @@ | ||
'use strict'; | ||
const isStream = require('is-stream'); | ||
const getStream = require('get-stream'); | ||
const mergeStream = require('merge-stream'); | ||
import {isStream} from 'is-stream'; | ||
import getStream from 'get-stream'; | ||
import mergeStream from 'merge-stream'; | ||
// `input` option | ||
const handleInput = (spawned, input) => { | ||
export const handleInput = (spawned, input) => { | ||
// Checking for stdin is workaround for https://github.com/nodejs/node/issues/26852 | ||
@@ -22,3 +21,3 @@ // @todo remove `|| spawned.stdin === undefined` once we drop support for Node.js <=12.2.0 | ||
// `all` interleaves `stdout` and `stderr` | ||
const makeAllStream = (spawned, {all}) => { | ||
export const makeAllStream = (spawned, {all}) => { | ||
if (!all || (!spawned.stdout && !spawned.stderr)) { | ||
@@ -69,3 +68,3 @@ return; | ||
// Retrieve result of child process: exit code, signal, error, streams (stdout/stderr/all) | ||
const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => { | ||
export const getSpawnedResult = async ({stdout, stderr, all}, {encoding, buffer, maxBuffer}, processDone) => { | ||
const stdoutPromise = getStreamPromise(stdout, {encoding, buffer, maxBuffer}); | ||
@@ -82,3 +81,3 @@ const stderrPromise = getStreamPromise(stderr, {encoding, buffer, maxBuffer}); | ||
getBufferedData(stderr, stderrPromise), | ||
getBufferedData(all, allPromise) | ||
getBufferedData(all, allPromise), | ||
]); | ||
@@ -88,3 +87,3 @@ } | ||
const validateInputSync = ({input}) => { | ||
export const validateInputSync = ({input}) => { | ||
if (isStream(input)) { | ||
@@ -94,9 +93,1 @@ throw new TypeError('The `input` option cannot be a stream in sync mode'); | ||
}; | ||
module.exports = { | ||
handleInput, | ||
makeAllStream, | ||
getSpawnedResult, | ||
validateInputSync | ||
}; | ||
{ | ||
"name": "execa", | ||
"version": "5.1.1", | ||
"version": "6.0.0", | ||
"description": "Process execution for humans", | ||
@@ -13,7 +13,9 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && nyc ava && tsd" | ||
"test": "xo && c8 ava && tsd" | ||
}, | ||
@@ -44,23 +46,23 @@ "files": [ | ||
"cross-spawn": "^7.0.3", | ||
"get-stream": "^6.0.0", | ||
"human-signals": "^2.1.0", | ||
"is-stream": "^2.0.0", | ||
"get-stream": "^6.0.1", | ||
"human-signals": "^3.0.1", | ||
"is-stream": "^3.0.0", | ||
"merge-stream": "^2.0.0", | ||
"npm-run-path": "^4.0.1", | ||
"onetime": "^5.1.2", | ||
"signal-exit": "^3.0.3", | ||
"strip-final-newline": "^2.0.0" | ||
"npm-run-path": "^5.0.1", | ||
"onetime": "^6.0.0", | ||
"signal-exit": "^3.0.5", | ||
"strip-final-newline": "^3.0.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.10", | ||
"ava": "^2.4.0", | ||
"get-node": "^11.0.1", | ||
"@types/node": "^16.11.7", | ||
"ava": "^3.15.0", | ||
"c8": "^7.10.0", | ||
"get-node": "^12.0.0", | ||
"is-running": "^2.1.0", | ||
"nyc": "^15.1.0", | ||
"p-event": "^4.2.0", | ||
"tempfile": "^3.0.0", | ||
"tsd": "^0.13.1", | ||
"xo": "^0.35.0" | ||
"p-event": "^5.0.1", | ||
"tempfile": "^4.0.0", | ||
"tsd": "^0.18.0", | ||
"xo": "^0.46.4" | ||
}, | ||
"nyc": { | ||
"c8": { | ||
"reporter": [ | ||
@@ -67,0 +69,0 @@ "text", |
141
readme.md
@@ -25,5 +25,5 @@ <img src="media/logo.svg" width="400"> | ||
```sh | ||
npm install execa | ||
``` | ||
$ npm install execa | ||
``` | ||
@@ -33,9 +33,7 @@ ## Usage | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
(async () => { | ||
const {stdout} = await execa('echo', ['unicorns']); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
})(); | ||
const {stdout} = await execa('echo', ['unicorns']); | ||
console.log(stdout); | ||
//=> 'unicorns' | ||
``` | ||
@@ -46,3 +44,3 @@ | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
@@ -55,34 +53,31 @@ execa('echo', ['unicorns']).stdout.pipe(process.stdout); | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
(async () => { | ||
// Catching an error | ||
try { | ||
await execa('unknown', ['command']); | ||
} catch (error) { | ||
console.log(error); | ||
/* | ||
{ | ||
message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', | ||
errno: -2, | ||
code: 'ENOENT', | ||
syscall: 'spawn unknown', | ||
path: 'unknown', | ||
spawnargs: ['command'], | ||
originalMessage: 'spawn unknown ENOENT', | ||
shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', | ||
command: 'unknown command', | ||
escapedCommand: 'unknown command', | ||
stdout: '', | ||
stderr: '', | ||
all: '', | ||
failed: true, | ||
timedOut: false, | ||
isCanceled: false, | ||
killed: false | ||
} | ||
*/ | ||
// Catching an error | ||
try { | ||
await execa('unknown', ['command']); | ||
} catch (error) { | ||
console.log(error); | ||
/* | ||
{ | ||
message: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', | ||
errno: -2, | ||
code: 'ENOENT', | ||
syscall: 'spawn unknown', | ||
path: 'unknown', | ||
spawnargs: ['command'], | ||
originalMessage: 'spawn unknown ENOENT', | ||
shortMessage: 'Command failed with ENOENT: unknown command spawn unknown ENOENT', | ||
command: 'unknown command', | ||
escapedCommand: 'unknown command', | ||
stdout: '', | ||
stderr: '', | ||
all: '', | ||
failed: true, | ||
timedOut: false, | ||
isCanceled: false, | ||
killed: false | ||
} | ||
})(); | ||
*/ | ||
} | ||
``` | ||
@@ -93,18 +88,16 @@ | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
(async () => { | ||
const subprocess = execa('node'); | ||
const subprocess = execa('node'); | ||
setTimeout(() => { | ||
subprocess.cancel(); | ||
}, 1000); | ||
setTimeout(() => { | ||
subprocess.cancel(); | ||
}, 1000); | ||
try { | ||
await subprocess; | ||
} catch (error) { | ||
console.log(subprocess.killed); // true | ||
console.log(error.isCanceled); // true | ||
} | ||
})() | ||
try { | ||
await subprocess; | ||
} catch (error) { | ||
console.log(subprocess.killed); // true | ||
console.log(error.isCanceled); // true | ||
} | ||
``` | ||
@@ -115,4 +108,6 @@ | ||
```js | ||
import {execaSync} from 'execa'; | ||
try { | ||
execa.sync('unknown', ['command']); | ||
execaSync('unknown', ['command']); | ||
} catch (error) { | ||
@@ -199,3 +194,3 @@ console.log(error); | ||
### execa.sync(file, arguments?, options?) | ||
### execaSync(file, arguments?, options?) | ||
@@ -206,5 +201,5 @@ Execute a file synchronously. | ||
### execa.command(command, options?) | ||
### execaCommand(command, options?) | ||
Same as [`execa()`](#execafile-arguments-options) except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execa.command('echo unicorns')`. | ||
Same as [`execa()`](#execafile-arguments-options) except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execaCommand('echo unicorns')`. | ||
@@ -215,9 +210,9 @@ If the file or an argument contains spaces, they must be escaped with backslashes. This matters especially if `command` is not a constant but a variable, for example with `__dirname` or `process.cwd()`. Except for spaces, no escaping/quoting is needed. | ||
### execa.commandSync(command, options?) | ||
### execaCommandSync(command, options?) | ||
Same as [`execa.command()`](#execacommand-command-options) but synchronous. | ||
Same as [`execaCommand()`](#execacommand-command-options) but synchronous. | ||
Returns or throws a [`childProcessResult`](#childProcessResult). | ||
### execa.node(scriptPath, arguments?, options?) | ||
### execaNode(scriptPath, arguments?, options?) | ||
@@ -250,3 +245,3 @@ Execute a Node.js script as a child process. | ||
This is not escaped and should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execa.command()`](#execacommandcommand-options). | ||
This is not escaped and should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options). | ||
@@ -260,3 +255,3 @@ #### escapedCommand | ||
This is meant to be copy and pasted into a shell, for debugging purposes. | ||
Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execa.command()`](#execacommandcommand-options). | ||
Since the escaping is fairly basic, this should not be executed directly as a process, including using [`execa()`](#execafile-arguments-options) or [`execaCommand()`](#execacommandcommand-options). | ||
@@ -289,3 +284,3 @@ #### exitCode | ||
- the [`all` option](#all-2) is `false` (the default value) | ||
- `execa.sync()` was used | ||
- `execaSync()` was used | ||
@@ -496,3 +491,3 @@ #### failed | ||
Specify the kind of serialization used for sending messages between processes when using the [`stdio: 'ipc'`](#stdio) option or [`execa.node()`](#execanodescriptpath-arguments-options): | ||
Specify the kind of serialization used for sending messages between processes when using the [`stdio: 'ipc'`](#stdio) option or [`execaNode()`](#execanodescriptpath-arguments-options): | ||
- `json`: Uses `JSON.stringify()` and `JSON.parse()`. | ||
@@ -598,3 +593,3 @@ - `advanced`: Uses [`v8.serialize()`](https://nodejs.org/api/v8.html#v8_v8_serialize_value) | ||
```js | ||
const pRetry = require('p-retry'); | ||
import pRetry from 'p-retry'; | ||
@@ -606,5 +601,3 @@ const run = async () => { | ||
(async () => { | ||
console.log(await pRetry(run, {retries: 5})); | ||
})(); | ||
console.log(await pRetry(run, {retries: 5})); | ||
``` | ||
@@ -617,3 +610,3 @@ | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
@@ -623,6 +616,4 @@ const subprocess = execa('echo', ['foo']); | ||
(async () => { | ||
const {stdout} = await subprocess; | ||
console.log('child output:', stdout); | ||
})(); | ||
const {stdout} = await subprocess; | ||
console.log('child output:', stdout); | ||
``` | ||
@@ -633,3 +624,3 @@ | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
@@ -643,3 +634,3 @@ const subprocess = execa('echo', ['foo']) | ||
```js | ||
const execa = require('execa'); | ||
import {execa} from 'execa'; | ||
@@ -653,3 +644,3 @@ const subprocess = execa('cat') | ||
```js | ||
const {getBinPathSync} = require('get-bin-path'); | ||
import {getBinPathSync} from 'get-bin-path'; | ||
@@ -656,0 +647,0 @@ const binPath = getBinPathSync(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
0
Yes
56711
972
655
+ Addedhuman-signals@3.0.1(transitive)
+ Addedis-stream@3.0.0(transitive)
+ Addedmimic-fn@4.0.0(transitive)
+ Addednpm-run-path@5.3.0(transitive)
+ Addedonetime@6.0.0(transitive)
+ Addedpath-key@4.0.0(transitive)
+ Addedstrip-final-newline@3.0.0(transitive)
- Removedhuman-signals@2.1.0(transitive)
- Removedis-stream@2.0.1(transitive)
- Removedmimic-fn@2.1.0(transitive)
- Removednpm-run-path@4.0.1(transitive)
- Removedonetime@5.1.2(transitive)
- Removedstrip-final-newline@2.0.0(transitive)
Updatedget-stream@^6.0.1
Updatedhuman-signals@^3.0.1
Updatedis-stream@^3.0.0
Updatednpm-run-path@^5.0.1
Updatedonetime@^6.0.0
Updatedsignal-exit@^3.0.5
Updatedstrip-final-newline@^3.0.0