Skip to content

Commit 3d7fd6a

Browse files
chenjiahanCopilot
andauthored
fix: print hint when stats.errors is disabled (#6304)
Co-authored-by: Copilot <[email protected]>
1 parent b17ae2f commit 3d7fd6a

File tree

8 files changed

+42
-17
lines changed

8 files changed

+42
-17
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { rspackTest } from '@e2e/helper';
2+
3+
const EXPECTED_LOG = `Build failed. No errors reported since Rspack's "stats.errors" is disabled.`;
4+
5+
rspackTest(
6+
'should print a hint if stats.errors is disabled after a dev failure',
7+
async ({ dev }) => {
8+
const rsbuild = await dev();
9+
await rsbuild.expectLog(EXPECTED_LOG);
10+
},
11+
);
12+
13+
rspackTest(
14+
'should print a hint if stats.errors is disabled after a build failure',
15+
async ({ build }) => {
16+
const rsbuild = await build({
17+
catchBuildError: true,
18+
});
19+
await rsbuild.expectLog(EXPECTED_LOG);
20+
},
21+
);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
3+
export default defineConfig({
4+
tools: {
5+
rspack: {
6+
stats: {
7+
errors: false,
8+
},
9+
},
10+
},
11+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './non-existent-file.js';

e2e/helper/fixture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {
1919
import { type ExtendedLogHelper, proxyConsole } from './logs';
2020

2121
function makeBox(title: string) {
22-
const header = `╭────────────── Logs from: "${title}" ──────────────╮`;
23-
const footer = `╰────────────── Logs from: "${title}" ──────────────╯`;
22+
const header = `╭──────────── Logs from: "${title}" ────────────╮`;
23+
const footer = `╰──────────── Logs from: "${title}" ────────────╯`;
2424
return {
2525
header: `\n${header}\n`,
2626
footer: `${footer}\n`,

packages/compat/webpack/src/createCompiler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function createCompiler(options: InitConfigsOptions) {
4242
compiler,
4343
context.action,
4444
);
45-
const hasErrors = helpers.getStatsErrors(stats).length > 0;
45+
const hasErrors = statsInstance.hasErrors();
4646

4747
context.buildState.stats = stats;
4848
context.buildState.status = 'done';

packages/core/src/helpers/stats.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ import { isMultiCompiler } from './';
55
import { formatStatsError } from './format';
66

77
function formatErrorMessage(errors: string[]) {
8-
const title = color.bold(
9-
color.red(errors.length > 1 ? 'Build errors: ' : 'Build error: '),
10-
);
11-
128
if (!errors.length) {
13-
return `${title}\n${color.yellow(`For more details, please set 'stats.errors: true' `)}`;
9+
return `Build failed. No errors reported since Rspack's "stats.errors" is disabled.`;
1410
}
1511

12+
const title = color.bold(
13+
color.red(errors.length > 1 ? 'Build errors: ' : 'Build error: '),
14+
);
1615
const text = `${errors.join('\n\n')}\n`;
17-
1816
return `${title}\n${text}`;
1917
}
2018

packages/core/src/provider/createCompiler.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
color,
44
formatStats,
55
getRsbuildStats,
6-
getStatsErrors,
76
isSatisfyRspackVersion,
87
prettyTime,
98
rspackMinVersion,
@@ -187,7 +186,7 @@ export async function createCompiler(options: InitConfigsOptions): Promise<{
187186
HOOK_NAME,
188187
(statsInstance: Rspack.Stats | Rspack.MultiStats) => {
189188
const stats = getRsbuildStats(statsInstance, compiler, context.action);
190-
const hasErrors = getStatsErrors(stats).length > 0;
189+
const hasErrors = statsInstance.hasErrors();
191190

192191
context.buildState.stats = stats;
193192
context.buildState.status = 'done';

packages/core/src/provider/helpers.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
*/
44

55
export { modifyBundlerChain } from '../configChain';
6-
export {
7-
formatStats,
8-
getRsbuildStats,
9-
getStatsErrors,
10-
prettyTime,
11-
} from '../helpers';
6+
export { formatStats, getRsbuildStats, prettyTime } from '../helpers';
127
export { registerBuildHook, registerDevHook } from '../hooks';
138
export { inspectConfig } from '../inspectConfig';
149
export {

0 commit comments

Comments
 (0)