Improve documentation of sync methods (#540)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 4993dcb · Browse files · 2 files·+37 added−27 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+37 added−27 removed
- other:+37 added−27 removed
Provenance
- Commit
1e23e91- Tree
088323d- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4993dcb
2 files changed+37 added−27 removed
modified:index.d.ts+19 added-9 removed
493 unmodified lines494 @param arguments - Arguments to pass to `file` on execution.495 @returns An `ExecaChildProcess` that is both:496 - a `Promise` resolving or rejecting with a `childProcessResult`.497 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.498+@throws A `childProcessResult` error499 500 @example501 ```502 import {execa} from 'execa';34 unmodified lines537 export function execa(file: string, options?: Options): ExecaChildProcess;538 export function execa(file: string, options?: Options<null>): ExecaChildProcess<Buffer>;539 540 /**540-Execute a file synchronously.541+Same as `execa()` but synchronous.542 542-This method throws an `Error` if the command fails.543-543 @param file - The program/script to execute.544 @param arguments - Arguments to pass to `file` on execution.546-@returns A result `Object` with `stdout` and `stderr` properties.545+@returns A `childProcessResult` object546+@throws A `childProcessResult` error547 */548 export function execaSync(549 file: string,550 arguments?: readonly string[],20 unmodified lines571 @param command - The program/script to execute and its arguments.572 @returns An `ExecaChildProcess` that is both:573 - a `Promise` resolving or rejecting with a `childProcessResult`.574 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.575+@throws A `childProcessResult` error576 577 @example578 ```579 import {execaCommand} from 'execa';25 unmodified lines605 606 @returns An `ExecaChildProcess` that is both:607 - a `Promise` resolving or rejecting with a `childProcessResult`.608 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.609+ @throws A `childProcessResult` error610 611 @example <caption>Basic</caption>612 ```613 import {$} from 'execa';56 unmodified lines670 ...expressions: TemplateExpression[]671 ): ExecaChildProcess<StdoutStderrType>;672 673 /**672- Same as `$` but synchronous like `execaSync()`.674+ Same as $\`command\` but synchronous.675 674- @returns The stdout and stderr output.676+ @returns A `childProcessResult` object677+ @throws A `childProcessResult` error678 679 @example680 ```681 import {$} from 'execa';20 unmodified lines702 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`.703 704 As a convenience, the result from previous `` $`command` `` or `` $.sync`command` `` calls can be used as template expressions in subsequent commands and `$`/`$.sync` will use the `stdout` value. See the example below `` with results from `$` or `$.sync` `` for more details.705 703-@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.706+@returns An `ExecaChildProcess` that is both:707+ - a `Promise` resolving or rejecting with a `childProcessResult`.708+ - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.709+@throws A `childProcessResult` error710 711 @example <caption>Basic</caption>712 ```713 import {$} from 'execa';53 unmodified lines767 /**768 Same as `execaCommand()` but synchronous.769 770 @param command - The program/script to execute and its arguments.765-@returns A result `Object` with `stdout` and `stderr` properties.771+@returns A `childProcessResult` object772+@throws A `childProcessResult` error773 */774 export function execaCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue;775 export function execaCommandSync(command: string, options?: SyncOptions<null>): ExecaSyncReturnValue<Buffer>;776 6 unmodified lines783 - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio)784 785 @param scriptPath - Node.js script to execute.786 @param arguments - Arguments to pass to `scriptPath` on execution.780-@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.787+@returns An `ExecaChildProcess` that is both:788+ - a `Promise` resolving or rejecting with a `childProcessResult`.789+ - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.790+@throws A `childProcessResult` error791 */792 export function execaNode(793 scriptPath: string,794 arguments?: readonly string[],9 unmodified linesmodified:readme.md+18 added-18 removed
277 unmodified lines278 No escaping/quoting is needed.279 280 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.281 282-### execaSync(file, arguments?, options?)283-284-Execute a file synchronously.285-286-Returns or throws a [`childProcessResult`](#childProcessResult).287-282 ### $\`command\`283 284 Same as [`execa()`](#execafile-arguments-options) (including its [return value](#childprocess)) except both file and arguments are specified in a single tagged template string. For example, `` $`echo unicorns` `` is the same as `execa('echo', ['unicorns'])`.285 4 unmodified lines290 As a convenience, the result from previous [`` $`command` ``](#command) or [`` $.sync`command` ``](#synccommand) calls can be used as template expressions in subsequent commands and `$`/`$.sync` will use the `stdout` value. See the example above [with results from `$` or `$.sync`](#with-results-from--or-sync) for more details.291 292 For more information, please see [this page](docs/scripts.md).293 300-### $.sync\`command\`301-302-Same as [$\`command\`](#command) but synchronous like [`execaSync()`](#execasyncfile-arguments-options).303-304-Returns or throws a [`childProcessResult`](#childProcessResult).305-294 ### $(options)295 296 Binds options to the [`$`](#command) API. For example, you can use `$(options)` to create a new `$` instance with specific default options, which are then bound to both the asynchronous [`` $`command` ``](#command) and synchronous [`` $.sync`command` ``](#synccommand) APIs.297 6 unmodified lines304 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.305 306 The [`shell` option](#shell) must be used if the `command` uses shell-specific features (for example, `&&` or `||`), as opposed to being a simple `file` followed by its `arguments`.307 320-### execaCommandSync(command, options?)321-322-Same as [`execaCommand()`](#execacommand-command-options) but synchronous.323-324-Returns or throws a [`childProcessResult`](#childProcessResult).325-308 ### execaNode(scriptPath, arguments?, options?)309 310 Execute a Node.js script as a child process.311 53 unmodified lines365 Combines both [`pipeStdout()`](#pipestdouttarget) and [`pipeStderr()`](#pipestderrtarget).366 367 Either the [`stdout` option](#stdout-1) or the [`stderr` option](#stderr-1) must be kept as `pipe`, their default value. Also, the [`all` option](#all-2) must be set to `true`.368 369+### execaSync(file, arguments?, options?)370+371+Same as [`execa()`](#execacommandcommand-options) but synchronous.372+373+Returns or throws a [`childProcessResult`](#childProcessResult).374+375+### $.sync\`command\`376+377+Same as [$\`command\`](#command) but synchronous.378+379+Returns or throws a [`childProcessResult`](#childProcessResult).380+381+### execaCommandSync(command, options?)382+383+Same as [`execaCommand()`](#execacommand-command-options) but synchronous.384+385+Returns or throws a [`childProcessResult`](#childProcessResult).386+387 ### childProcessResult388 389 Type: `object`390 421 unmodified lines