Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: respect stats from the config for webpack@4 (#2098)
  • Loading branch information
evilebottnawi committed Nov 11, 2020
1 parent f6f4585 commit 2d6e5c6
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
13 changes: 12 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -666,11 +666,22 @@ class WebpackCLI {
process.exit(2);
}
} else {
logger.raw(`${stats.toString(foundStats)}`);
const printedStats = stats.toString(foundStats);

// Avoid extra empty line when `stats: 'none'`
if (printedStats) {
logger.raw(`${stats.toString(foundStats)}`);
}
}
};

compiler = this.createCompiler(options, callback);

// TODO webpack@4 return Watching and MultiWathing instead Compiler and MultiCompiler, remove this after drop webpack@4
if (compiler && compiler.compiler) {
compiler = compiler.compiler;
}

return Promise.resolve();
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/stats/watch/multi-webpack.config.js
@@ -0,0 +1,10 @@
module.exports = [
{
watch: true,
stats: 'none',
},
{
watch: true,
stats: 'none',
},
];
1 change: 1 addition & 0 deletions test/stats/watch/src/index.js
@@ -0,0 +1 @@
console.log('TEST');
35 changes: 35 additions & 0 deletions test/stats/watch/stats-and-watch.test.js
@@ -0,0 +1,35 @@
'use strict';

const { runWatch, isWebpack5 } = require('../../utils/test-utils');

describe('stats and watch', () => {
it('should not log stats with the "none" value from the configuration', async () => {
const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--color']);

expect(stdout).toContain('[webpack-cli] Compilation starting...');
expect(stdout).toContain('[webpack-cli] Compilation finished');
expect(stdout).toContain('[webpack-cli] watching files for updates...');
expect(stderr).toBeFalsy();
});

it('should not log stats with the "none" value from the configuration and multi compiler mode', async () => {
const { stderr, stdout } = await runWatch(__dirname, ['-c', './multi-webpack.config.js', '--color']);

expect(stdout).toContain('[webpack-cli] Compilation starting...');
expect(stdout).toContain('[webpack-cli] Compilation finished');
expect(stdout).toContain('[webpack-cli] watching files for updates...');
expect(stderr).toBeFalsy();
});

it('should log stats with the "normal" value in arguments', async () => {
const { stderr, stdout } = await runWatch(__dirname, ['-c', './webpack.config.js', '--stats', 'normal', '--color']);

const output = isWebpack5 ? 'successfully' : 'main.js';

expect(stdout).toContain('[webpack-cli] Compilation starting...');
expect(stdout).toContain('[webpack-cli] Compilation finished');
expect(stdout).toContain('[webpack-cli] watching files for updates...');
expect(stdout).toContain(output);
expect(stderr).toBeFalsy();
});
});
4 changes: 4 additions & 0 deletions test/stats/watch/webpack.config.js
@@ -0,0 +1,4 @@
module.exports = {
watch: true,
stats: 'none',
};

0 comments on commit 2d6e5c6

Please sign in to comment.