Skip to content

Commit 4cd5aef

Browse files
snitin315alexander-akait
authored andcommittedDec 18, 2024
fix: improve help output for possible values (#4316)
* fix: improve help output for possible values * test: udpate snaps
1 parent 1490af0 commit 4cd5aef

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed
 

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -1646,9 +1646,14 @@ class WebpackCLI implements IWebpackCLI {
16461646
);
16471647

16481648
if (possibleValues.length > 0) {
1649-
this.logger.raw(
1650-
`${bold("Possible values:")} ${JSON.stringify(possibleValues.join(" | "))}`,
1651-
);
1649+
// Convert the possible values to a union type string
1650+
// ['mode', 'development', 'production'] => "'mode' | 'development' | 'production'"
1651+
// [false, 'eval'] => "false | 'eval'"
1652+
const possibleValuesUnionTypeString = possibleValues
1653+
.map((value) => (typeof value === "string" ? `'${value}'` : value))
1654+
.join(" | ");
1655+
1656+
this.logger.raw(`${bold("Possible values:")} ${possibleValuesUnionTypeString}`);
16521657
}
16531658
}
16541659

‎test/api/__snapshots__/CLI.test.js.snap.webpack5

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports[`CLI API custom help output should display help information 1`] = `
99
"Description: Enable production optimizations or development hints.",
1010
],
1111
[
12-
"Possible values: "development | production | none"",
12+
"Possible values: 'development' | 'production' | 'none'",
1313
],
1414
[
1515
"",

‎test/help/__snapshots__/help.test.js.snap.devServer5.webpack5

+19-5
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ exports[`help should show help information using the "help --cache-type" option:
12071207
exports[`help should show help information using the "help --cache-type" option: stdout 1`] = `
12081208
"Usage: webpack --cache-type <value>
12091209
Description: In memory caching. Filesystem caching.
1210-
Possible values: "memory | filesystem"
1210+
Possible values: 'memory' | 'filesystem'
12111211

12121212
To see list of all supported commands and options run 'webpack --help=verbose'.
12131213

@@ -1234,7 +1234,7 @@ exports[`help should show help information using the "help --mode" option: stder
12341234
exports[`help should show help information using the "help --mode" option: stdout 1`] = `
12351235
"Usage: webpack --mode <value>
12361236
Description: Enable production optimizations or development hints.
1237-
Possible values: "development | production | none"
1237+
Possible values: 'development' | 'production' | 'none'
12381238

12391239
To see list of all supported commands and options run 'webpack --help=verbose'.
12401240

@@ -1269,12 +1269,26 @@ CLI documentation: https://webpack.js.org/api/cli/.
12691269
Made with ♥ by the webpack team."
12701270
`;
12711271

1272+
exports[`help should show help information using the "help --output-chunk-format" option: stderr 1`] = `""`;
1273+
1274+
exports[`help should show help information using the "help --output-chunk-format" option: stdout 1`] = `
1275+
"Usage: webpack --output-chunk-format <value>
1276+
Description: The format of chunks (formats included by default are 'array-push' (web/WebWorker), 'commonjs' (node.js), 'module' (ESM), but others might be added by plugins).
1277+
Possible values: 'array-push' | 'commonjs' | 'module' | false
1278+
1279+
To see list of all supported commands and options run 'webpack --help=verbose'.
1280+
1281+
Webpack documentation: https://webpack.js.org/.
1282+
CLI documentation: https://webpack.js.org/api/cli/.
1283+
Made with ♥ by the webpack team."
1284+
`;
1285+
12721286
exports[`help should show help information using the "help --stats" option: stderr 1`] = `""`;
12731287

12741288
exports[`help should show help information using the "help --stats" option: stdout 1`] = `
12751289
"Usage: webpack --stats [value]
12761290
Description: Stats options object or preset name.
1277-
Possible values: "none | summary | errors-only | errors-warnings | minimal | normal | detailed | verbose"
1291+
Possible values: 'none' | 'summary' | 'errors-only' | 'errors-warnings' | 'minimal' | 'normal' | 'detailed' | 'verbose'
12781292

12791293
To see list of all supported commands and options run 'webpack --help=verbose'.
12801294

@@ -1289,7 +1303,7 @@ exports[`help should show help information using the "help --target" option: std
12891303
"Usage: webpack --target <value...>
12901304
Short: webpack -t <value...>
12911305
Description: Environment to build for. Environment to build for. An array of environments to build for all of them when possible.
1292-
Possible values: "false"
1306+
Possible values: false
12931307

12941308
To see list of all supported commands and options run 'webpack --help=verbose'.
12951309

@@ -1344,7 +1358,7 @@ exports[`help should show help information using the "help serve --mode" option:
13441358
exports[`help should show help information using the "help serve --mode" option: stdout 1`] = `
13451359
"Usage: webpack serve --mode <value>
13461360
Description: Enable production optimizations or development hints.
1347-
Possible values: "development | production | none"
1361+
Possible values: 'development' | 'production' | 'none'
13481362

13491363
To see list of all supported commands and options run 'webpack --help=verbose'.
13501364

‎test/help/help.test.js

+8
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,14 @@ describe("help", () => {
243243
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
244244
});
245245

246+
it('should show help information using the "help --output-chunk-format" option', async () => {
247+
const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--output-chunk-format"]);
248+
249+
expect(exitCode).toBe(0);
250+
expect(normalizeStderr(stderr)).toMatchSnapshot("stderr");
251+
expect(normalizeStdout(stdout)).toMatchSnapshot("stdout");
252+
});
253+
246254
it('should show help information using the "help --no-stats" option', async () => {
247255
const { exitCode, stderr, stdout } = await run(__dirname, ["help", "--no-stats"]);
248256

0 commit comments

Comments
 (0)
Please sign in to comment.