Skip to content

Commit 3309d4a

Browse files
feat(cli): add status icons to webpack-cli's own log messages
Prefix every webpack-cli logger message with a status icon — ✔ success, ✖ error, ⚠ warning, ℹ info — so build, serve and all other commands share the same visual language as the framed help/info/version/configtest screens. The icon sits between the existing `[webpack-cli]` prefix and the unchanged message text, so this is non-breaking: webpack's own `stats.toString()` / `--json` output and webpack-dev-server's messages are untouched, the `[webpack-cli]` prefix is preserved, and tooling that greps the prefix or the message text keeps working. Snapshots updated to include the icons. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012j95RhPtEkRKfzDM4JEhdS Co-authored-by: ThierryRakotomanana <105288252+ThierryRakotomanana@users.noreply.github.com>
1 parent e30c7af commit 3309d4a

11 files changed

Lines changed: 116 additions & 112 deletions

File tree

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,11 +578,15 @@ class WebpackCLI {
578578
}
579579

580580
getLogger(): Logger {
581+
// Status icons brand every webpack-cli message (`✔`/`✖`/`⚠`/`ℹ`). They sit
582+
// between the `[webpack-cli]` prefix and the unchanged message text, so
583+
// tooling that greps the prefix or the message keeps working, and they
584+
// collapse to plain glyphs when colors are disabled.
581585
return {
582-
error: (val) => console.error(`[webpack-cli] ${this.colors.red(util.format(val))}`),
583-
warn: (val) => console.warn(`[webpack-cli] ${this.colors.yellow(val)}`),
584-
info: (val) => console.info(`[webpack-cli] ${this.colors.cyan(val)}`),
585-
success: (val) => console.log(`[webpack-cli] ${this.colors.green(val)}`),
586+
error: (val) => console.error(`[webpack-cli] ${this.colors.red(`✖ ${util.format(val)}`)}`),
587+
warn: (val) => console.warn(`[webpack-cli] ${this.colors.yellow(`⚠ ${val}`)}`),
588+
info: (val) => console.info(`[webpack-cli] ${this.colors.cyan(`ℹ ${val}`)}`),
589+
success: (val) => console.log(`[webpack-cli] ${this.colors.green(`✔ ${val}`)}`),
586590
log: (val) => console.log(`[webpack-cli] ${val}`),
587591
raw: (val) => console.log(val),
588592
};

‎test/build/config/error-array/__snapshots__/config-array-error.test.js.snap.webpack5‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`config with invalid array syntax should throw syntax error and exit with non-zero exit code when even 1 object has syntax error 1`] = `
4-
"[webpack-cli] Failed to load './webpack.config.js' config
4+
"[webpack-cli] ✖ Failed to load './webpack.config.js' config
55
▶ ESM (\`import\`) failed:
66
<cwd>/test/build/config/error-array/webpack.config.js:8
77
target: 'node'; // error eslint-ignore

‎test/build/config/error-commonjs/__snapshots__/config-error.test.js.snap.webpack5‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`config with errors should throw syntax error and exit with non-zero exit code 1`] = `
4-
"[webpack-cli] Failed to load '<cwd>/test/build/config/error-commonjs/syntax-error.js' config
4+
"[webpack-cli] ✖ Failed to load '<cwd>/test/build/config/error-commonjs/syntax-error.js' config
55
▶ ESM (\`import\`) failed:
66
<cwd>/test/build/config/error-commonjs/syntax-error.js:4
77
target: 'node'; //SyntaxError: <error-message>
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`output flag named bundles should output file in bin directory using default webpack config with warning for empty output value: stderr 1`] = `
4-
"[webpack-cli] Error: Option '-o, --output-path <value>' argument missing
5-
[webpack-cli] Run 'webpack --help' to see available commands and options"
4+
"[webpack-cli] ✖ Error: Option '-o, --output-path <value>' argument missing
5+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
66
`;
77

88
exports[`output flag named bundles should output file in bin directory using default webpack config with warning for empty output value: stdout 1`] = `""`;
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`stats flag should log error when an unknown flag stats value is passed: stderr 1`] = `
4-
"[webpack-cli] Invalid value 'foo' for the '--stats' option
5-
[webpack-cli] Expected: 'none | summary | errors-only | errors-warnings | minimal | normal | detailed | verbose'
6-
[webpack-cli] Invalid value 'foo' for the '--stats' option
7-
[webpack-cli] Expected: without value or negative option"
4+
"[webpack-cli] ✖ Invalid value 'foo' for the '--stats' option
5+
[webpack-cli] ✖ Expected: 'none | summary | errors-only | errors-warnings | minimal | normal | detailed | verbose'
6+
[webpack-cli] ✖ Invalid value 'foo' for the '--stats' option
7+
[webpack-cli] ✖ Expected: without value or negative option"
88
`;
99

1010
exports[`stats flag should log error when an unknown flag stats value is passed: stdout 1`] = `""`;

‎test/build/target/flag-test/__snapshots__/target-flag.test.js.snap.webpack5‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ exports[`--target flag should reset the \`target\` option when the \`--target-re
55
exports[`--target flag should reset the \`target\` option when the \`--target-reset\` is used: stderr 1`] = `""`;
66

