From f145401192f5212e459478a554d2f1c7d3c6c3b0 Mon Sep 17 00:00:00 2001 From: Alexander Akait <4567934+alexander-akait@users.noreply.github.com> Date: Fri, 28 Aug 2026 16:54:40 +0300 Subject: [PATCH 01/35] feat: add shell completions (#4840) * 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 ` offered 4 candidates where `webpack build ` offers 25, and `webpack s ` 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 ` 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 -- ` on every keypress and now gets silence when the package is absent, while `complete ` says what to install. Also updates the dev-server 6 help snapshots, which were added after this work branched. Co-authored-by: AmirSa12 * 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` 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 * 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 * 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 --------- Co-authored-by: AmirSa12 --- .changeset/tab-completions.md | 5 + .cspell.json | 3 +- README.md | 37 +++ package-lock.json | 35 ++- package.json | 1 + packages/webpack-cli/README.md | 1 + packages/webpack-cli/package.json | 4 + packages/webpack-cli/src/webpack-cli.ts | 202 +++++++++++++++- test/complete/complete.test.js | 223 ++++++++++++++++++ test/complete/no-completion-parser.mjs | 18 ++ .../help.test.js.snap.devServer5.webpack5 | 7 + .../help.test.js.snap.devServer6.webpack5 | 7 + 12 files changed, 535 insertions(+), 8 deletions(-) create mode 100644 .changeset/tab-completions.md create mode 100644 test/complete/complete.test.js create mode 100644 test/complete/no-completion-parser.mjs diff --git a/.changeset/tab-completions.md b/.changeset/tab-completions.md new file mode 100644 index 00000000000..a02d23abd15 --- /dev/null +++ b/.changeset/tab-completions.md @@ -0,0 +1,5 @@ +--- +"webpack-cli": minor +--- + +feat: add shell completions for zsh, bash, fish and powershell through the `complete` command diff --git a/.cspell.json b/.cspell.json index c79593fbea6..565018f91da 100644 --- a/.cspell.json +++ b/.cspell.json @@ -106,7 +106,8 @@ "Zenitsu", "quickstart", "pinia", - "watchpack" + "watchpack", + "zsh" ], "dictionaries": ["npm", "software-terms"], "ignorePaths": [ diff --git a/README.md b/README.md index 0885c87a284..0c50d6efbcb 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ - [Packages](#packages) - [Commands](#commands) - [Getting started](#getting-started) +- [Shell completion](#shell-completion) - [Exit codes and their meanings](#exit-codes-and-their-meanings) - [Contributing and Internal Documentation](#contributing-and-internal-documentation) - [Funding](#funding) @@ -58,6 +59,7 @@ Supporting developers is an important task for webpack CLI. Thus, webpack CLI provides different commands for many common tasks. - [`build|bundle|b [entries...] [options]`](https://webpack.js.org/api/cli/#build) - Run webpack (default command, can be omitted). +- `complete [shell]` - Print a shell completion script, see [Shell completion](#shell-completion). - [`configtest|t [config-path]`](https://webpack.js.org/api/cli/#configtest) - Validate a webpack configuration. - [`help|h [command] [option]`](https://webpack.js.org/api/cli/#help) - Display help for commands and options. - [`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 You will then be prompted for some questions about which features you want to use, such as `scss`, `typescript`, `PWA` support or other features. +## Shell completion + +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. + +Completion is served by [`@bomb.sh/tab`](https://www.npmjs.com/package/@bomb.sh/tab), which is optional and not installed with `webpack-cli`: + +```sh +npm install --save-dev @bomb.sh/tab +``` + +Then load the script for your shell: + +```sh +# zsh +echo 'source <(webpack complete zsh)' >> ~/.zshrc + +# bash +echo 'source <(webpack complete bash)' >> ~/.bashrc + +# fish +webpack complete fish > ~/.config/fish/completions/webpack.fish + +# powershell +webpack complete powershell > ~/.webpack-completion.ps1 +echo '. ~/.webpack-completion.ps1' >> $PROFILE +``` + +Once the shell is restarted, `Tab` completes commands, their aliases, options and option values: + +```sh +webpack b # webpack build +webpack build --mode= # development, production, none +webpack serve --his # webpack serve --history-api-fallback +``` + ## Exit codes and their meanings | Exit Code | Description | diff --git a/package-lock.json b/package-lock.json index 3d9eeff34e8..8ddebfa27b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@babel/core": "^8.0.1", "@babel/preset-env": "^8.0.2", "@babel/register": "^8.0.1", + "@bomb.sh/tab": "^0.0.22", "@changesets/cli": "^3.0.1", "@changesets/get-github-info": "^1.0.0", "@swc/core": "^1.16.1", @@ -1557,6 +1558,32 @@ "node": ">=18" } }, + "node_modules/@bomb.sh/tab": { + "version": "0.0.22", + "resolved": "https://registry.npmjs.org/@bomb.sh/tab/-/tab-0.0.22.tgz", + "integrity": "sha512-l5IuWpV7szqG4MM6A7I+qPMmP2qPMq2TD4veIXaOH0sD53dV0Tv8WZPARp5O5Kp4+y4fnVCl3VL1HZKNghO1yg==", + "devOptional": true, + "license": "MIT", + "bin": { + "tab": "dist/bin/cli.mjs" + }, + "peerDependencies": { + "cac": "^6.7.14 || ^7.0.0", + "citty": "^0.1.6 || ^0.2.0", + "commander": "^13.1.0 || ^14.0.0 || ^15.0.0" + }, + "peerDependenciesMeta": { + "cac": { + "optional": true + }, + "citty": { + "optional": true + }, + "commander": { + "optional": true + } + } + }, "node_modules/@changesets/apply-release-plan": { "version": "8.0.0", "resolved": "https://registry.npmjs.org/@changesets/apply-release-plan/-/apply-release-plan-8.0.0.tgz", @@ -21268,7 +21295,7 @@ } }, "packages/create-webpack-app": { - "version": "2.1.0", + "version": "2.2.0", "license": "MIT", "dependencies": { "@inquirer/expand": "^5.1.3", @@ -21304,7 +21331,7 @@ } }, "packages/webpack-cli": { - "version": "7.2.2", + "version": "7.2.3", "license": "MIT", "dependencies": { "@discoveryjs/json-ext": "^1.1.0", @@ -21330,6 +21357,7 @@ "url": "https://opencollective.com/webpack" }, "peerDependencies": { + "@bomb.sh/tab": "^0.0.22", "js-yaml": "^4.0.0 || ^5.0.0", "json5": "^2.2.3", "toml": "^3.0.0 || ^4.0.0 || ^5.0.0", @@ -21338,6 +21366,9 @@ "webpack-dev-server": "^5.0.0 || ^6.0.0" }, "peerDependenciesMeta": { + "@bomb.sh/tab": { + "optional": true + }, "js-yaml": { "optional": true }, diff --git a/package.json b/package.json index b51ce36f861..3d515e67e01 100644 --- a/package.json +++ b/package.json @@ -48,6 +48,7 @@ "prepare": "husky" }, "devDependencies": { + "@bomb.sh/tab": "^0.0.22", "@babel/core": "^8.0.1", "@babel/preset-env": "^8.0.2", "@babel/register": "^8.0.1", diff --git a/packages/webpack-cli/README.md b/packages/webpack-cli/README.md index b32696c8224..064f9def5c4 100644 --- a/packages/webpack-cli/README.md +++ b/packages/webpack-cli/README.md @@ -64,6 +64,7 @@ npx webpack-cli --help verbose ``` build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. diff --git a/packages/webpack-cli/package.json b/packages/webpack-cli/package.json index ad6dba55219..457588ec62a 100644 --- a/packages/webpack-cli/package.json +++ b/packages/webpack-cli/package.json @@ -44,6 +44,7 @@ "@types/envinfo": "^7.8.4" }, "peerDependencies": { + "@bomb.sh/tab": "^0.0.22", "js-yaml": "^4.0.0 || ^5.0.0", "json5": "^2.2.3", "toml": "^3.0.0 || ^4.0.0 || ^5.0.0", @@ -52,6 +53,9 @@ "webpack-dev-server": "^5.0.0 || ^6.0.0" }, "peerDependenciesMeta": { + "@bomb.sh/tab": { + "optional": true + }, "js-yaml": { "optional": true }, diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index f43b06b0879..8a324a51054 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -4,6 +4,7 @@ import path from "node:path"; import { type Readable as ReadableType } from "node:stream"; import { fileURLToPath, pathToFileURL } from "node:url"; import util from "node:util"; +import { type RootCommand } from "@bomb.sh/tab"; import { type stringifyChunked as stringifyChunkedType } from "@discoveryjs/json-ext"; import { type Command as CommanderCommand, @@ -40,6 +41,7 @@ const WEBPACK_DEV_SERVER_PACKAGE_IS_CUSTOM = Boolean(process.env.WEBPACK_DEV_SER const WEBPACK_DEV_SERVER_PACKAGE = WEBPACK_DEV_SERVER_PACKAGE_IS_CUSTOM ? (process.env.WEBPACK_DEV_SERVER_PACKAGE as string) : "webpack-dev-server"; +const COMPLETION_PACKAGE = "@bomb.sh/tab"; // `webpack-dev-server` v6 is ESM and exposes the server as its `default` export, // while v5 exports it directly @@ -157,6 +159,7 @@ interface KnownWebpackCLICommands { help: CommandOptions; info: CommandOptions; configtest: CommandOptions; + complete: CommandOptions; } // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -585,6 +588,12 @@ class WebpackCLI { return str.length > 0 ? str.charAt(0).toUpperCase() + str.slice(1) : str; } + #commandTerm(command: CommanderCommand): string { + const aliases = command.aliases().filter(Boolean); + + return aliases.length > 0 ? `${command.name()}|${aliases.join("|")}` : command.name(); + } + toKebabCase(str: string): string { return str.replaceAll(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase(); } @@ -1432,14 +1441,12 @@ class WebpackCLI { return `${parentCmdNames}${command.usage()} | ${parentCmdNames}[command] [options]`; } - return `${parentCmdNames}${command.name()}|${command - .aliases() - .join("|")} ${command.usage()}`; + return `${parentCmdNames}${this.#commandTerm(command)} ${command.usage()}`; }, // Support multiple aliases subcommandTerm: (command) => { const usage = command.usage(); - return `${command.name()}|${command.aliases().join("|")}${usage.length > 0 ? ` ${usage}` : ""}`; + return `${this.#commandTerm(command)}${usage.length > 0 ? ` ${usage}` : ""}`; }, visibleOptions: function visibleOptions(command) { return command.options.filter((option) => { @@ -2445,6 +2452,16 @@ class WebpackCLI { ); }, }, + complete: { + rawName: "complete", + name: "complete [shell]", + alias: [], + description: "Generate shell completion scripts.", + action: () => { + // Display-only stub for `--help`. Completion requests are handled in `run()` + // before parse so the completion adapter can inspect the loaded command tree. + }, + }, }; #isCommand( @@ -2489,6 +2506,8 @@ class WebpackCLI { return await this.makeCommand(this.#commands.info); } else if (this.#isCommand(commandName, this.#commands.configtest)) { return await this.makeCommand(this.#commands.configtest); + } else if (this.#isCommand(commandName, this.#commands.complete)) { + return await this.makeCommand(this.#commands.complete); } const pkg: string = commandName; @@ -2527,7 +2546,174 @@ class WebpackCLI { return externalCommand; } - async run(args: readonly string[], parseOptions: ParseOptions) { + #completionRequest( + args: readonly string[], + parseOptions?: ParseOptions, + ): { words: string[] } | undefined { + const userArgs = parseOptions?.from === "user" ? args : args.slice(2); + + if (userArgs.find((arg) => arg !== "--" && !arg.startsWith("-")) !== "complete") { + return; + } + + // `complete -- ` asks what to suggest for ``; `complete ` + // only prints a script and has no words to resolve. + const separator = userArgs.indexOf("--"); + + return { words: separator === -1 ? [] : userArgs.slice(separator + 1) }; + } + + async #prepareCompletions(words: string[]): Promise { + // Register every option (same as `--help`) so tab can inspect the full tree. + this.program.forHelp = true; + + await Promise.all( + Object.values(this.#commands) + .filter((command) => command.rawName !== "complete") + .map((command) => this.#loadCommandByName(command.rawName)), + ); + + let tab: typeof import("@bomb.sh/tab/commander").default; + + try { + ({ default: tab } = await import("@bomb.sh/tab/commander")); + } catch (error) { + if ((error as NodeJS.ErrnoException).code !== "ERR_MODULE_NOT_FOUND") { + throw error; + } + + // The shell runs `complete -- ` on every keypress, so a missing + // optional package stays silent there and only reports when asked for a script. + if (words.length === 0) { + this.logger.error( + `For using '${this.colors.green("complete")}' command you need to install: '${this.colors.green(COMPLETION_PACKAGE)}' package.`, + ); + process.exit(2); + } + + process.exit(0); + } + + this.#attachCompletionHandlers(tab(this.program), words); + } + + #attachCompletionHandlers(completion: RootCommand, words: string[]): void { + const helpOption = completion.options.get("help"); + + if (helpOption) { + helpOption.handler = (complete) => { + complete("verbose", "Show all available commands and options"); + }; + } + + const outputHandler = (complete: (value: string, description: string) => void) => { + complete("json", "JSON output"); + complete("markdown", "Markdown output"); + }; + + for (const name of ["info", "version"]) { + const outputOption = completion.commands.get(name)?.options.get("output"); + + if (outputOption) { + outputOption.handler = outputHandler; + } + } + + const progressHandler = (complete: (value: string, description: string) => void) => { + complete("profile", "Capture profiling data"); + }; + + for (const name of ["build", "watch", "serve"]) { + const progressOption = completion.commands.get(name)?.options.get("progress"); + + if (progressOption) { + progressOption.handler = progressHandler; + } + } + + const completeCommand = completion.commands.get("complete"); + const shellArg = completeCommand?.arguments.get("shell"); + + if (shellArg) { + shellArg.handler = (complete) => { + complete("zsh", "Zsh"); + complete("bash", "Bash"); + complete("fish", "Fish"); + complete("powershell", "PowerShell"); + }; + } + + // The command already typed, e.g. `b` in `complete -- b --mode=`. The last word + // is still being written — `complete -- b` is completing `b` itself, which must + // stay a prefix of `build` so the shell expands it instead of matching an alias. + const requested = words.slice(0, -1).find((word) => word !== "--" && !word.startsWith("-")); + + for (const command of this.program.commands) { + const tabCommand = completion.commands.get(command.name()); + + if (!tabCommand) { + continue; + } + + // Commands are registered under their name, so an alias resolves to nothing. + // Only the requested one is registered, to keep aliases out of the suggestions. + if (requested && requested !== command.name() && command.aliases().includes(requested)) { + completion.commands.set(requested, tabCommand); + } + + // Global options stay on the root command, yet they are accepted after a + // command too, so offer them there as well (e.g. `webpack build --col`). + for (const [name, option] of completion.options) { + if (!tabCommand.options.has(name)) { + tabCommand.options.set(name, option); + } + } + + for (const option of command.options) { + const longName = option.long?.slice(2); + + if (!longName) { + continue; + } + + const { configs } = option as Option & { configs?: ArgumentConfig[] }; + + if (!configs) { + continue; + } + + const values: string[] = []; + + for (const config of configs) { + if (config.type !== "enum" || !config.values) { + continue; + } + + for (const value of config.values) { + if (typeof value === "string") { + values.push(value); + } + } + } + + if (values.length === 0) { + continue; + } + + const tabOption = tabCommand.options.get(longName); + + if (tabOption) { + tabOption.handler = (complete) => { + for (const value of values) { + complete(value, ""); + } + }; + } + } + } + } + + async run(args: readonly string[], parseOptions?: ParseOptions) { // Default `--color` and `--no-color` options const self: WebpackCLI = this; @@ -2735,6 +2921,12 @@ class WebpackCLI { await command.parseAsync([...commandOperands, ...unknown], { from: "user" }); }); + const completionRequest = this.#completionRequest(args, parseOptions); + + if (completionRequest) { + await this.#prepareCompletions(completionRequest.words); + } + await this.program.parseAsync(args, parseOptions); } diff --git a/test/complete/complete.test.js b/test/complete/complete.test.js new file mode 100644 index 00000000000..457982ee7ca --- /dev/null +++ b/test/complete/complete.test.js @@ -0,0 +1,223 @@ +"use strict"; + +const path = require("node:path"); +const { pathToFileURL } = require("node:url"); +const { run } = require("../utils/test-utils"); + +// Hides `@bomb.sh/tab` from the CLI, the way a project that never installed the +// optional package sees it. +const withoutParser = { + nodeOptions: [ + `--import=${pathToFileURL(path.resolve(__dirname, "no-completion-parser.mjs")).href}`, + ], +}; + +const parseCompletions = (stdout) => + stdout + .split("\n") + .map((line) => line.trimEnd()) + .filter((line) => line && !line.startsWith(":")) + .map((line) => line.split("\t")[0]); + +describe("complete", () => { + it("should generate a zsh completion script", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "zsh"]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(stdout).toContain("webpack"); + expect(stdout).toContain("complete"); + }); + + it("should generate a bash completion script", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "bash"]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(stdout).toContain("webpack"); + }); + + it("should suggest commands", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", ""]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + + const suggestions = parseCompletions(stdout); + + expect(suggestions).toEqual(expect.arrayContaining(["build", "watch", "serve", "info"])); + }); + + it("should suggest option values for --mode", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "complete", + "--", + "build", + "--mode=", + ]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + + const suggestions = parseCompletions(stdout); + + expect(suggestions).toEqual(expect.arrayContaining(["development", "production", "none"])); + }); + + it("should suggest option values for info --output", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "complete", + "--", + "info", + "--output=", + ]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + + const suggestions = parseCompletions(stdout); + + expect(suggestions).toEqual(expect.arrayContaining(["json", "markdown"])); + }); + + it("should expand a partial command to a single suggestion", async () => { + // `webpack b` has to offer `build` alone, so the shell writes it out; + // suggesting the alias `b` next to it would leave the word as typed. + for (const [typed, command] of [ + ["b", "build"], + ["w", "watch"], + ["s", "serve"], + ["i", "info"], + ]) { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", typed]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual([command]); + } + }); + + it("should suggest the same options for a command alias", async () => { + const { stdout: canonical } = await run(__dirname, ["complete", "--", "build", "--"]); + + for (const alias of ["b", "bundle"]) { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", alias, "--"]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual(parseCompletions(canonical)); + } + }); + + it("should suggest option values for a command alias", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", "b", "--mode="]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual( + expect.arrayContaining(["development", "production", "none"]), + ); + }); + + it("should stay silent for a completion request without the parser", async () => { + const { exitCode, stderr, stdout } = await run( + __dirname, + ["complete", "--", "build", "--"], + withoutParser, + ); + + // A shell asks for this on every keypress, so it must print nothing at all. + expect(exitCode).toBe(0); + expect(stdout).toBeFalsy(); + expect(stderr).toBeFalsy(); + }); + + it("should ask to install the parser when generating a script", async () => { + const { exitCode, stderr } = await run(__dirname, ["complete", "zsh"], withoutParser); + + expect(exitCode).toBe(2); + expect(stderr).toContain("@bomb.sh/tab"); + }); + + it("should suggest option values for build --progress", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "complete", + "--", + "build", + "--progress=", + ]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual(expect.arrayContaining(["profile"])); + }); + + it("should suggest option values for version --output", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, [ + "complete", + "--", + "version", + "--output=", + ]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual(expect.arrayContaining(["json", "markdown"])); + }); + + it("should suggest option values for --help", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", "--help="]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual(expect.arrayContaining(["verbose"])); + }); + + it("should suggest shells for the complete command", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", "complete", ""]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual( + expect.arrayContaining(["zsh", "bash", "fish", "powershell"]), + ); + }); + + it("should suggest global options after a command", async () => { + for (const command of ["build", "serve", "help"]) { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", command, "--"]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + expect(parseCompletions(stdout)).toEqual( + expect.arrayContaining(["--color", "--no-color", "--help"]), + ); + } + }); + + it("should not suggest aliases as commands", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", ""]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + + const suggestions = parseCompletions(stdout); + + expect(suggestions).toEqual(expect.arrayContaining(["build", "watch", "serve"])); + + for (const alias of ["b", "bundle", "w", "s", "server"]) { + expect(suggestions).not.toContain(alias); + } + }); + + it("should suggest flags for the build command", async () => { + const { exitCode, stderr, stdout } = await run(__dirname, ["complete", "--", "build", "--"]); + + expect(exitCode).toBe(0); + expect(stderr).toBeFalsy(); + + const suggestions = parseCompletions(stdout); + + expect(suggestions).toEqual(expect.arrayContaining(["--mode", "--config", "--entry"])); + }); +}); diff --git a/test/complete/no-completion-parser.mjs b/test/complete/no-completion-parser.mjs new file mode 100644 index 00000000000..1bf55e94ff9 --- /dev/null +++ b/test/complete/no-completion-parser.mjs @@ -0,0 +1,18 @@ +// Makes `@bomb.sh/tab` unresolvable, so the CLI takes its missing-package path. +import { register } from "node:module"; + +register( + `data:text/javascript,${encodeURIComponent(` + export async function resolve(specifier, context, nextResolve) { + if (specifier.startsWith("@bomb.sh/tab")) { + const error = new Error("Cannot find package '" + specifier + "'"); + + error.code = "ERR_MODULE_NOT_FOUND"; + + throw error; + } + + return nextResolve(specifier, context); + } + `)}`, +); diff --git a/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 index 46552514d82..e64cdf6d4b0 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer5.webpack5 @@ -134,6 +134,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -193,6 +194,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -252,6 +254,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -2643,6 +2646,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -2732,6 +2736,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -3089,6 +3094,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -3146,6 +3152,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. diff --git a/test/help/__snapshots__/help.test.js.snap.devServer6.webpack5 b/test/help/__snapshots__/help.test.js.snap.devServer6.webpack5 index 5d230226777..72507ea3f5c 100644 --- a/test/help/__snapshots__/help.test.js.snap.devServer6.webpack5 +++ b/test/help/__snapshots__/help.test.js.snap.devServer6.webpack5 @@ -134,6 +134,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -193,6 +194,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -252,6 +254,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -2643,6 +2646,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -2732,6 +2736,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -3089,6 +3094,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. @@ -3146,6 +3152,7 @@ Global options Commands ──────────────────────────────────────────────────────────────────────── build|bundle|b [entries...] [options] Run webpack (default command, can be omitted). + complete [shell] Generate shell completion scripts. configtest|t [config-path] Validate a webpack configuration. help|h [command] [option] Display help for commands and options. info|i [options] Outputs information about your system. From 29a73f0bca737ce98e3591ca0695b87840b86496 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:09:16 +0000 Subject: [PATCH 02/35] chore(deps): bump changesets/action in the dependencies group (#4843) Bumps the dependencies group with 1 update: [changesets/action](https://github.com/changesets/action). Updates `changesets/action` from 2.1.0 to 2.1.1 - [Release notes](https://github.com/changesets/action/releases) - [Changelog](https://github.com/changesets/action/blob/main/CHANGELOG.md) - [Commits](https://github.com/changesets/action/compare/198f833dd7d863100ea6e28967bc9a9fdefadb0a...8488615a623b1b9c987934bb89eae8af6a946ac1) --- updated-dependencies: - dependency-name: changesets/action dependency-version: 2.1.1 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: dependencies ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a9f13eeb5e4..51ddf1a5d07 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -32,7 +32,7 @@ jobs: - name: Create Release Pull Request or Publish to npm id: changesets - uses: changesets/action@198f833dd7d863100ea6e28967bc9a9fdefadb0a # v2.1.0 + uses: changesets/action@8488615a623b1b9c987934bb89eae8af6a946ac1 # v2.1.1 with: version-script: npm run version publish-script: npm run release From 6e6dd45e5efa58b827326d8ab0725d7a5b30b653 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 30 Aug 2026 01:41:50 +0000 Subject: [PATCH 03/35] docs: update (#4844) Co-authored-by: alexander-akait <4567934+alexander-akait@users.noreply.github.com> --- OPTIONS.md | 631 ++++++++++++++++++++++++++++++++++++++++++-- SERVE-OPTIONS-v6.md | 119 +++++++++ 2 files changed, 734 insertions(+), 16 deletions(-) create mode 100644 SERVE-OPTIONS-v6.md diff --git a/OPTIONS.md b/OPTIONS.md index 341b0d5ad71..34dfa73e833 100644 --- a/OPTIONS.md +++ b/OPTIONS.md @@ -72,7 +72,7 @@ Options --dotenv-template-reset Clear all items provided in 'dotenv.template' configuration. Template patterns for .env file names. Use [mode] as placeholder for the webpack mode. Defaults to ['.env', '.env.local', '.env.[mode]', '.env.[mode].local']. --entry A module that is loaded upon startup. Only the last one is exported. --entry-reset Clear all items provided in 'entry' configuration. All modules are loaded upon startup. The last one is exported. - --experiments-async-web-assembly Support WebAssembly as asynchronous EcmaScript Module. + --experiments-async-web-assembly [value] Enable the built-in async WebAssembly support only when no loader is registered for WebAssembly files. Enable/disable the built-in async WebAssembly support. --no-experiments-async-web-assembly Negative 'experiments-async-web-assembly' option. --experiments-back-compat Enable backward-compat layer with deprecation warnings for many webpack 4 APIs. --no-experiments-back-compat Negative 'experiments-back-compat' option. @@ -88,13 +88,13 @@ Options --no-experiments-build-http-upgrade Negative 'experiments-build-http-upgrade' option. --experiments-cache-unaffected Enable additional in memory caching of modules that are unchanged and reference only unchanged modules. --no-experiments-cache-unaffected Negative 'experiments-cache-unaffected' option. - --experiments-css Enable css support. + --experiments-css [value] Enable the built-in CSS support only when no loader is registered for CSS files. Enable/disable the built-in CSS support. --no-experiments-css Negative 'experiments-css' option. --experiments-defer-import Enable experimental tc39 proposal https://github.com/tc39/proposal-defer-import-eval. This allows to defer execution of a module until it's first use. --no-experiments-defer-import Negative 'experiments-defer-import' option. --experiments-future-defaults Apply defaults of next major version. --no-experiments-future-defaults Negative 'experiments-future-defaults' option. - --experiments-html Enable HTML entry support. Treats `.html` files as a first-class module type so they can be used directly as entry points. + --experiments-html [value] Enable the built-in HTML support only when no loader is registered for HTML files. Enable/disable the built-in HTML support. --no-experiments-html Negative 'experiments-html' option. --experiments-lazy-compilation Compile entrypoints and import()s only when they are accessed. --no-experiments-lazy-compilation Negative 'experiments-lazy-compilation' option. @@ -114,7 +114,7 @@ Options --no-experiments-source-import Negative 'experiments-source-import' option. --experiments-sync-web-assembly Support WebAssembly as synchronous EcmaScript Module (outdated). --no-experiments-sync-web-assembly Negative 'experiments-sync-web-assembly' option. - --experiments-typescript Enable typescript support. + --experiments-typescript [value] Enable the built-in TypeScript support only when Node.js supports it (>= 22.6) and no loader is registered for TypeScript files. Enable/disable the built-in TypeScript support. --no-experiments-typescript Negative 'experiments-typescript' option. -e, --extends Path to the configuration to be extended (only works when using webpack-cli). --extends-reset Clear all items provided in 'extends' configuration. Extend configuration from another configuration (only works when using webpack-cli). @@ -134,6 +134,10 @@ Options --no-externals-presets-electron-renderer Negative 'externals-presets-electron-renderer' option. --externals-presets-node Treat node.js built-in modules like fs, path or vm as external and load them via require() when used. --no-externals-presets-node Negative 'externals-presets-node' option. + --externals-presets-node-modules Enable or disable externalizing installed packages. + --no-externals-presets-node-modules Negative 'externals-presets-node-modules' option. + --externals-presets-node-modules-allowlist Requests matching the RegExp stay bundled. An exact request that should stay bundled. + --externals-presets-node-modules-allowlist-reset Clear all items provided in 'externalsPresets.nodeModules.allowlist' configuration. Keep these requests bundled instead of externalizing them. --externals-presets-nwjs Treat NW.js legacy nw.gui module as external and load it via require() when used. --no-externals-presets-nwjs Negative 'externals-presets-nwjs' option. --externals-presets-web Treat references to 'http(s)://...' and 'std:...' as external and load them via import when used (Note that this changes execution order as externals are executed before any other code in the chunk). @@ -154,6 +158,8 @@ Options --no-infrastructure-logging-debug Negative 'infrastructure-logging-debug' option. --infrastructure-logging-debug-reset Clear all items provided in 'infrastructureLogging.debug' configuration. Enable debug logging for specific loggers. --infrastructure-logging-level Log level. + --infrastructure-logging-progress [value] Show build progress. `"auto"` shows it only for interactive terminals. This option is only used when no custom console is provided. + --no-infrastructure-logging-progress Negative 'infrastructure-logging-progress' option. --mode Enable production optimizations or development hints. --module-expr-context-critical Enable warnings for full dynamic dependencies. --no-module-expr-context-critical Negative 'module-expr-context-critical' option. @@ -229,13 +235,41 @@ Options --module-no-parse-reset Clear all items provided in 'module.noParse' configuration. Don't parse files matching. It's matched against the full resolved request. --module-parser-asset-data-url-condition-max-size Maximum size of asset that should be inline as modules. Default: 8kb. --module-parser-css-as Configure how the CSS source is parsed: as a full stylesheet (default) or as a block's contents (e.g. the content of an HTML `style` attribute). + --module-parser-css-custom-media Enable/disable resolution of `@custom-media` at-rules (file-local build-time substitution). + --no-module-parser-css-custom-media Negative 'module-parser-css-custom-media' option. + --module-parser-css-custom-selectors Enable/disable resolution of `@custom-selector` at-rules (file-local build-time expansion to `:is(...)`). + --no-module-parser-css-custom-selectors Negative 'module-parser-css-custom-selectors' option. --module-parser-css-export-type Configure how CSS content is exported as default. + --module-parser-css-font-preload Auto-emit `` for the primary `src` URL of each `@font-face` reachable from an HTML entry's initial CSS. Only the first URL per `@font-face` is preloaded (preloading every format would double-download). Off by default; `parser.css.urlHints` rules and per-URL magic comments still override the seeded defaults. Set `output.crossOriginLoading` so the preload matches the font's CORS fetch. + --no-module-parser-css-font-preload Negative 'module-parser-css-font-preload' option. --module-parser-css-import Enable/disable `@import` at-rules handling. --no-module-parser-css-import Negative 'module-parser-css-import' option. --module-parser-css-named-exports Use ES modules named export for css exports. --no-module-parser-css-named-exports Negative 'module-parser-css-named-exports' option. --module-parser-css-url Enable/disable `url()`/`image-set()`/`src()`/`image()` functions handling. --no-module-parser-css-url Negative 'module-parser-css-url' option. + --module-parser-css-url-hints-as Default `as` attribute (script / style / font / image / …). + --module-parser-css-url-hints-exclude One default-hint rule for URL-referenced assets emitted by this parser (JS `new URL(...)`, CSS `url(...)`, HTML `` / `` / `