Skip to content

Commit 2d6e5c6

Browse files
fix: respect stats from the config for webpack@4 (#2098)
1 parent f6f4585 commit 2d6e5c6

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

packages/webpack-cli/lib/webpack-cli.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -666,11 +666,22 @@ class WebpackCLI {
666666
process.exit(2);
667667
}
668668
} else {
669-
logger.raw(`${stats.toString(foundStats)}`);
669+
const printedStats = stats.toString(foundStats);
670+
671+
// Avoid extra empty line when `stats: 'none'`
672+
if (printedStats) {
673+
logger.raw(`${stats.toString(foundStats)}`);
674+
}
670675
}
671676
};
672677

673678
compiler = this.createCompiler(options, callback);
679+
680+
// TODO webpack@4 return Watching and MultiWathing instead Compiler and MultiCompiler, remove this after drop webpack@4
681+
if (compiler && compiler.compiler) {
682+
compiler = compiler.compiler;
683+
}
684+
674685
return Promise.resolve();
675686
}
676687
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = [
2+
{
3+
watch: true,
4+
stats: 'none',
5+
},
6+
{
7+
watch: true,
8+
stats: 'none',
9+
},
10+
];

test/stats/watch/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('TEST');
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
const { runWatch, isWebpack5 } = require('../../utils/test-utils');
4+
5+
describe('stats and watch', () => {
6+
it('should not log stats with the "none" value from the configuration', async () => {
7+
const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--color']);
8+
9+
expect(stdout).toContain('[webpack-cli] Compilation starting...');
10+
expect(stdout).toContain('[webpack-cli] Compilation finished');
11+
expect(stdout).toContain('[webpack-cli] watching files for updates...');
12+
expect(stderr).toBeFalsy();
13+
});
14+
15+
it('should not log stats with the "none" value from the configuration and multi compiler mode', async () => {
16+
const { stderr, stdout } = await runWatch(__dirname, ['-c', './multi-webpack.config.js', '--color']);
17+
18+
expect(stdout).toContain('[webpack-cli] Compilation starting...');
19+
expect(stdout).toContain('[webpack-cli] Compilation finished');
20+
expect(stdout).toContain('[webpack-cli] watching files for updates...');
21+
expect(stderr).toBeFalsy();
22+
});
23+
24+
it('should log stats with the "normal" value in arguments', async () => {
25+
const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--stats', 'normal', '--color']);
26+
27+
const output = isWebpack5 ? 'successfully' : 'main.js';
28+
29+
expect(stdout).toContain('[webpack-cli] Compilation starting...');
30+
expect(stdout).toContain('[webpack-cli] Compilation finished');
31+
expect(stdout).toContain('[webpack-cli] watching files for updates...');
32+
expect(stdout).toContain(output);
33+
expect(stderr).toBeFalsy();
34+
});
35+
});

test/stats/watch/webpack.config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
watch: true,
3+
stats: 'none',
4+
};

0 commit comments

Comments
 (0)