Skip to content

Commit

Permalink
feat: update commander to v9 (#3460)
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 authored and alexander-akait committed Nov 15, 2022
1 parent ddfc21f commit 6621c02
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/webpack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -278,7 +278,7 @@ interface ImportLoaderError extends Error {
/**
* External libraries types
*/

type OptionConstructor = new (flags: string, description?: string) => Option;
type CommanderOption = InstanceType<OptionConstructor>;

interface Rechoir {
Expand Down
12 changes: 9 additions & 3 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 + "]";
};
Expand Down Expand Up @@ -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), ""]);
Expand Down
2 changes: 1 addition & 1 deletion test/api/CLI.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ describe("CLI API", () => {
],
(options) => {
expect(options).toEqual({
booleanAndNumberAndString: "default",
booleanAndNumberAndString: true,
});
},
);
Expand Down
9 changes: 2 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down

0 comments on commit 6621c02

Please sign in to comment.