Skip to content

Commit a3e8ee8

Browse files
committed
fix: show warning if bail and watch are used together
1 parent 1724ddb commit a3e8ee8

File tree

6 files changed

+38
-0
lines changed

6 files changed

+38
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ class ConfigGroup extends GroupHelper {
127127
newOptionsObject['options'] = configOptions;
128128
}
129129

130+
//warn the user if bail and watch both are used together
131+
const { bail, watch } = newOptionsObject['options'];
132+
if (bail && watch) {
133+
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
134+
}
135+
130136
if (configOptions && configPath.includes('.webpack')) {
131137
const currentPath = configPath;
132138
const parentContext = dirname(currentPath).split(sep).slice(0, -1).join(sep);

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ class Compiler {
117117
return interactive(options, outputOptions);
118118
}
119119

120+
//warn the user if bail and watch both are used together
121+
if (this.compiler.options.bail && outputOptions.watch) {
122+
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
123+
}
124+
120125
if (this.compiler.compilers) {
121126
this.compiler.compilers.forEach((comp, idx) => {
122127
this.setUpHookForCompilation(comp, outputOptions, options[idx]);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const { run } = require('../utils/test-utils');
4+
5+
describe('bail and watch warning', () => {
6+
it('should log warning if bail and watch both options are true', () => {
7+
const { stderr, stdout } = run(__dirname, ['-c', 'webpack.config.js']);
8+
9+
expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
10+
expect(stdout).toBeTruthy();
11+
});
12+
});

test/bail/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('bail and watch warning test');

test/bail/webpack.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
entry: './main.js',
3+
mode: 'development',
4+
bail: true,
5+
watch: true,
6+
};

test/core-flags/bail-flag.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,12 @@ describe('--bail flag', () => {
1616
expect(stderr).toBeFalsy();
1717
expect(stdout).toContain('bail: false');
1818
});
19+
20+
it('should log warning if --bail and --watch are used together', () => {
21+
const { stderr, stdout } = run(__dirname, ['--bail', '--watch']);
22+
23+
expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
24+
expect(stdout).toContain('bail: true');
25+
expect(stdout).toContain('watch: true');
26+
});
1927
});

0 commit comments

Comments
 (0)