Skip to content

Commit

Permalink
fix: show warning if bail and watch are used together
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Sep 17, 2020
1 parent 1724ddb commit a3e8ee8
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions packages/webpack-cli/lib/groups/ConfigGroup.js
Expand Up @@ -127,6 +127,12 @@ class ConfigGroup extends GroupHelper {
newOptionsObject['options'] = configOptions;
}

//warn the user if bail and watch both are used together
const { bail, watch } = newOptionsObject['options'];
if (bail && watch) {
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
}

if (configOptions && configPath.includes('.webpack')) {
const currentPath = configPath;
const parentContext = dirname(currentPath).split(sep).slice(0, -1).join(sep);
Expand Down
5 changes: 5 additions & 0 deletions packages/webpack-cli/lib/utils/Compiler.js
Expand Up @@ -117,6 +117,11 @@ class Compiler {
return interactive(options, outputOptions);
}

//warn the user if bail and watch both are used together
if (this.compiler.options.bail && outputOptions.watch) {
logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.');
}

if (this.compiler.compilers) {
this.compiler.compilers.forEach((comp, idx) => {
this.setUpHookForCompilation(comp, outputOptions, options[idx]);
Expand Down
12 changes: 12 additions & 0 deletions test/bail/bail-and-watch-warning.test.js
@@ -0,0 +1,12 @@
'use strict';

const { run } = require('../utils/test-utils');

describe('bail and watch warning', () => {
it('should log warning if bail and watch both options are true', () => {
const { stderr, stdout } = run(__dirname, ['-c', 'webpack.config.js']);

expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
expect(stdout).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/bail/main.js
@@ -0,0 +1 @@
console.log('bail and watch warning test');
6 changes: 6 additions & 0 deletions test/bail/webpack.config.js
@@ -0,0 +1,6 @@
module.exports = {
entry: './main.js',
mode: 'development',
bail: true,
watch: true,
};
8 changes: 8 additions & 0 deletions test/core-flags/bail-flag.test.js
Expand Up @@ -16,4 +16,12 @@ describe('--bail flag', () => {
expect(stderr).toBeFalsy();
expect(stdout).toContain('bail: false');
});

it('should log warning if --bail and --watch are used together', () => {
const { stderr, stdout } = run(__dirname, ['--bail', '--watch']);

expect(stderr).toContain(`You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.`);
expect(stdout).toContain('bail: true');
expect(stdout).toContain('watch: true');
});
});

0 comments on commit a3e8ee8

Please sign in to comment.