From 29a3b9521e259f39d92923c46dcd7cb3b517280a Mon Sep 17 00:00:00 2001 From: Nitin Kumar Date: Thu, 17 Sep 2020 14:13:13 +0530 Subject: [PATCH] fix: show warning if bail and watch are used together --- packages/webpack-cli/lib/bootstrap.js | 4 ++++ packages/webpack-cli/lib/groups/ConfigGroup.js | 6 ++++++ test/bail/bail-and-watch-warning.test.js | 12 ++++++++++++ test/bail/main.js | 1 + test/bail/webpack.config.js | 6 ++++++ test/core-flags/bail-flag.test.js | 8 ++++++++ 6 files changed, 37 insertions(+) create mode 100644 test/bail/bail-and-watch-warning.test.js create mode 100644 test/bail/main.js create mode 100644 test/bail/webpack.config.js diff --git a/packages/webpack-cli/lib/bootstrap.js b/packages/webpack-cli/lib/bootstrap.js index 5c15faa5ab9..d941e71ec61 100644 --- a/packages/webpack-cli/lib/bootstrap.js +++ b/packages/webpack-cli/lib/bootstrap.js @@ -71,6 +71,10 @@ async function runCLI(cliArgs) { parsedArgsOpts.entry = entry; } + if (parsedArgsOpts.bail && parsedArgsOpts.watch) { + logger.warn('You are using "bail" with "watch". "bail" will still exit webpack when the first error is found.'); + } + const result = await cli.run(parsedArgsOpts, core); if (!result) { return; diff --git a/packages/webpack-cli/lib/groups/ConfigGroup.js b/packages/webpack-cli/lib/groups/ConfigGroup.js index ed22885fce9..64cedceb59e 100644 --- a/packages/webpack-cli/lib/groups/ConfigGroup.js +++ b/packages/webpack-cli/lib/groups/ConfigGroup.js @@ -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); diff --git a/test/bail/bail-and-watch-warning.test.js b/test/bail/bail-and-watch-warning.test.js new file mode 100644 index 00000000000..9700436421d --- /dev/null +++ b/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(); + }); +}); diff --git a/test/bail/main.js b/test/bail/main.js new file mode 100644 index 00000000000..15e0a061dc2 --- /dev/null +++ b/test/bail/main.js @@ -0,0 +1 @@ +console.log('bail and watch warning test'); diff --git a/test/bail/webpack.config.js b/test/bail/webpack.config.js new file mode 100644 index 00000000000..e066755baef --- /dev/null +++ b/test/bail/webpack.config.js @@ -0,0 +1,6 @@ +module.exports = { + entry: './main.js', + mode: 'development', + bail: true, + watch: true, +}; diff --git a/test/core-flags/bail-flag.test.js b/test/core-flags/bail-flag.test.js index 48587933155..d938bdf2609 100644 --- a/test/core-flags/bail-flag.test.js +++ b/test/core-flags/bail-flag.test.js @@ -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'); + }); });