You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit f145401
Browse filesBrowse the repository at this point in the historyBrowse files
* feat: add tab completions
* fix(complete): resolve command aliases and make the parser optional
Completing after an alias returned only the global options, because
`@bomb.sh/tab` registers each command under `command.name()` and has no
alias concept: `webpack b <TAB>` offered 4 candidates where `webpack build
<TAB>` offers 25, and `webpack s <TAB>` 4 against `serve`'s 98. The alias
being completed is now registered against the command it stands for, so
every alias resolves. Only the requested one is registered, which keeps
`webpack <TAB>` listing the eight commands rather than all thirteen names.
Global options are registered on the root command, so nothing offered them
after a command, though they are accepted there: `webpack build --col` did
not complete `--color`, and `configtest`, `help` and `complete` offered
nothing at all, having no options of their own. Every command now carries
them.
`@bomb.sh/tab` also moves to an optional peer dependency, next to the other
packages the CLI loads on demand. It is imported only to serve a completion
request, so installing it is the user's choice: the shell runs
`complete -- <words>` on every keypress and now gets silence when the
package is absent, while `complete <shell>` says what to install.
Also updates the dev-server 6 help snapshots, which were added after this
work branched.
Co-authored-by: AmirSa12 <[email protected]>
* fix(complete): keep a partial command expanding to its full name
Registering the requested alias made it a suggestion of its own, so
`webpack b<TAB>` offered `build` and `b` and the shell, having two
candidates, left the word at their common prefix instead of writing
`build` out. The last word is the one being typed, so only the words
before it name the command an alias has to resolve.
Co-authored-by: AmirSa12 <[email protected]>
* test(complete): cover the option-value handlers
Patch coverage reported 30 uncovered lines, most of them handler bodies
that only run while the option they belong to is being completed. Covers
`build --progress`, `version --output`, the root `--help`, and the shell
argument of `complete` itself.
Co-authored-by: AmirSa12 <[email protected]>
* test(complete): cover the missing-parser paths
`@bomb.sh/tab` is optional, so the two paths that run without it carry the
behaviour a user without it sees, and both were checked by hand only. A
resolve hook now hides the package the way an install that never had it
does, pinning that a completion request prints nothing on either stream and
that asking for a script reports what to install.
* docs: describe shell completion
Covers what completes, that `@bomb.sh/tab` has to be installed for it, and
the line to add per shell. Also lists `complete` among the commands in both
readmes, the second of which quotes `--help` and so has to match it.
Co-authored-by: AmirSa12 <[email protected]>
---------
Co-authored-by: AmirSa12 <[email protected]>
Copy file name to clipboardExpand all lines: README.md
+37Lines changed: 37 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -26,6 +26,7 @@
26
26
-[Packages](#packages)
27
27
-[Commands](#commands)
28
28
-[Getting started](#getting-started)
29
+
-[Shell completion](#shell-completion)
29
30
-[Exit codes and their meanings](#exit-codes-and-their-meanings)
30
31
-[Contributing and Internal Documentation](#contributing-and-internal-documentation)
31
32
-[Funding](#funding)
@@ -58,6 +59,7 @@ Supporting developers is an important task for webpack CLI.
58
59
Thus, webpack CLI provides different commands for many common tasks.
59
60
60
61
-[`build|bundle|b [entries...] [options]`](https://webpack.js.org/api/cli/#build) - Run webpack (default command, can be omitted).
62
+
-`complete [shell]` - Print a shell completion script, see [Shell completion](#shell-completion).
61
63
-[`configtest|t [config-path]`](https://webpack.js.org/api/cli/#configtest) - Validate a webpack configuration.
62
64
-[`help|h [command] [option]`](https://webpack.js.org/api/cli/#help) - Display help for commands and options.
63
65
-[`info|i [options]`](https://webpack.js.org/api/cli/#info) - Returns information related to the local environment.
@@ -79,6 +81,41 @@ npx create-webpack-app init
79
81
80
82
You will then be prompted for some questions about which features you want to use, such as `scss`, `typescript`, `PWA` support or other features.
81
83
84
+
## Shell completion
85
+
86
+
Commands, their options and the values those options accept can be completed in `zsh`, `bash`, `fish` and `powershell`. The completions are read from webpack's own schema, so they cover whatever your webpack and `webpack-dev-server` versions support.
87
+
88
+
Completion is served by [`@bomb.sh/tab`](https://www.npmjs.com/package/@bomb.sh/tab), which is optional and not installed with `webpack-cli`:
89
+
90
+
```sh
91
+
npm install --save-dev @bomb.sh/tab
92
+
```
93
+
94
+
Then load the script for your shell:
95
+
96
+
```sh
97
+
# zsh
98
+
echo'source <(webpack complete zsh)'>>~/.zshrc
99
+
100
+
# bash
101
+
echo'source <(webpack complete bash)'>>~/.bashrc
102
+
103
+
# fish
104
+
webpack complete fish >~/.config/fish/completions/webpack.fish
0 commit comments