Skip to content

Commit 90a9ca0

Browse files
committed
feat: add MergeError calss
1 parent a875a61 commit 90a9ca0

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const { extensions } = require('interpret');
44
const webpackMerge = require('webpack-merge');
55
const GroupHelper = require('../utils/GroupHelper');
66
const rechoir = require('rechoir');
7-
const logger = require('../utils/logger');
7+
const MergeError = require('../utils/errors/MergeError');
88

99
// Order defines the priority, in increasing order
1010
// example - config file lookup will be in order of .webpack/webpack.config.development.js -> webpack.config.development.js -> webpack.config.js
@@ -174,8 +174,7 @@ class ConfigGroup extends GroupHelper {
174174
const newConfigPath = this.resolveFilePath(merge);
175175

176176
if (!newConfigPath) {
177-
logger.error("The supplied merge config doesn't exist.");
178-
process.exit(1);
177+
throw new MergeError("The supplied merge config doesn't exist.");
179178
}
180179

181180
const configFiles = getConfigInfoFromFileName(newConfigPath);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class MergeError extends Error {
2+
constructor(message) {
3+
super(message);
4+
this.name = 'MergeError';
5+
// No need to show stack trace for known errors
6+
this.stack = '';
7+
}
8+
}
9+
10+
module.exports = MergeError;

test/merge/config-absent/merge-config-absent.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe('merge flag configuration', () => {
1313
// Since the process will exit, nothing on stdout
1414
expect(stdout).toBeFalsy();
1515
// Confirm that the user is notified
16-
expect(stderr).toContain(`[webpack-cli] The supplied merge config doesn't exist.`);
16+
expect(stderr).toContain(`MergeError: The supplied merge config doesn't exist.`);
1717
// Default config would be used
1818
expect(fs.existsSync(join(__dirname, './dist/merged.js'))).toBeFalsy();
1919
// Since the process will exit so no compilation will be done

0 commit comments

Comments
 (0)