77
exports[`--target flag should throw an error for incompatible multiple targets: stderr 1`] = `
8-
"[webpack-cli] Error: For the selected environment is no default script chunk format available:
8+
"[webpack-cli] ✖ Error: For the selected environment is no default script chunk format available:
99

1010
JSONP Array push ('array-push') can be chosen when 'document' or 'importScripts' is available.
1111
CommonJs exports ('commonjs') can be chosen when 'require' or node builtins are available.
@@ -16,7 +16,7 @@ Select an appropriate 'target' to allow selecting one by default, or specify the
1616
exports[`--target flag should throw an error for incompatible multiple targets: stdout 1`] = `""`;
1717

1818
exports[`--target flag should throw an error for invalid target in multiple syntax: stderr 1`] = `
19-
"[webpack-cli] Error: Unknown target 'invalid'. The following targets are supported:
19+
"[webpack-cli] ✖ Error: Unknown target 'invalid'. The following targets are supported:
2020
* browserslist / browserslist:env / browserslist:query / browserslist:path-to-config / browserslist:path-to-config:env: Resolve features from browserslist. Will resolve browserslist config automatically. Only browser or node queries are supported (electron is not supported). Examples: 'browserslist:modern' to use 'modern' environment from browserslist config
2121
* web: Web browser.
2222
* webworker: Web Worker, SharedWorker or Service Worker.
@@ -30,14 +30,14 @@ exports[`--target flag should throw an error for invalid target in multiple synt
3030
exports[`--target flag should throw an error for invalid target in multiple syntax: stdout 1`] = `""`;
3131

3232
exports[`--target flag should throw error if target is an empty array: stderr 1`] = `
33-
"[webpack-cli] Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
33+
"[webpack-cli] ✖ Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
3434
- configuration.target should be a non-empty array."
3535
`;
3636

3737
exports[`--target flag should throw error if target is an empty array: stdout 1`] = `""`;
3838

3939
exports[`--target flag should throw error with invalid value for --target: stderr 1`] = `
40-
"[webpack-cli] Error: Unknown target 'invalid'. The following targets are supported:
40+
"[webpack-cli] ✖ Error: Unknown target 'invalid'. The following targets are supported:
4141
* browserslist / browserslist:env / browserslist:query / browserslist:path-to-config / browserslist:path-to-config:env: Resolve features from browserslist. Will resolve browserslist config automatically. Only browser or node queries are supported (electron is not supported). Examples: 'browserslist:modern' to use 'modern' environment from browserslist config
4242
* web: Web browser.
4343
* webworker: Web Worker, SharedWorker or Service Worker.
Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,164 +1,164 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

33
exports[`unknown behaviour should log an error if an unknown flag is passed #2: stderr 1`] = `
4-
"[webpack-cli] Error: Unknown option '-u'
5-
[webpack-cli] Run 'webpack --help' to see available commands and options"
4+
"[webpack-cli] ✖ Error: Unknown option '-u'
5+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
66
`;
77

88
exports[`unknown behaviour should log an error if an unknown flag is passed #2: stdout 1`] = `""`;
99

1010
exports[`unknown behaviour should log an error if an unknown flag is passed #3: stderr 1`] = `
11-
"[webpack-cli] Error: Unknown option '-u'
12-
[webpack-cli] Run 'webpack --help' to see available commands and options"
11+
"[webpack-cli] ✖ Error: Unknown option '-u'
12+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
1313
`;
1414

1515
exports[`unknown behaviour should log an error if an unknown flag is passed #3: stdout 1`] = `""`;
1616

1717
exports[`unknown behaviour should log an error if an unknown flag is passed #4: stderr 1`] = `
18-
"[webpack-cli] Error: Unknown option '-u'
19-
[webpack-cli] Run 'webpack --help' to see available commands and options"
18+
"[webpack-cli] ✖ Error: Unknown option '-u'
19+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
2020
`;
2121

2222
exports[`unknown behaviour should log an error if an unknown flag is passed #4: stdout 1`] = `""`;
2323

2424
exports[`unknown behaviour should log an error if an unknown flag is passed #5: stderr 1`] = `
25-
"[webpack-cli] Error: Unknown option '-u'
26-
[webpack-cli] Run 'webpack --help' to see available commands and options"
25+
"[webpack-cli] ✖ Error: Unknown option '-u'
26+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
2727
`;
2828

2929
exports[`unknown behaviour should log an error if an unknown flag is passed #5: stdout 1`] = `""`;
3030

3131
exports[`unknown behaviour should log an error if an unknown flag is passed and includes =: stderr 1`] = `
32-
"[webpack-cli] Error: Unknown option '--unknown=foo'
33-
[webpack-cli] Run 'webpack --help' to see available commands and options"
32+
"[webpack-cli] ✖ Error: Unknown option '--unknown=foo'
33+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
3434
`;
3535

3636
exports[`unknown behaviour should log an error if an unknown flag is passed and includes =: stdout 1`] = `""`;
3737

3838
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #2: stderr 1`] = `
39-
"[webpack-cli] Error: Unknown option '--output-fileneme'
40-
[webpack-cli] Did you mean '--output-filename'?
41-
[webpack-cli] Run 'webpack --help' to see available commands and options"
39+
"[webpack-cli] ✖ Error: Unknown option '--output-fileneme'
40+
[webpack-cli] ✖ Did you mean '--output-filename'?
41+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
4242
`;
4343

4444
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #2: stdout 1`] = `""`;
4545

