Improve main method documentation (#545)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by ehmicky · committed by GitHub · parent 72443f3 · Browse files · 2 files·+77 added−57 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+77 added−57 removed
- other:+77 added−57 removed
Provenance
- Commit
db2ad9a- Tree
d1e7e3c- Author
ehmicky <ehmicky@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
72443f3
2 files changed+77 added−57 removed
modified:index.d.ts+23 added-15 removed
502 unmodified lines503 ExecaChildPromise<StdoutStderrType> &504 Promise<ExecaReturnValue<StdoutStderrType>>;505 506 /**507-Execute a file.507+Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a `childProcess`.508 509-Think of this as a mix of `child_process.execFile` and `child_process.spawn`.509+Arguments are automatically escaped. They can contain any character, including spaces.510 511+This is the preferred method when executing single commands.512+513 @param file - The program/script to execute.514 @param arguments - Arguments to pass to `file` on execution.515 @returns An `ExecaChildProcess` that is both:516 - a `Promise` resolving or rejecting with a `childProcessResult`.184 unmodified lines701 options?: SyncOptions<null>702 ): ExecaSyncReturnValue<Buffer>;703 704 /**703-Same as `execa()` (including its return value) except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execaCommand('echo unicorns')`.705+Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`.706 705-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.707+Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.708 707-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`.709+This is the preferred method when executing a user-supplied `command` string, such as in a REPL.710 711 @param command - The program/script to execute and its arguments.712 @returns An `ExecaChildProcess` that is both:713 - a `Promise` resolving or rejecting with a `childProcessResult`.39 unmodified lines753 | Array<string | number | ExecaReturnValue<string | Buffer> | ExecaSyncReturnValue<string | Buffer>>;754 755 type Execa$<StdoutStderrType extends StdoutStderrAll = string> = {756 /**755- Binds options to the `$` 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` `` and synchronous `` $.sync`command` `` APIs.757+ Returns a new instance of `$` but with different default `options`. Consecutive calls are merged to previous ones.758 757- > **Note:** Consecutive calls to this API will shallow merge the options.759+ This can be used to either:760+ - Set options for a specific command: `` $(options)`command` ``761+ - Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand` ``762 763 @param options - Options to set764 @returns A new instance of `$` with those `options` set765 69 unmodified lines835 ): ExecaSyncReturnValue<StdoutStderrType>;836 };837 838 /**835-Same as `execa()` except both file and arguments are specified in a single tagged template string. For example, `` $`echo unicorns` `` is the same as `execa('echo', ['unicorns'])`.839+Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`.840 837-It's important to note that quotes, backslashes, and spaces are automatically escaped and have no special meaning unless the `shell` option is used. This escaping behavior also applies to interpolated expressions such as strings (`` $`echo ${'string'}` ``), arrays of strings (`` $`echo ${['array', 'of strings']}` ``), and so on.841+Arguments are automatically escaped. They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``.842 839-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`.843+This is the preferred method when executing multiple commands in a script file.844 841-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.845+The `command` string can inject any `${value}` with the following types: string, number, `childProcess` or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${childProcess}`, the process's `stdout` is used.846 847 @returns An `ExecaChildProcess` that is both:848 - a `Promise` resolving or rejecting with a `childProcessResult`.849 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with some additional methods and properties.42 unmodified lines892 893 /**894 Execute a Node.js script as a child process.895 892-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)):893- - the current Node version and options are used. This can be overridden using the `nodePath` and `nodeArguments` options.894- - the `shell` option cannot be used895- - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio)896+Arguments are automatically escaped. They can contain any character, including spaces.897 898+This is the preferred method when executing Node.js files.899+900+Like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options):901+ - the current Node version and options are used. This can be overridden using the `nodePath` and `nodeOptions` options.902+ - the `shell` option cannot be used903+ - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to `stdio`904+905 @param scriptPath - Node.js script to execute.906 @param arguments - Arguments to pass to `scriptPath` on execution.907 @returns An `ExecaChildProcess` that is both:908 - a `Promise` resolving or rejecting with a `childProcessResult`.22 unmodified linesmodified:readme.md+54 added-42 removed
202 unmodified lines203 ```204 205 ## API206 207-### execa(file, arguments, options?)207+### Methods208 209-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). This returns a [`childProcess`](#childprocess).209+#### execa(file, arguments?, options?)210 211-No escaping/quoting is needed.211+Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a [`childProcess`](#childprocess).212 213-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.213+Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.214 215-### $\`command\`215+This is the preferred method when executing single commands.216 217-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'])`.217+#### execaNode(scriptPath, arguments?, options?)218 219-It's important to note that quotes, backslashes, and spaces are automatically escaped and have no special meaning unless the [`shell` option](#shell) is used. This escaping behavior also applies to interpolated expressions such as strings (`` $`echo ${'string'}` ``), arrays of strings (`` $`echo ${['array', 'of strings']}` ``), and so on.219+Executes a Node.js file using `node scriptPath ...arguments`. `arguments` are specified as an array of strings. Returns a [`childProcess`](#childprocess).220 221-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`.221+Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.222 223-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.223+This is the preferred method when executing Node.js files.224 225-For more information, please see [this page](docs/scripts.md).225+Like [`child_process#fork()`](https://nodejs.org/api/child_process.html#child_process_child_process_fork_modulepath_args_options):226+ - the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeOptions`](#nodeoptions-for-node-only) options.227+ - the [`shell`](#shell) option cannot be used228+ - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio)229 227-### $(options)230+#### $\`command\`231 229-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.232+Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess).233 231-> **Note:** Consecutive calls to this API will shallow merge the options.234+Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``.235 233-### execaCommand(command, options?)236+This is the preferred method when executing multiple commands in a script file.237 235-Same as [`execa()`](#execafile-arguments-options) (including its [return value](#childprocess)) except both file and arguments are specified in a single `command` string. For example, `execa('echo', ['unicorns'])` is the same as `execaCommand('echo unicorns')`.238+The `command` string can inject any `${value}` with the following types: string, number, [`childProcess`](#childprocess) or an array of those types. For example: `` $`echo one ${'two'} ${3} ${['four', 'five']}` ``. For `${childProcess}`, the process's `stdout` is used.239 237-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.240+For more information, please see [this section](#scripts-interface) and [this page](docs/scripts.md).241 239-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`.242+#### $(options)243 241-### execaNode(scriptPath, arguments?, options?)244+Returns a new instance of [`$`](#command) but with different default `options`. Consecutive calls are merged to previous ones.245 243-Execute a Node.js script as a child process.246+This can be used to either:247+ - Set options for a specific command: `` $(options)`command` ``248+ - Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand`; ``249 245-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)):246- - the current Node version and options are used. This can be overridden using the [`nodePath`](#nodepath-for-node-only) and [`nodeOptions`](#nodeoptions-for-node-only) options.247- - the [`shell`](#shell) option cannot be used248- - an extra channel [`ipc`](https://nodejs.org/api/child_process.html#child_process_options_stdio) is passed to [`stdio`](#stdio)250+#### execaCommand(command, options?)251 252+Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess).253+254+Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.255+256+This is the preferred method when executing a user-supplied `command` string, such as in a REPL.257+258+### execaSync(file, arguments?, options?)259+260+Same as [`execa()`](#execacommandcommand-options) but synchronous.261+262+Returns or throws a [`childProcessResult`](#childProcessResult).263+264+### $.sync\`command\`265+266+Same as [$\`command\`](#command) but synchronous.267+268+Returns or throws a [`childProcessResult`](#childProcessResult).269+270+### execaCommandSync(command, options?)271+272+Same as [`execaCommand()`](#execacommand-command-options) but synchronous.273+274+Returns or throws a [`childProcessResult`](#childProcessResult).275+276+### Shell syntax277+278+For all the [methods above](#methods), no shell interpreter (Bash, cmd.exe, etc.) is used unless the [`shell` option](#shell) is set. This means shell-specific characters and expressions (`$variable`, `&&`, `||`, `;`, `|`, etc.) have no special meaning and do not need to be escaped.279+280 ### childProcess281 252-This is both:282+The return value of all [asynchronous methods](#methods) is both:283 - a `Promise` resolving or rejecting with a [`childProcessResult`](#childProcessResult).284 - a [`child_process` instance](https://nodejs.org/api/child_process.html#child_process_class_childprocess) with the following additional methods and properties.285 286 #### kill(signal?, options?)41 unmodified lines328 Combines both [`pipeStdout()`](#pipestdouttarget) and [`pipeStderr()`](#pipestderrtarget).329 330 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`.331 302-### execaSync(file, arguments?, options?)303-304-Same as [`execa()`](#execacommandcommand-options) but synchronous.305-306-Returns or throws a [`childProcessResult`](#childProcessResult).307-308-### $.sync\`command\`309-310-Same as [$\`command\`](#command) but synchronous.311-312-Returns or throws a [`childProcessResult`](#childProcessResult).313-314-### execaCommandSync(command, options?)315-316-Same as [`execaCommand()`](#execacommand-command-options) but synchronous.317-318-Returns or throws a [`childProcessResult`](#childProcessResult).319-332 ### childProcessResult333 334 Type: `object`335 451 unmodified lines