Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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!)
Expand Down
12 changes: 12 additions & 0 deletions lib/WebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,12 @@ class WebpackConfig {
} = {},
ruleCallback: OptionsCallback<webpack.RuleSetRule> = () => {}
) {
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(
Expand Down Expand Up @@ -1301,6 +1307,12 @@ class WebpackConfig {
} = {},
ruleCallback: OptionsCallback<webpack.RuleSetRule> = () => {}
) {
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(
Expand Down
16 changes: 16 additions & 0 deletions test/WebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down