4646
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #3: stderr 1`] = `
47-
"[webpack-cli] Error: Unknown option '--output-library-auxiliary-comment-commnjs'
48-
[webpack-cli] Did you mean '--output-library-auxiliary-comment-commonjs'?
49-
[webpack-cli] Did you mean '--output-library-auxiliary-comment-commonjs2'?
50-
[webpack-cli] Run 'webpack --help' to see available commands and options"
47+
"[webpack-cli] ✖ Error: Unknown option '--output-library-auxiliary-comment-commnjs'
48+
[webpack-cli] ✖ Did you mean '--output-library-auxiliary-comment-commonjs'?
49+
[webpack-cli] ✖ Did you mean '--output-library-auxiliary-comment-commonjs2'?
50+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
5151
`;
5252

5353
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag #3: stdout 1`] = `""`;
5454

5555
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "b" command: stderr 1`] = `
56-
"[webpack-cli] Error: Unknown option '--entyr'
57-
[webpack-cli] Did you mean '--entry'?
58-
[webpack-cli] Run 'webpack --help' to see available commands and options"
56+
"[webpack-cli] ✖ Error: Unknown option '--entyr'
57+
[webpack-cli] ✖ Did you mean '--entry'?
58+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
5959
`;
6060

6161
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "b" command: stdout 1`] = `""`;
6262

