Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: respect stats from the config for webpack@4 #2098

Merged
merged 6 commits into from Nov 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 12 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Expand Up @@ -641,11 +641,22 @@ class WebpackCLI {
process.exit(2);
}
} else {
logger.raw(`${stats.toString(foundStats)}`);
const printedStats = stats.toString(foundStats);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we use stats: 'none' we have empty string, so no need to log empty string


// 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 instad Compiler and MultiCompiler, remove this after drop webpack@4
alexander-akait marked this conversation as resolved.
Show resolved Hide resolved
if (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/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']);

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']);

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']);

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

expect(stdout).toContain('[webpack-cli] Compilation starting...');
expect(stdout).toContain('[webpack-cli] Compilation finished');
expect(stdout).toContain(output);
expect(stdout).toContain('[webpack-cli] watching files for updates...');
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',
};