diff --git a/CHANGELOG.md b/CHANGELOG.md index 779bc0eb..fce72ae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## Unreleased + +- Throw a helpful error when a callback is passed as the first argument of `configureImageRule()` or `configureFontRule()` instead of being silently ignored + ## 7.2.0 - Migrate internal code to TypeScript, ship package with type definitions (better DX and IDE support!) diff --git a/lib/WebpackConfig.ts b/lib/WebpackConfig.ts index 57bc7e8d..a9d5f706 100644 --- a/lib/WebpackConfig.ts +++ b/lib/WebpackConfig.ts @@ -1267,6 +1267,12 @@ class WebpackConfig { } = {}, ruleCallback: OptionsCallback = () => {} ) { + if (typeof options === 'function') { + throw new Error( + 'configureImageRule() expects an options object as its first argument. To pass only a callback, use configureImageRule({}, callback).' + ); + } + for (const optionKey of Object.keys(options)) { if (!(optionKey in this.imageRuleOptions)) { throw new Error( @@ -1301,6 +1307,12 @@ class WebpackConfig { } = {}, ruleCallback: OptionsCallback = () => {} ) { + if (typeof options === 'function') { + throw new Error( + 'configureFontRule() expects an options object as its first argument. To pass only a callback, use configureFontRule({}, callback).' + ); + } + for (const optionKey of Object.keys(options)) { if (!(optionKey in this.fontRuleOptions)) { throw new Error( diff --git a/test/WebpackConfig.js b/test/WebpackConfig.js index c7ee85d3..63e1e2ca 100644 --- a/test/WebpackConfig.js +++ b/test/WebpackConfig.js @@ -1446,6 +1446,14 @@ describe('WebpackConfig object', function () { config.configureImageRule({}, {}); }).toThrow('Argument 2 to configureImageRule() must be a callback'); }); + + it('Passing a callback as the 1st arg throws a helpful error', function () { + const config = createConfig(); + + expect(() => { + config.configureImageRule(() => {}); + }).toThrow('configureImageRule() expects an options object as its first argument'); + }); }); describe('configureFontRule', function () { @@ -1487,6 +1495,14 @@ describe('WebpackConfig object', function () { config.configureFontRule({}, {}); }).toThrow('Argument 2 to configureFontRule() must be a callback'); }); + + it('Passing a callback as the 1st arg throws a helpful error', function () { + const config = createConfig(); + + expect(() => { + config.configureFontRule(() => {}); + }).toThrow('configureFontRule() expects an options object as its first argument'); + }); }); describe('configureWatchOptions()', function () {