6363
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "bundle" command: stderr 1`] = `
64-
"[webpack-cli] Error: Unknown option '--entyr'
65-
[webpack-cli] Did you mean '--entry'?
66-
[webpack-cli] Run 'webpack --help' to see available commands and options"
64+
"[webpack-cli] ✖ Error: Unknown option '--entyr'
65+
[webpack-cli] ✖ Did you mean '--entry'?
66+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
6767
`;
6868

6969
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "bundle" command: stdout 1`] = `""`;
7070

7171
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "i" command: stderr 1`] = `
72-
"[webpack-cli] Error: Unknown option '--outpyt'
73-
[webpack-cli] Did you mean '--output'?
74-
[webpack-cli] Run 'webpack --help' to see available commands and options"
72+
"[webpack-cli] ✖ Error: Unknown option '--outpyt'
73+
[webpack-cli] ✖ Did you mean '--output'?
74+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
7575
`;
7676

7777
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "i" command: stdout 1`] = `""`;
7878

7979
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "info" command: stderr 1`] = `
80-
"[webpack-cli] Error: Unknown option '--outpyt'
81-
[webpack-cli] Did you mean '--output'?
82-
[webpack-cli] Run 'webpack --help' to see available commands and options"
80+
"[webpack-cli] ✖ Error: Unknown option '--outpyt'
81+
[webpack-cli] ✖ Did you mean '--output'?
82+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
8383
`;
8484

8585
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag using "info" command: stdout 1`] = `""`;
8686

8787
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag: stderr 1`] = `
88-
"[webpack-cli] Error: Unknown option '--entyr'
89-
[webpack-cli] Did you mean '--entry'?
90-
[webpack-cli] Run 'webpack --help' to see available commands and options"
88+
"[webpack-cli] ✖ Error: Unknown option '--entyr'
89+
[webpack-cli] ✖ Did you mean '--entry'?
90+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
9191
`;
9292

9393
exports[`unknown behaviour should log an error if an unknown flag is passed and suggests the closest match to an unknown flag: stdout 1`] = `""`;
9494

9595
exports[`unknown behaviour should log an error if an unknown flag is passed using "b" command: stderr 1`] = `
96-
"[webpack-cli] Error: Unknown option '--unknown'
97-
[webpack-cli] Run 'webpack --help' to see available commands and options"
96+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
97+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
9898
`;
9999

100100
exports[`unknown behaviour should log an error if an unknown flag is passed using "b" command: stdout 1`] = `""`;
101101

102102
exports[`unknown behaviour should log an error if an unknown flag is passed using "bundle" command #2: stderr 1`] = `
103-
"[webpack-cli] Error: Unknown option '--unknown'
104-
[webpack-cli] Run 'webpack --help' to see available commands and options"
103+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
104+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
105105
`;
106106

107107
exports[`unknown behaviour should log an error if an unknown flag is passed using "bundle" command #2: stdout 1`] = `""`;
108108

109109
exports[`unknown behaviour should log an error if an unknown flag is passed using "bundle" command: stderr 1`] = `
110-
"[webpack-cli] Error: Unknown option '--unknown'
111-
[webpack-cli] Run 'webpack --help' to see available commands and options"
110+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
111+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
112112
`;
113113

114114
exports[`unknown behaviour should log an error if an unknown flag is passed using "bundle" command: stdout 1`] = `""`;
115115

116116
exports[`unknown behaviour should log an error if an unknown flag is passed using "i" command: stderr 1`] = `
117-
"[webpack-cli] Error: Unknown option '--unknown'
118-
[webpack-cli] Run 'webpack --help' to see available commands and options"
117+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
118+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
119119
`;
120120

