Skip to content

Commit b91afbf

Browse files
committed
feat: add RegExp support for test option
1 parent 1d4bd3e commit b91afbf

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/runtime/asyncChunkRetry.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,16 @@ function findMatchingRule(url: string): RuntimeRetryOptions {
104104
// Check test condition
105105
let tester = rule.test;
106106
if (tester) {
107-
if (typeof tester === 'string') {
108-
const regexp = new RegExp(tester);
109-
tester = (str: string) => regexp.test(str);
107+
if (tester instanceof RegExp) {
108+
if (!tester.test(url)) continue;
109+
} else if (typeof tester === 'string') {
110+
const regexp = new RegExp(tester);
111+
tester = (str: string) => regexp.test(str);
110112
}
111-
if (typeof tester !== 'function' || !tester(url)) {
112-
continue;
113-
}
114-
}
113+
if (typeof tester === 'function' && !tester(url)) {
114+
continue;
115+
}
116+
}
115117

116118
// Check domain condition
117119
const domain = findCurrentDomain(url, rule.domain || []);

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export type PluginAssetsRetryOptions = {
1414
/**
1515
* The test function of the asset to be retried.
1616
*/
17-
test?: string | ((url: string) => boolean);
17+
test?: string | RegExp | ((url: string) => boolean);
1818
/**
1919
* Specifies the retry domain when assets fail to load.
2020
*/

0 commit comments

Comments
 (0)