Skip to content
Myr

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

2 files+37 added−27 removed

modified:index.d.ts+19 added-9 removed
493 unmodified lines
494@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` error499500@example501```502import {execa} from 'execa';
34 unmodified lines
537export function execa(file: string, options?: Options): ExecaChildProcess;538export function execa(file: string, options?: Options<null>): ExecaChildProcess<Buffer>;539540/**540Execute a file synchronously.541Same as `execa()` but synchronous.542542This method throws an `Error` if the command fails.543543@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*/548export function execaSync(549 file: string,550 arguments?: readonly string[],
20 unmodified lines
571@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` error576577@example578```579import {execaCommand} from 'execa';
25 unmodified lines
605606 @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` error610611 @example <caption>Basic</caption>612 ```613 import {$} from 'execa';
56 unmodified lines
670 ...expressions: TemplateExpression[]671 ): ExecaChildProcess<StdoutStderrType>;672673 /**672 Same as `$` but synchronous like `execaSync()`.674 Same as $\`command\` but synchronous.675674 @returns The stdout and stderr output.676 @returns A `childProcessResult` object677 @throws A `childProcessResult` error678679 @example680 ```681 import {$} from 'execa';
20 unmodified lines
702The `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`.703704As 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.705703@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` error710711@example <caption>Basic</caption>712```713import {$} from 'execa';
53 unmodified lines
767/**768Same as `execaCommand()` but synchronous.769770@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*/774export function execaCommandSync(command: string, options?: SyncOptions): ExecaSyncReturnValue;775export function execaCommandSync(command: string, options?: SyncOptions<null>): ExecaSyncReturnValue<Buffer>;776
6 unmodified lines
783 - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio)784785@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*/792export function execaNode(793 scriptPath: string,794 arguments?: readonly string[],
9 unmodified lines
modified:readme.md+18 added-18 removed
277 unmodified lines
278No escaping/quoting is needed.279280Unless 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.281282### execaSync(file, arguments?, options?)283284Execute a file synchronously.285286Returns or throws a [`childProcessResult`](#childProcessResult).287282### $\`command\`283284Same 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 lines
290As 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.291292For more information, please see [this page](docs/scripts.md).293300### $.sync\`command\`301302Same as [$\`command\`](#command) but synchronous like [`execaSync()`](#execasyncfile-arguments-options).303304Returns or throws a [`childProcessResult`](#childProcessResult).305294### $(options)295296Binds 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 lines
304If 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.305306The [`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`.307320### execaCommandSync(command, options?)321322Same as [`execaCommand()`](#execacommand-command-options) but synchronous.323324Returns or throws a [`childProcessResult`](#childProcessResult).325308### execaNode(scriptPath, arguments?, options?)309310Execute a Node.js script as a child process.311
53 unmodified lines
365Combines both [`pipeStdout()`](#pipestdouttarget) and [`pipeStderr()`](#pipestderrtarget).366367Either 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`.368369### execaSync(file, arguments?, options?)370371Same as [`execa()`](#execacommandcommand-options) but synchronous.372373Returns or throws a [`childProcessResult`](#childProcessResult).374375### $.sync\`command\`376377Same as [$\`command\`](#command) but synchronous.378379Returns or throws a [`childProcessResult`](#childProcessResult).380381### execaCommandSync(command, options?)382383Same as [`execaCommand()`](#execacommand-command-options) but synchronous.384385Returns or throws a [`childProcessResult`](#childProcessResult).386387### childProcessResult388389Type: `object`390
421 unmodified lines