From 6621c023ab59cc510a5f76e262f2c81676d1920b Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Wed, 26 Oct 2022 14:15:45 +0530 Subject: [PATCH] feat: update commander to v9 (#3460) --- packages/webpack-cli/package.json | 2 +- packages/webpack-cli/src/types.ts | 4 ++-- packages/webpack-cli/src/webpack-cli.ts | 12 +++++++++--- test/api/CLI.test.js | 2 +- yarn.lock | 9 ++------- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/webpack-cli/package.json b/packages/webpack-cli/package.json index ef6261b256c..4e53352a9b2 100644 --- a/packages/webpack-cli/package.json +++ b/packages/webpack-cli/package.json @@ -39,7 +39,7 @@ "@webpack-cli/info": "^1.5.0", "@webpack-cli/serve": "^1.7.0", "colorette": "^2.0.14", - "commander": "^7.0.0", + "commander": "^9.4.1", "cross-spawn": "^7.0.3", "envinfo": "^7.7.3", "fastest-levenshtein": "^1.0.12", diff --git a/packages/webpack-cli/src/types.ts b/packages/webpack-cli/src/types.ts index 2afbaa471e5..b51d7e0485d 100644 --- a/packages/webpack-cli/src/types.ts +++ b/packages/webpack-cli/src/types.ts @@ -19,7 +19,7 @@ import webpack, { import { ClientConfiguration, Configuration as DevServerConfig } from "webpack-dev-server"; import { Colorette } from "colorette"; -import { Command, CommandOptions, OptionConstructor, ParseOptions } from "commander"; +import { Command, CommandOptions, Option, ParseOptions } from "commander"; import { prepare } from "rechoir"; import { stringifyStream } from "@discoveryjs/json-ext"; @@ -278,7 +278,7 @@ interface ImportLoaderError extends Error { /** * External libraries types */ - +type OptionConstructor = new (flags: string, description?: string) => Option; type CommanderOption = InstanceType; interface Rechoir { diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index e116c888ccc..40c364814c6 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -479,7 +479,10 @@ class WebpackCLI implements IWebpackCLI { }) as WebpackCLICommand; if (commandOptions.description) { - command.description(commandOptions.description, commandOptions.argsDescription); + command.description( + commandOptions.description, + commandOptions.argsDescription as { [argName: string]: string }, + ); } if (commandOptions.usage) { @@ -1292,6 +1295,9 @@ class WebpackCLI implements IWebpackCLI { "Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.", ); + // webpack-cli has it's own logic for showing suggestions + this.program.showSuggestionAfterError(false); + const outputHelp = async ( options: string[], isVerbose: boolean, @@ -1335,7 +1341,7 @@ class WebpackCLI implements IWebpackCLI { // Support multiple aliases subcommandTerm: (command: WebpackCLICommand) => { const humanReadableArgumentName = (argument: WebpackCLICommandOption) => { - const nameOutput = argument.name + (argument.variadic === true ? "..." : ""); + const nameOutput = argument.name() + (argument.variadic === true ? "..." : ""); return argument.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]"; }; @@ -1412,7 +1418,7 @@ class WebpackCLI implements IWebpackCLI { // Arguments const argumentList = helper .visibleArguments(command) - .map((argument) => formatItem(argument.term, argument.description)); + .map((argument) => formatItem(argument.name(), argument.description)); if (argumentList.length > 0) { output = output.concat([bold("Arguments:"), formatList(argumentList), ""]); diff --git a/test/api/CLI.test.js b/test/api/CLI.test.js index aaffdf26137..cdf53153fea 100644 --- a/test/api/CLI.test.js +++ b/test/api/CLI.test.js @@ -1340,7 +1340,7 @@ describe("CLI API", () => { ], (options) => { expect(options).toEqual({ - booleanAndNumberAndString: "default", + booleanAndNumberAndString: true, }); }, ); diff --git a/yarn.lock b/yarn.lock index cc2b3fefb16..5f1d6bd8d32 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4021,17 +4021,12 @@ commander@^2.20.0: resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33" integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ== -commander@^7.0.0, commander@^7.2.0: +commander@^7.2.0: version "7.2.0" resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7" integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw== -commander@^9.0.0, commander@^9.3.0: - version "9.4.1" - resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.1.tgz#d1dd8f2ce6faf93147295c0df13c7c21141cfbdd" - integrity sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw== - -commander@^9.4.0: +commander@^9.0.0, commander@^9.3.0, commander@^9.4.0, commander@^9.4.1: version "9.4.1" resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.1.tgz#d1dd8f2ce6faf93147295c0df13c7c21141cfbdd" integrity sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==