feat: add shell completions - #4840
Conversation
🦋 Changeset detectedLatest commit: 67bd238 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
This PR is packaged and the instant preview is available (f145401). Install it locally:
npm i -D webpack-cli@https://pkg.pr.new/webpack-cli@f145401
yarn add -D webpack-cli@https://pkg.pr.new/webpack-cli@f145401
pnpm add -D webpack-cli@https://pkg.pr.new/webpack-cli@f145401 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4840 +/- ##
==========================================
+ Coverage 94.78% 94.81% +0.03%
==========================================
Files 14 14
Lines 5406 5598 +192
Branches 799 837 +38
==========================================
+ Hits 5124 5308 +184
- Misses 281 289 +8
Partials 1 1
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
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 <amirhosseinpr184@gmail.com>
095d282 to
df97606
Compare
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 <amirhosseinpr184@gmail.com>
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 <amirhosseinpr184@gmail.com>
`@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.
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 <amirhosseinpr184@gmail.com>
Summary
Builds on @AmirSa12's #4829 (their commit is kept as-is, first in this branch) and fixes the two things that stood between it and covering every command. Closes #1402.
@bomb.sh/tabregisters each command undercommand.name()and has no alias concept, so completing after one returned only the global options:webpack b <TAB>offered 4 candidates againstbuild's 21,webpack s <TAB>4 againstserve's 94. The alias being completed is now registered against the command it stands for. Only the requested alias is registered, sowebpack <TAB>still lists the eight commands instead of all thirteen names — flip that if you would rather aliases were discoverable.@bomb.sh/tabmoves fromdependenciesto an optional peer, alongsidewebpack-dev-server,webpack-bundle-analyzer,js-yaml,json5andtoml. It is imported only to serve a completion request. A shell runscomplete -- <words>on every keypress, so a missing package is silent there (exit 0, nothing on either stream), whilecomplete <shell>reports what to install in the usual format.Also updates the dev-server 6 help snapshots, added after #4829 branched — without them its CI fails on every dev-server 6 job.
Not covered, and inherent rather than an oversight: third-party commands, which the CLI resolves by
import(commandName)as a package, so there is no set to enumerate before one is typed.What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes —
test/complete/complete.test.jsgains three cases on top of #4829's six: an alias offers byte-identical candidates to its command, values complete through an alias (b --mode=), and aliases stay out of the command suggestions. Measured before and after across all commands:build/watchb,bundle,wserves,serverThe missing-package paths were checked by hand (both streams empty for a resolution request; exit 2 with the install message for
complete zsh) since simulating an absent package inside the suite is not worth the machinery.Does this PR introduce a breaking change?
No — a new command, and the parser it needs is optional.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
Installing completions per shell:
webpack complete zsh(and bash/fish/powershell) prints the script to source, and@bomb.sh/tabhas to be installed to use it.Use of AI
Claude Code was used to review #4829 by running its CLI, which is how the alias gap was measured, to read
@bomb.sh/tab's adapter and find that it keys commands by name, and to write the fix and its tests. All changes were reviewed before committing.Generated by Claude Code