Skip to content
Myr

Improve the API section of the readme (#239)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by ehmicky · committed by Sindre Sorhus · parent 943f040 · Browse files · 2 files+84 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+84 added−16 removed

  • other:+84 added−16 removed

2 files+84 added−16 removed

modified:index.d.ts+2 added-4 removed
292 unmodified lines
293 onRejected?: (reason: ExecaError<StdoutErrorType>) => ResultType | PromiseLike<ResultType>294 ): Promise<ExecaReturnValue<StdoutErrorType> | ResultType>;295296 /**297 Cancel the subprocess.298299 Causes the promise to reject an error with a `.isCanceled = true` property, provided the process gets canceled. The process will not be canceled if it has already exited.297 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`.298 */299 cancel(): void;300 }301
57 unmodified lines
359 This method throws an `Error` if the command fails.360361 @param file - The program/script to execute.362 @param arguments - Arguments to pass to `file` on execution.365 @returns The same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).363 @returns A result `Object` with `stdout` and `stderr` properties.364 */365 sync(366 file: string,367 arguments?: readonly string[],
15 unmodified lines
modified:readme.md+82 added-12 removed
13 unmodified lines
14- [Improved Windows support.](https://github.com/IndigoUnited/node-cross-spawn#why)15- Higher max buffer. 10 MB instead of 200 KB.16- [Executes locally installed binaries by name.](#preferlocal)17- [Cleans up spawned processes when the parent process dies.](#cleanup)18- [Get interleaved output](#execafile-arguments-options) from `stdout` and `stderr` similar to what is printed on the terminal. [*(Async only)*](#execasyncfile-arguments-options)18- [Get interleaved output](#all) from `stdout` and `stderr` similar to what is printed on the terminal. [*(Async only)*](#execasyncfile-arguments-options)19- [Can specify command and arguments as a single string without a shell](#execafile-arguments-options)20- More descriptive errors.2122
88 unmodified lines
111112### execa(file, [arguments], [options])113### execa(command, [options])114115Execute a file.115Execute a file. Think of this as a mix of [`child_process.execFile()`](https://nodejs.org/api/child_process.html#child_process_child_process_execfile_file_args_options_callback) and [`child_process.spawn()`](https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options).116117Arguments can be specified in either:118 - `arguments`: `execa('echo', ['unicorns'])`.119 - `command`: `execa('echo unicorns')`.120121Arguments should not be escaped nor quoted. Exception: inside `command`, spaces can be escaped with a backslash.121Arguments should not be escaped nor quoted, except inside `command` where spaces can be escaped with a backslash.122123Think of this as a mix of `child_process.execFile` and `child_process.spawn`.124123Unless the [`shell`](#shell) option is used, no shell interpreter (Bash, `cmd.exe`, etc.) is used, so shell features such as variables substitution (`echo $PATH`) are not allowed.124127Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) which is enhanced to be a `Promise`.125Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) which:126 - is also a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult).127 - exposes the following additional methods and properties.128129It exposes an additional `.all` stream, with `stdout` and `stderr` interleaved.129#### cancel()130131The spawned process can be canceled with the `.cancel()` method on the promise, which causes the promise to reject an error with a `.isCanceled = true` property, provided the process gets canceled. The process will not be canceled if it has already exited.131Similar 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`.132133The promise result is an `Object` with `stdout`, `stderr` and `all` properties.133#### all134135Stream 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).136137### execa.sync(file, [arguments], [options])138### execa.sync(command, [options])139140Execute a file synchronously.141140Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).142Returns or throws a [`childProcessResult`](#childProcessResult).143142It does not have the `.all` property that `execa()` has because the [underlying synchronous implementation](https://nodejs.org/api/child_process.html#child_process_child_process_execfilesync_file_args_options) only returns `stdout` and `stderr` at the end of the execution, so they cannot be interleaved.144### childProcessResult145144This method throws an `Error` if the command fails.146Type: `object`147148Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.149150#### exitCode151152Type: `number`153154The numeric exit code of the process that was run.155156#### exitCodeName157158Type: `string`159160The textual exit code of the process that was run.161162#### stdout163164Type: `string | Buffer`165166The output of the process on stdout.167168#### stderr169170Type: `string | Buffer`171172The output of the process on stderr.173174#### all175176Type: `string | Buffer`177178The output of the process on both stdout and stderr. `undefined` if `execa.sync()` was used.179180#### command181182Type: `string`183184The command that was run.185186#### failed187188Type: `boolean`189190Whether the process failed to run.191192#### timedOut193194Type: `boolean`195196Whether the process timed out.197198#### killed199200Type: `boolean`201202Whether the process was killed.203204#### isCanceled205206Type: `boolean`207208Whether the process was canceled.209210#### signal211212Type: `string | undefined`213214The signal that was used to terminate the process.215216### options217218Type: `object`219
197 unmodified lines