From 540d5012d2f69a25105bf30086eee7772103d3ad Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Mon, 4 Nov 2024 16:42:19 +0530 Subject: [PATCH] chore: update commander.js to v12 (#4315) --- packages/webpack-cli/package.json | 2 +- packages/webpack-cli/src/webpack-cli.ts | 3 ++- test/api/CLI.test.js | 4 +--- test/api/__snapshots__/CLI.test.js.snap.webpack5 | 12 ++++++------ yarn.lock | 5 ----- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/packages/webpack-cli/package.json b/packages/webpack-cli/package.json index 86b25c2d5e3..6c406a3cfb7 100644 --- a/packages/webpack-cli/package.json +++ b/packages/webpack-cli/package.json @@ -39,7 +39,7 @@ "@webpack-cli/info": "^2.0.2", "@webpack-cli/serve": "^2.0.5", "colorette": "^2.0.14", - "commander": "^10.0.1", + "commander": "^12.1.0", "cross-spawn": "^7.0.3", "envinfo": "^7.14.0", "fastest-levenshtein": "^1.0.12", diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index 8b29eb91f98..fc9eb770b4a 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -1669,7 +1669,8 @@ class WebpackCLI implements IWebpackCLI { process.exit(0); }; this.program.helpOption(false); - this.program.addHelpCommand(false); + // Suppress the default help command + this.program.helpCommand(false); this.program.option("-h, --help [verbose]", "Display help for commands and options."); let isInternalActionCalled = false; diff --git a/test/api/CLI.test.js b/test/api/CLI.test.js index a9f490a3d8f..bb4b4601505 100644 --- a/test/api/CLI.test.js +++ b/test/api/CLI.test.js @@ -1703,11 +1703,9 @@ describe("CLI API", () => { consoleSpy = jest.spyOn(global.console, "log"); exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {}); - cli.program.option("--color [value]", "any color", "blue"); - await new Promise((resolve, reject) => { try { - cli.run(["help", "--color"], { from: "user" }); + cli.run(["help", "--mode"], { from: "user" }); resolve(); } catch (error) { reject(error); diff --git a/test/api/__snapshots__/CLI.test.js.snap.webpack5 b/test/api/__snapshots__/CLI.test.js.snap.webpack5 index 1df97468a75..40b8c08886a 100644 --- a/test/api/__snapshots__/CLI.test.js.snap.webpack5 +++ b/test/api/__snapshots__/CLI.test.js.snap.webpack5 @@ -3,13 +3,13 @@ exports[`CLI API custom help output should display help information 1`] = ` [ [ - "Usage: webpack --color [value]", + "Usage: webpack --mode ", ], [ - "Description: any color", + "Description: Enable production optimizations or development hints.", ], [ - "Default value: "blue"", + "Possible values: "development | production | none"", ], [ "", @@ -19,13 +19,13 @@ exports[`CLI API custom help output should display help information 1`] = ` ", ], [ - "Webpack documentation: https://webpack.js.org/.", + "Webpack documentation: https://webpack.js.org/.", ], [ - "CLI documentation: https://webpack.js.org/api/cli/.", + "CLI documentation: https://webpack.js.org/api/cli/.", ], [ - "Made with ♥ by the webpack team.", + "Made with ♥ by the webpack team.", ], ] `; diff --git a/yarn.lock b/yarn.lock index 027b8a90f67..2337f74ef48 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4142,11 +4142,6 @@ combined-stream@^1.0.8: dependencies: delayed-stream "~1.0.0" -commander@^10.0.1: - version "10.0.1" - resolved "https://registry.yarnpkg.com/commander/-/commander-10.0.1.tgz#881ee46b4f77d1c1dccc5823433aa39b022cbe06" - integrity sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug== - commander@^12.1.0, commander@~12.1.0: version "12.1.0" resolved "https://registry.yarnpkg.com/commander/-/commander-12.1.0.tgz#01423b36f501259fdaac4d0e4d60c96c991585d3"