diff --git a/packages/webpack-cli/lib/groups/ConfigGroup.js b/packages/webpack-cli/lib/groups/ConfigGroup.js index 3ddf1875ad8..09f4cea3f3b 100644 --- a/packages/webpack-cli/lib/groups/ConfigGroup.js +++ b/packages/webpack-cli/lib/groups/ConfigGroup.js @@ -4,7 +4,7 @@ const webpackMerge = require('webpack-merge'); const { extensions, jsVariants } = require('interpret'); const GroupHelper = require('../utils/GroupHelper'); const rechoir = require('rechoir'); -const MergeError = require('../utils/errors/MergeError'); +const ConfigError = require('../utils/errors/ConfigError'); const logger = require('../utils/logger'); // Order defines the priority, in increasing order @@ -89,7 +89,6 @@ class ConfigGroup extends GroupHelper { const newOptionsObject = { outputOptions: {}, options: {}, - processingMessageBuffer: [], }; if (!moduleObj) { @@ -148,11 +147,7 @@ class ConfigGroup extends GroupHelper { const configPath = resolve(process.cwd(), config); const configFiles = getConfigInfoFromFileName(configPath); if (!configFiles.length) { - this.opts.processingMessageBuffer.push({ - lvl: 'warn', - msg: `Configuration ${config} not found in ${configPath}`, - }); - return; + throw new ConfigError(`The specified config file doesn't exist in ${configPath}`); } const foundConfig = configFiles[0]; const resolvedConfig = this.requireConfig(foundConfig); @@ -187,7 +182,7 @@ class ConfigGroup extends GroupHelper { const newConfigPath = this.resolveFilePath(merge); if (!newConfigPath) { - throw new MergeError("The supplied merge config doesn't exist."); + throw new ConfigError("The supplied merge config doesn't exist.", 'MergeError'); } const configFiles = getConfigInfoFromFileName(newConfigPath); diff --git a/packages/webpack-cli/lib/utils/Compiler.js b/packages/webpack-cli/lib/utils/Compiler.js index 89c6b7126d2..691bff79e0a 100644 --- a/packages/webpack-cli/lib/utils/Compiler.js +++ b/packages/webpack-cli/lib/utils/Compiler.js @@ -68,7 +68,7 @@ class Compiler { } } - compilerCallback(err, stats, lastHash, options, outputOptions, processingMessageBuffer) { + compilerCallback(err, stats, lastHash, options, outputOptions) { const statsErrors = []; if (!outputOptions.watch || err) { @@ -94,23 +94,23 @@ class Compiler { statsErrors.push({ name: statErr.message, loc: errLoc }); }); } - return this.generateOutput(outputOptions, stats, statsErrors, processingMessageBuffer); + return this.generateOutput(outputOptions, stats, statsErrors); } } - async invokeCompilerInstance(lastHash, options, outputOptions, processingMessageBuffer) { + async invokeCompilerInstance(lastHash, options, outputOptions) { // eslint-disable-next-line no-async-promise-executor return new Promise(async (resolve) => { await this.compiler.run((err, stats) => { - const content = this.compilerCallback(err, stats, lastHash, options, outputOptions, processingMessageBuffer); + const content = this.compilerCallback(err, stats, lastHash, options, outputOptions); resolve(content); }); }); } - async invokeWatchInstance(lastHash, options, outputOptions, watchOptions, processingMessageBuffer) { + async invokeWatchInstance(lastHash, options, outputOptions, watchOptions) { return this.compiler.watch(watchOptions, (err, stats) => { - return this.compilerCallback(err, stats, lastHash, options, outputOptions, processingMessageBuffer); + return this.compilerCallback(err, stats, lastHash, options, outputOptions); }); } @@ -131,7 +131,7 @@ class Compiler { } async webpackInstance(opts) { - const { outputOptions, processingMessageBuffer, options } = opts; + const { outputOptions, options } = opts; const lastHash = null; const { ProgressPlugin } = webpack; @@ -141,7 +141,7 @@ class Compiler { if (outputOptions.interactive) { const interactive = require('./interactive'); - return interactive(options, outputOptions, processingMessageBuffer); + return interactive(options, outputOptions); } if (this.compiler.compilers) { @@ -160,9 +160,9 @@ class Compiler { }); process.stdin.resume(); } - await this.invokeWatchInstance(lastHash, options, outputOptions, watchOptions, processingMessageBuffer); + await this.invokeWatchInstance(lastHash, options, outputOptions, watchOptions); } else { - return await this.invokeCompilerInstance(lastHash, options, outputOptions, processingMessageBuffer); + return await this.invokeCompilerInstance(lastHash, options, outputOptions); } } } diff --git a/packages/webpack-cli/lib/utils/GroupHelper.js b/packages/webpack-cli/lib/utils/GroupHelper.js index e683128e8b1..f7e539533eb 100644 --- a/packages/webpack-cli/lib/utils/GroupHelper.js +++ b/packages/webpack-cli/lib/utils/GroupHelper.js @@ -7,7 +7,6 @@ class GroupHelper { this.opts = { outputOptions: {}, options: {}, - processingMessageBuffer: [], }; this.strategy = undefined; } diff --git a/packages/webpack-cli/lib/utils/errors/ConfigError.js b/packages/webpack-cli/lib/utils/errors/ConfigError.js new file mode 100644 index 00000000000..3a7539c21bc --- /dev/null +++ b/packages/webpack-cli/lib/utils/errors/ConfigError.js @@ -0,0 +1,11 @@ +class ConfigError extends Error { + constructor(message, name) { + super(message); + this.name = name || 'ConfigError'; + // No need to show stack trace for known errors + this.stack = ''; + process.exitCode = 2; + } +} + +module.exports = ConfigError; diff --git a/packages/webpack-cli/lib/utils/errors/MergeError.js b/packages/webpack-cli/lib/utils/errors/MergeError.js deleted file mode 100644 index 74c39efd6e6..00000000000 --- a/packages/webpack-cli/lib/utils/errors/MergeError.js +++ /dev/null @@ -1,10 +0,0 @@ -class MergeError extends Error { - constructor(message) { - super(message); - this.name = 'MergeError'; - // No need to show stack trace for known errors - this.stack = ''; - } -} - -module.exports = MergeError; diff --git a/packages/webpack-cli/lib/utils/interactive.js b/packages/webpack-cli/lib/utils/interactive.js index ba1317291a4..e18b5c3ebbf 100644 --- a/packages/webpack-cli/lib/utils/interactive.js +++ b/packages/webpack-cli/lib/utils/interactive.js @@ -96,7 +96,7 @@ const ENTER_KEY = '\n'; const B_KEY = 'b'; const C_KEY = 'c'; -module.exports = async function (config, outputOptions, processingMessageBuffer) { +module.exports = async function (config, outputOptions) { const stdin = process.stdin; stdin.setEncoding('utf-8'); stdin.setRawMode(true); @@ -104,7 +104,7 @@ module.exports = async function (config, outputOptions, processingMessageBuffer) outputOptions.interactive = false; - const webpackCompilation = await webpack({ options: config, outputOptions, processingMessageBuffer }); + const webpackCompilation = await webpack({ options: config, outputOptions }); /* if(errors) { Hngggg } */ @@ -164,7 +164,7 @@ module.exports = async function (config, outputOptions, processingMessageBuffer) if (state.length) { state.pop(); } - const webpackCompilation = await webpack({ options: config, outputOptions, processingMessageBuffer }); + const webpackCompilation = await webpack({ options: config, outputOptions }); state.push(webpackCompilation); informActions(); isSub = true; diff --git a/packages/webpack-cli/lib/webpack-cli.js b/packages/webpack-cli/lib/webpack-cli.js index a6f6909acf9..26e5cb5929d 100644 --- a/packages/webpack-cli/lib/webpack-cli.js +++ b/packages/webpack-cli/lib/webpack-cli.js @@ -12,7 +12,6 @@ class WebpackCLI extends GroupHelper { this.groupMap = new Map(); this.groups = []; this.args = {}; - this.processingMessageBuffer = []; this.compilation = new Compiler(); this.defaultEntry = 'index'; this.possibleFileNames = [ @@ -186,19 +185,6 @@ class WebpackCLI extends GroupHelper { } } - /** - * Responsible for updating the buffer - * - * @param {string[]} messageBuffer The current buffer message - * @private - * @returns {void} - */ - _mergeProcessingMessageBuffer(messageBuffer) { - if (messageBuffer) { - this.processingMessageBuffer = this.processingMessageBuffer.concat(...messageBuffer); - } - } - /** * It receives a group helper, it runs and it merges its result inside * the file result that will be passed to the compiler @@ -212,7 +198,6 @@ class WebpackCLI extends GroupHelper { const result = await groupHelper.run(); this._mergeOptionsToConfiguration(result.options, groupHelper.strategy); this._mergeOptionsToOutputConfiguration(result.outputOptions); - this._mergeProcessingMessageBuffer(result.processingMessageBuffer); } } @@ -270,7 +255,6 @@ class WebpackCLI extends GroupHelper { const webpack = await this.compilation.webpackInstance({ options: this.compilerConfiguration, outputOptions: this.outputConfiguration, - processingMessageBuffer: this.processingMessageBuffer, }); return webpack; } diff --git a/test/config/absent/a.js b/test/config/absent/a.js new file mode 100644 index 00000000000..8ac1838ebe9 --- /dev/null +++ b/test/config/absent/a.js @@ -0,0 +1 @@ +console.log('Zenitsu'); diff --git a/test/config/absent/config-absent.test.js b/test/config/absent/config-absent.test.js new file mode 100644 index 00000000000..51bbea08355 --- /dev/null +++ b/test/config/absent/config-absent.test.js @@ -0,0 +1,18 @@ +'use strict'; +const { existsSync } = require('fs'); +const { resolve } = require('path'); +const { run } = require('../../utils/test-utils'); + +describe('Config:', () => { + it('supplied config file is absent', () => { + const { stdout, stderr, exitCode } = run(__dirname, ['-c', resolve(__dirname, 'webpack.config.js')], false); + // should throw with correct exit code + expect(exitCode).toBe(2); + expect(stdout).toBeFalsy(); + const configPath = resolve(__dirname, 'webpack.config.js'); + // Should contain the correct error message + expect(stderr).toContain(`ConfigError: The specified config file doesn't exist in ${configPath}`); + // Should not bundle + expect(existsSync(resolve(__dirname, './binary/a.bundle.js'))).toBeFalsy(); + }); +}); diff --git a/test/config/absent/webpack.config-absent.js b/test/config/absent/webpack.config-absent.js new file mode 100644 index 00000000000..b58f8a91f0d --- /dev/null +++ b/test/config/absent/webpack.config-absent.js @@ -0,0 +1,9 @@ +const { resolve } = require('path'); + +module.exports = { + entry: './a.js', + output: { + path: resolve(__dirname, 'binary'), + filename: 'a.bundle.js', + }, +};