Skip to content

Commit c4cb62a

Browse files
authored
Improve documentation for windowsVerbatimArguments (#1149)
1 parent 0a51f7c commit c4cb62a

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

docs/api.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ _Default:_ `true` if the [`shell`](#optionsshell) option is `true`, `false` othe
11701170

11711171
If `false`, escapes the command arguments on Windows.
11721172

1173-
[More info.](windows.md#cmdexe-escaping)
1173+
[More info.](windows.md#escaping)
11741174

11751175
## Verbose function
11761176

docs/windows.md

+25-3
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,33 @@ The default value for the [`stdin`](api.md#optionsstdin), [`stdout`](api.md#opti
3434

3535
Instead of `'pipe'`, `'overlapped'` can be used instead to use [asynchronous I/O](https://learn.microsoft.com/en-us/windows/win32/fileio/synchronous-and-asynchronous-i-o) under-the-hood on Windows, instead of the default behavior which is synchronous. On other platforms, asynchronous I/O is always used, so `'overlapped'` behaves the same way as `'pipe'`.
3636

37-
## `cmd.exe` escaping
37+
## Escaping
3838

39-
If the [`windowsVerbatimArguments`](api.md#optionswindowsverbatimarguments) option is `false`, the [command arguments](input.md#command-arguments) are automatically escaped on Windows. When using a [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) [shell](api.md#optionsshell), this is `true` by default instead.
39+
Windows requires files and arguments to be quoted when they contain spaces, tabs, backslashes or double quotes. Unlike Unix, this is needed even when no [shell](shell.md) is used.
4040

41-
This is ignored on other platforms: those are [automatically escaped](escaping.md) by default.
41+
When not using any shell, Execa performs that quoting automatically. This ensures files and arguments are split correctly.
42+
43+
```js
44+
await execa`npm run ${'task with space'}`;
45+
```
46+
47+
When using a [shell](shell.md), the user must manually perform shell-specific quoting, on both Unix and Windows. When the [`shell`](api.md#optionsshell) option is `true`, [`cmd.exe`](https://en.wikipedia.org/wiki/Cmd.exe) is used on Windows and `sh` on Unix. Unfortunately, both shells use different quoting rules. With `cmd.exe`, this mostly involves double quoting arguments and prepending double quotes with a backslash.
48+
49+
```js
50+
if (isWindows) {
51+
await execa({shell: true})`npm run ${'"task with space"'}`;
52+
} else {
53+
await execa({shell: true})`npm run ${'\'task with space\''}`;
54+
}
55+
```
56+
57+
When using other Windows shells (such as PowerShell or WSL), Execa performs `cmd.exe`-specific automatic quoting by default. This is a problem since Powershell uses different quoting rules. This can be disabled using the [`windowsVerbatimArguments: true`](api.md#optionswindowsverbatimarguments) option.
58+
59+
```js
60+
if (isWindows) {
61+
await execa({windowsVerbatimArguments: true})`wsl ...`;
62+
}
63+
```
4264

4365
## Console window
4466

0 commit comments

Comments
 (0)