Skip to content

Commit a06b3cc

Browse files
committed
fix: detect duplicate builds and prevent duplicate output
1 parent b78c2ba commit a06b3cc

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

bin/wp.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ webpack v${webpack.version}
8181
}
8282

8383
let config = {};
84+
let lastHash;
8485
let watchConfig;
8586

8687
if (!argv.config && existsSync(defaultConfigPath)) {
@@ -124,6 +125,13 @@ webpack v${webpack.version}
124125
return;
125126
}
126127

128+
if (lastHash === stats.hash) {
129+
log.info(chalk`{dim ⁿᵃⁿᵒ} Duplicate build detected {dim (${lastHash})}\n`);
130+
return;
131+
}
132+
133+
lastHash = stats.hash;
134+
127135
const statsDefaults = { colors: chalk.supportsColor.hasBasic, exclude: ['node_modules'] };
128136
const { options = {} } =
129137
[]
@@ -135,7 +143,8 @@ webpack v${webpack.version}
135143
: options.stats;
136144
const result = stats.toString(statsOptions);
137145

138-
log.info(result);
146+
// indent the result slightly to visually set it apart from other output
147+
log.info(result.split('\n').join('\n '), '\n');
139148
};
140149

141150
if (watchConfig) {

test/snapshots/test.js.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,12 @@ Generated by [AVA](https://ava.li).
3636
_: [
3737
'undefined',
3838
],
39-
}
39+
}
40+
41+
## stats
42+
43+
> Snapshot 1
44+
45+
`⬡ webpack: Build Finished␊
46+
⬡ webpack: 1 module ␊
47+
`

test/snapshots/test.js.snap

59 Bytes
Binary file not shown.

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ test('multi', async (t) => {
6868

6969
test('stats', async (t) => {
7070
const { stderr } = await run('--config', 'stats.config.js');
71-
t.is(stderr, '⬡ webpack: Build Finished\n⬡ webpack: 1 module');
71+
t.snapshot(stderr);
7272
});
7373

7474
test('watch', (t) => {

0 commit comments

Comments
 (0)