121121
exports[`unknown behaviour should log an error if an unknown flag is passed using "i" command: stdout 1`] = `""`;
122122

123123
exports[`unknown behaviour should log an error if an unknown flag is passed using "info" command: stderr 1`] = `
124-
"[webpack-cli] Error: Unknown option '--unknown'
125-
[webpack-cli] Run 'webpack --help' to see available commands and options"
124+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
125+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
126126
`;
127127

128128
exports[`unknown behaviour should log an error if an unknown flag is passed using "info" command: stdout 1`] = `""`;
129129

130130
exports[`unknown behaviour should log an error if an unknown flag is passed: stderr 1`] = `
131-
"[webpack-cli] Error: Unknown option '--unknown'
132-
[webpack-cli] Run 'webpack --help' to see available commands and options"
131+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
132+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
133133
`;
134134

135135
exports[`unknown behaviour should log an error if an unknown flag is passed: stdout 1`] = `""`;
136136

137137
exports[`unknown behaviour should log error and provide suggestion if an unknown command passed: stderr 1`] = `
138-
"[webpack-cli] Unknown command or entry 'serverr'
139-
[webpack-cli] Did you mean 'serve' (alias 'server, s')?
140-
[webpack-cli] Run 'webpack --help' to see available commands and options"
138+
"[webpack-cli] ✖ Unknown command or entry 'serverr'
139+
[webpack-cli] ✖ Did you mean 'serve' (alias 'server, s')?
140+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
141141
`;
142142

143143
exports[`unknown behaviour should log error and provide suggestion if an unknown command passed: stdout 1`] = `""`;
144144

145145
exports[`unknown behaviour should log error and respect --color flag: stderr 1`] = `
146-
"[webpack-cli] Error: Unknown option '--unknown'
147-
[webpack-cli] Run 'webpack --help' to see available commands and options"
146+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
147+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
148148
`;
149149

150150
exports[`unknown behaviour should log error and respect --color flag: stdout 1`] = `""`;
151151

152152
exports[`unknown behaviour should log error for unknown flag and respect --no-color: stderr 1`] = `
153-
"[webpack-cli] Error: Unknown option '--unknown'
154-
[webpack-cli] Run 'webpack --help' to see available commands and options"
153+
"[webpack-cli] ✖ Error: Unknown option '--unknown'
154+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
155155
`;
156156

157157
exports[`unknown behaviour should log error for unknown flag and respect --no-color: stdout 1`] = `""`;
158158

159159
exports[`unknown behaviour should log error if an unknown command passed: stderr 1`] = `
160-
"[webpack-cli] Unknown command or entry 'qqq'
161-
[webpack-cli] Run 'webpack --help' to see available commands and options"
160+
"[webpack-cli] ✖ Unknown command or entry 'qqq'
161+
[webpack-cli] ✖ Run 'webpack --help' to see available commands and options"
162162
`;
163163

164164
exports[`unknown behaviour should log error if an unknown command passed: stdout 1`] = `""`;

‎test/configtest/with-config-path/__snapshots__/with-config-path.test.js.snap.webpack5‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
22

3-
exports[`'configtest' command with the configuration path option should throw error if configuration does not exist: stderr 1`] = `"[webpack-cli] Failed to load './a.js' config"`;
3+
exports[`'configtest' command with the configuration path option should throw error if configuration does not exist: stderr 1`] = `"[webpack-cli] ✖ Failed to load './a.js' config"`;
44

55
exports[`'configtest' command with the configuration path option should throw error if configuration does not exist: stdout 1`] = `""`;
66

77
exports[`'configtest' command with the configuration path option should throw syntax error: stderr 1`] = `
8-
"[webpack-cli] Failed to load './syntax-error.config.js' config
8+
"[webpack-cli] ✖ Failed to load './syntax-error.config.js' config
99
▶ ESM (\`import\`) failed:
1010
<cwd>/test/configtest/with-config-path/syntax-error.config.js:5
1111
target: 'node';

0 commit comments

Comments
 (0)