Skip to content

Commit 6621c02

Browse files
snitin315alexander-akait
authored andcommittedNov 15, 2022
feat: update commander to v9 (#3460)
1 parent ddfc21f commit 6621c02

File tree

5 files changed

+15
-14
lines changed

5 files changed

+15
-14
lines changed
 

‎packages/webpack-cli/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"@webpack-cli/info": "^1.5.0",
4040
"@webpack-cli/serve": "^1.7.0",
4141
"colorette": "^2.0.14",
42-
"commander": "^7.0.0",
42+
"commander": "^9.4.1",
4343
"cross-spawn": "^7.0.3",
4444
"envinfo": "^7.7.3",
4545
"fastest-levenshtein": "^1.0.12",

‎packages/webpack-cli/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import webpack, {
1919
import { ClientConfiguration, Configuration as DevServerConfig } from "webpack-dev-server";
2020

2121
import { Colorette } from "colorette";
22-
import { Command, CommandOptions, OptionConstructor, ParseOptions } from "commander";
22+
import { Command, CommandOptions, Option, ParseOptions } from "commander";
2323
import { prepare } from "rechoir";
2424
import { stringifyStream } from "@discoveryjs/json-ext";
2525

@@ -278,7 +278,7 @@ interface ImportLoaderError extends Error {
278278
/**
279279
* External libraries types
280280
*/
281-
281+
type OptionConstructor = new (flags: string, description?: string) => Option;
282282
type CommanderOption = InstanceType<OptionConstructor>;
283283

284284
interface Rechoir {

‎packages/webpack-cli/src/webpack-cli.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,10 @@ class WebpackCLI implements IWebpackCLI {
479479
}) as WebpackCLICommand;
480480

481481
if (commandOptions.description) {
482-
command.description(commandOptions.description, commandOptions.argsDescription);
482+
command.description(
483+
commandOptions.description,
484+
commandOptions.argsDescription as { [argName: string]: string },
485+
);
483486
}
484487

485488
if (commandOptions.usage) {
@@ -1292,6 +1295,9 @@ class WebpackCLI implements IWebpackCLI {
12921295
"Output the version number of 'webpack', 'webpack-cli' and 'webpack-dev-server' and commands.",
12931296
);
12941297

1298+
// webpack-cli has it's own logic for showing suggestions
1299+
this.program.showSuggestionAfterError(false);
1300+
12951301
const outputHelp = async (
12961302
options: string[],
12971303
isVerbose: boolean,
@@ -1335,7 +1341,7 @@ class WebpackCLI implements IWebpackCLI {
13351341
// Support multiple aliases
13361342
subcommandTerm: (command: WebpackCLICommand) => {
13371343
const humanReadableArgumentName = (argument: WebpackCLICommandOption) => {
1338-
const nameOutput = argument.name + (argument.variadic === true ? "..." : "");
1344+
const nameOutput = argument.name() + (argument.variadic === true ? "..." : "");
13391345

13401346
return argument.required ? "<" + nameOutput + ">" : "[" + nameOutput + "]";
13411347
};
@@ -1412,7 +1418,7 @@ class WebpackCLI implements IWebpackCLI {
14121418
// Arguments
14131419
const argumentList = helper
14141420
.visibleArguments(command)
1415-
.map((argument) => formatItem(argument.term, argument.description));
1421+
.map((argument) => formatItem(argument.name(), argument.description));
14161422

14171423
if (argumentList.length > 0) {
14181424
output = output.concat([bold("Arguments:"), formatList(argumentList), ""]);

‎test/api/CLI.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ describe("CLI API", () => {
13401340
],
13411341
(options) => {
13421342
expect(options).toEqual({
1343-
booleanAndNumberAndString: "default",
1343+
booleanAndNumberAndString: true,
13441344
});
13451345
},
13461346
);

‎yarn.lock

+2-7
Original file line numberDiff line numberDiff line change
@@ -4021,17 +4021,12 @@ commander@^2.20.0:
40214021
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
40224022
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==
40234023

4024-
commander@^7.0.0, commander@^7.2.0:
4024+
commander@^7.2.0:
40254025
version "7.2.0"
40264026
resolved "https://registry.yarnpkg.com/commander/-/commander-7.2.0.tgz#a36cb57d0b501ce108e4d20559a150a391d97ab7"
40274027
integrity sha512-QrWXB+ZQSVPmIWIhtEO9H+gwHaMGYiF5ChvoJ+K9ZGHG/sVsa6yiesAD1GC/x46sET00Xlwo1u49RVVVzvcSkw==
40284028

4029-
commander@^9.0.0, commander@^9.3.0:
4030-
version "9.4.1"
4031-
resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.1.tgz#d1dd8f2ce6faf93147295c0df13c7c21141cfbdd"
4032-
integrity sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==
4033-
4034-
commander@^9.4.0:
4029+
commander@^9.0.0, commander@^9.3.0, commander@^9.4.0, commander@^9.4.1:
40354030
version "9.4.1"
40364031
resolved "https://registry.yarnpkg.com/commander/-/commander-9.4.1.tgz#d1dd8f2ce6faf93147295c0df13c7c21141cfbdd"
40374032
integrity sha512-5EEkTNyHNGFPD2H+c/dXXfQZYa/scCKasxWcXJaWnNJ99pnQN9Vnmqow+p+PlFPE63Q6mThaZws1T+HxfpgtPw==

0 commit comments

Comments
 (0)
Please sign in to comment.