Skip to content
Myr

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

2 files+77 added−57 removed

modified:index.d.ts+23 added-15 removed
502 unmodified lines
503ExecaChildPromise<StdoutStderrType> &504Promise<ExecaReturnValue<StdoutStderrType>>;505506/**507Execute a file.507Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a `childProcess`.508509Think of this as a mix of `child_process.execFile` and `child_process.spawn`.509Arguments are automatically escaped. They can contain any character, including spaces.510511This is the preferred method when executing single commands.512513@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 lines
701 options?: SyncOptions<null>702): ExecaSyncReturnValue<Buffer>;703704/**703Same 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')`.705Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`.706705If 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.707Arguments are automatically escaped. They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.708707The `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`.709This is the preferred method when executing a user-supplied `command` string, such as in a REPL.710711@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 lines
753 | Array<string | number | ExecaReturnValue<string | Buffer> | ExecaSyncReturnValue<string | Buffer>>;754755type 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.758757 > **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` ``762763 @param options - Options to set764 @returns A new instance of `$` with those `options` set765
69 unmodified lines
835 ): ExecaSyncReturnValue<StdoutStderrType>;836};837838/**835Same 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'])`.839Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a `childProcess`.840837It'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.841Arguments are automatically escaped. They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``.842839The `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`.843This is the preferred method when executing multiple commands in a script file.844841As 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.845The `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.846847@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 lines
892893/**894Execute a Node.js script as a child process.895892Same 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)896Arguments are automatically escaped. They can contain any character, including spaces.897898This is the preferred method when executing Node.js files.899900Like [`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`904905@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 lines
modified:readme.md+54 added-42 removed
202 unmodified lines
203```204205## API206207### execa(file, arguments, options?)207### Methods208209Execute 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?)210211No escaping/quoting is needed.211Executes a command using `file ...arguments`. `arguments` are specified as an array of strings. Returns a [`childProcess`](#childprocess).212213Unless 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.213Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.214215### $\`command\`215This is the preferred method when executing single commands.216217Same 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?)218219It'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.219Executes a Node.js file using `node scriptPath ...arguments`. `arguments` are specified as an array of strings. Returns a [`childProcess`](#childprocess).220221The [`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`.221Arguments are [automatically escaped](#shell-syntax). They can contain any character, including spaces.222223As 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.223This is the preferred method when executing Node.js files.224225For more information, please see [this page](docs/scripts.md).225Like [`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)229227### $(options)230#### $\`command\`231229Binds 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.232Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess).233231> **Note:** Consecutive calls to this API will shallow merge the options.234Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must use `${}` like `` $`echo ${'has space'}` ``.235233### execaCommand(command, options?)236This is the preferred method when executing multiple commands in a script file.237235Same 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')`.238The `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.239237If 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.240For more information, please see [this section](#scripts-interface) and [this page](docs/scripts.md).241239The [`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)243241### execaNode(scriptPath, arguments?, options?)244Returns a new instance of [`$`](#command) but with different default `options`. Consecutive calls are merged to previous ones.245243Execute a Node.js script as a child process.246This can be used to either:247 - Set options for a specific command: `` $(options)`command` ``248 - Share options for multiple commands: `` const $$ = $(options); $$`command`; $$`otherCommand`; ``249245Same 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?)251252Executes a command. The `command` string includes both the `file` and its `arguments`. Returns a [`childProcess`](#childprocess).253254Arguments are [automatically escaped](#shell-syntax). They can contain any character, but spaces must be escaped with a backslash like `execaCommand('echo has\\ space')`.255256This is the preferred method when executing a user-supplied `command` string, such as in a REPL.257258### execaSync(file, arguments?, options?)259260Same as [`execa()`](#execacommandcommand-options) but synchronous.261262Returns or throws a [`childProcessResult`](#childProcessResult).263264### $.sync\`command\`265266Same as [$\`command\`](#command) but synchronous.267268Returns or throws a [`childProcessResult`](#childProcessResult).269270### execaCommandSync(command, options?)271272Same as [`execaCommand()`](#execacommand-command-options) but synchronous.273274Returns or throws a [`childProcessResult`](#childProcessResult).275276### Shell syntax277278For 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.279280### childProcess281252This is both:282The 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.285286#### kill(signal?, options?)
41 unmodified lines
328Combines both [`pipeStdout()`](#pipestdouttarget) and [`pipeStderr()`](#pipestderrtarget).329330Either 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`.331302### execaSync(file, arguments?, options?)303304Same as [`execa()`](#execacommandcommand-options) but synchronous.305306Returns or throws a [`childProcessResult`](#childProcessResult).307308### $.sync\`command\`309310Same as [$\`command\`](#command) but synchronous.311312Returns or throws a [`childProcessResult`](#childProcessResult).313314### execaCommandSync(command, options?)315316Same as [`execaCommand()`](#execacommand-command-options) but synchronous.317318Returns or throws a [`childProcessResult`](#childProcessResult).319332### childProcessResult333334Type: `object`335
451 unmodified lines