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
Provenance
- Commit
0d39fdf- Tree
ba87d6b- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
Sindre Sorhus <sindresorhus@gmail.com>- Parent
943f040
2 files changed+84 added−16 removed
modified:index.d.ts+2 added-4 removed
292 unmodified lines293 onRejected?: (reason: ExecaError<StdoutErrorType>) => ResultType | PromiseLike<ResultType>294 ): Promise<ExecaReturnValue<StdoutErrorType> | ResultType>;295 296 /**297- Cancel the subprocess.298-299- 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 lines359 This method throws an `Error` if the command fails.360 361 @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 linesmodified:readme.md+82 added-12 removed
13 unmodified lines14 - [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.21 22 88 unmodified lines111 112 ### execa(file, [arguments], [options])113 ### execa(command, [options])114 115-Execute a file.115+Execute 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).116 117 Arguments can be specified in either:118 - `arguments`: `execa('echo', ['unicorns'])`.119 - `command`: `execa('echo unicorns')`.120 121-Arguments should not be escaped nor quoted. Exception: inside `command`, spaces can be escaped with a backslash.121+Arguments should not be escaped nor quoted, except inside `command` where spaces can be escaped with a backslash.122 123-Think of this as a mix of `child_process.execFile` and `child_process.spawn`.124-123 Unless 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.124 127-Returns a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) which is enhanced to be a `Promise`.125+Returns 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.128 129-It exposes an additional `.all` stream, with `stdout` and `stderr` interleaved.129+#### cancel()130 131-The 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.131+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`.132 133-The promise result is an `Object` with `stdout`, `stderr` and `all` properties.133+#### all134 135+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).136+137 ### execa.sync(file, [arguments], [options])138 ### execa.sync(command, [options])139 140 Execute a file synchronously.141 140-Returns the same result object as [`child_process.spawnSync`](https://nodejs.org/api/child_process.html#child_process_child_process_spawnsync_command_args_options).142+Returns or throws a [`childProcessResult`](#childProcessResult).143 142-It 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+### childProcessResult145 144-This method throws an `Error` if the command fails.146+Type: `object`147 148+Result of a child process execution. On success this is a plain object. On failure this is also an `Error` instance.149+150+#### exitCode151+152+Type: `number`153+154+The numeric exit code of the process that was run.155+156+#### exitCodeName157+158+Type: `string`159+160+The textual exit code of the process that was run.161+162+#### stdout163+164+Type: `string | Buffer`165+166+The output of the process on stdout.167+168+#### stderr169+170+Type: `string | Buffer`171+172+The output of the process on stderr.173+174+#### all175+176+Type: `string | Buffer`177+178+The output of the process on both stdout and stderr. `undefined` if `execa.sync()` was used.179+180+#### command181+182+Type: `string`183+184+The command that was run.185+186+#### failed187+188+Type: `boolean`189+190+Whether the process failed to run.191+192+#### timedOut193+194+Type: `boolean`195+196+Whether the process timed out.197+198+#### killed199+200+Type: `boolean`201+202+Whether the process was killed.203+204+#### isCanceled205+206+Type: `boolean`207+208+Whether the process was canceled.209+210+#### signal211+212+Type: `string | undefined`213+214+The signal that was used to terminate the process.215+216 ### options217 218 Type: `object`219 197 unmodified lines