Skip to content

Commit 29a3b95

Browse files
committed
fix: show warning if bail and watch are used together
1 parent 4ee08d8 commit 29a3b95

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

packages/webpack-cli/lib/bootstrap.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ async function runCLI(cliArgs) {
7171
parsedArgsOpts.entry = entry;
7272
}
7373

74+
if (parsedArgsOpts.bail && parsedArgsOpts.watch) {
75+
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
76+
}
77+
7478
const result = await cli.run(parsedArgsOpts, core);
7579
if (!result) {
7680
return;

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