@rsbuild/plugin-assets-retry 1.2.3 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,251 +1,218 @@
1
- // rsbuild/runtime/async-chunk-retry
2
- // init retryCollector and nextRetry function
3
- var config = __RETRY_OPTIONS__;
4
- var maxRetries = config.max || 3;
5
- var retryCollector = {};
6
- var retryCssCollector = {};
7
- function findCurrentDomain(url) {
8
- var domains = config.domain || [];
9
- var domain = '';
10
- for(var i = 0; i < domains.length; i++){
11
- if (url.indexOf(domains[i]) !== -1) {
12
- domain = domains[i];
13
- break;
1
+ (function() {
2
+ "use strict";
3
+ var ERROR_PREFIX = '[@rsbuild/plugin-assets-retry] ';
4
+ function findCurrentDomain(url, config) {
5
+ var domains = config.domain;
6
+ for(var i = 0; i < domains.length; i++){
7
+ var domain = domains[i];
8
+ if (-1 !== url.indexOf(domain)) return domain;
14
9
  }
10
+ return window.origin;
15
11
  }
16
- return domain || window.origin;
17
- }
18
- function findNextDomain(url) {
19
- var domains = config.domain || [];
20
- var currentDomain = findCurrentDomain(url);
21
- var index = domains.indexOf(currentDomain);
22
- return domains[(index + 1) % domains.length] || url;
23
- }
24
- var postfixRE = /[?#].*$/;
25
- function cleanUrl(url) {
26
- return url.replace(postfixRE, '');
27
- }
28
- function getQueryFromUrl(url) {
29
- var parts = url.split('?')[1];
30
- return parts ? "?".concat(parts.split('#')[0]) : '';
31
- }
32
- function getUrlRetryQuery(existRetryTimes, originalQuery) {
33
- if (config.addQuery === true) {
34
- return originalQuery !== '' ? "".concat(originalQuery, "&retry=").concat(existRetryTimes) : "?retry=".concat(existRetryTimes);
12
+ function findNextDomain(url, config) {
13
+ var domains = config.domain;
14
+ var currentDomain = findCurrentDomain(url, config);
15
+ var index = domains.indexOf(currentDomain);
16
+ return -1 === index ? currentDomain : domains[(index + 1) % domains.length];
35
17
  }
36
- if (typeof config.addQuery === 'function') {
37
- return config.addQuery({
18
+ var postfixRE = /[?#].*$/;
19
+ function cleanUrl(url) {
20
+ return url.replace(postfixRE, '');
21
+ }
22
+ function getQueryFromUrl(url) {
23
+ var parts = url.split('?')[1];
24
+ return parts ? "?".concat(parts.split('#')[0]) : '';
25
+ }
26
+ function getUrlRetryQuery(existRetryTimes, originalQuery, config) {
27
+ if (true === config.addQuery) return '' !== originalQuery ? "".concat(originalQuery, "&retry=").concat(existRetryTimes) : "?retry=".concat(existRetryTimes);
28
+ if ('function' == typeof config.addQuery) return config.addQuery({
38
29
  times: existRetryTimes,
39
30
  originalQuery: originalQuery
40
31
  });
32
+ return '';
41
33
  }
42
- return '';
43
- }
44
- function getNextRetryUrl(currRetryUrl, domain, nextDomain, existRetryTimes, originalQuery) {
45
- return cleanUrl(currRetryUrl.replace(domain, nextDomain)) + getUrlRetryQuery(existRetryTimes + 1, originalQuery);
46
- }
47
- // shared between ensureChunk and loadScript
48
- var globalCurrRetrying = {};
49
- // shared between ensureChunk and loadStyleSheet
50
- var globalCurrRetryingCss = {};
51
- function getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
52
- var _retryCssCollector_chunkId, _retryCollector_chunkId;
53
- return isCssAsyncChunk ? (_retryCssCollector_chunkId = retryCssCollector[chunkId]) === null || _retryCssCollector_chunkId === void 0 ? void 0 : _retryCssCollector_chunkId[existRetryTimes] : (_retryCollector_chunkId = retryCollector[chunkId]) === null || _retryCollector_chunkId === void 0 ? void 0 : _retryCollector_chunkId[existRetryTimes];
54
- }
55
- function initRetry(chunkId, isCssAsyncChunk) {
56
- var originalScriptFilename = isCssAsyncChunk ? originalGetCssFilename(chunkId) : originalGetChunkScriptFilename(chunkId);
57
- if (!originalScriptFilename) {
58
- throw new Error('only support cssExtract');
34
+ function getNextRetryUrl(currRetryUrl, domain, nextDomain, existRetryTimes, originalQuery, config) {
35
+ return cleanUrl(currRetryUrl.replace(domain, nextDomain)) + getUrlRetryQuery(existRetryTimes + 1, originalQuery, config);
59
36
  }
60
- var originalPublicPath = __RUNTIME_GLOBALS_PUBLIC_PATH__;
61
- var originalSrcUrl = originalPublicPath[0] === '/' && originalPublicPath[1] !== '/' ? window.origin + originalPublicPath + originalScriptFilename : originalPublicPath + originalScriptFilename;
62
- var originalQuery = getQueryFromUrl(originalSrcUrl);
63
- var existRetryTimes = 0;
64
- var nextDomain = findCurrentDomain(originalSrcUrl);
65
- return {
66
- nextDomain: nextDomain,
67
- nextRetryUrl: getNextRetryUrl(originalSrcUrl, nextDomain, nextDomain, existRetryTimes, originalQuery),
68
- originalScriptFilename: originalScriptFilename,
69
- originalSrcUrl: originalSrcUrl,
70
- originalQuery: originalQuery
71
- };
72
- }
73
- function nextRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
74
- var currRetry = getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk);
75
- var nextRetry;
76
- var nextExistRetryTimes = existRetryTimes + 1;
77
- if (existRetryTimes === 0 || currRetry === undefined) {
78
- nextRetry = initRetry(chunkId, isCssAsyncChunk);
79
- if (isCssAsyncChunk) {
80
- retryCssCollector[chunkId] = [];
81
- } else {
82
- retryCollector[chunkId] = [];
37
+ function _instanceof(left, right) {
38
+ if (null != right && "undefined" != typeof Symbol && right[Symbol.hasInstance]) return !!right[Symbol.hasInstance](left);
39
+ return left instanceof right;
40
+ }
41
+ function findMatchingRule(url, type, rules) {
42
+ for(var i = 0; i < rules.length; i++){
43
+ var rule = rules[i];
44
+ var tester = rule.test;
45
+ var shouldMatch = true;
46
+ if (_instanceof(tester, RegExp)) shouldMatch = tester.test(url);
47
+ else if ('string' == typeof tester) {
48
+ var regexp = new RegExp(tester);
49
+ shouldMatch = regexp.test(url);
50
+ } else if ('function' == typeof tester) shouldMatch = tester(url);
51
+ if (rule.domain && rule.domain.length > 0) {
52
+ var domain = findCurrentDomain(url, rule);
53
+ if (!rule.domain.includes(domain)) shouldMatch = false;
54
+ }
55
+ if (rule.type && rule.type.length > 0) {
56
+ if (!rule.type.includes(type)) shouldMatch = false;
57
+ }
58
+ if (shouldMatch) return rule;
83
59
  }
84
- } else {
85
- var originalScriptFilename = currRetry.originalScriptFilename, originalSrcUrl = currRetry.originalSrcUrl, originalQuery = currRetry.originalQuery;
86
- var nextDomain = findNextDomain(currRetry.nextDomain);
87
- nextRetry = {
60
+ return null;
61
+ }
62
+ var asyncChunkRetry_rules = __RETRY_OPTIONS__;
63
+ var retryCollector = {};
64
+ var retryCssCollector = {};
65
+ var globalCurrRetrying = {};
66
+ var globalCurrRetryingCss = {};
67
+ function getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
68
+ var _retryCssCollector_chunkId, _retryCollector_chunkId;
69
+ return isCssAsyncChunk ? null == (_retryCssCollector_chunkId = retryCssCollector[chunkId]) ? void 0 : _retryCssCollector_chunkId[existRetryTimes] : null == (_retryCollector_chunkId = retryCollector[chunkId]) ? void 0 : _retryCollector_chunkId[existRetryTimes];
70
+ }
71
+ function initRetry(chunkId, isCssAsyncChunk) {
72
+ var originalScriptFilename = isCssAsyncChunk ? originalGetCssFilename(chunkId) : originalGetChunkScriptFilename(chunkId);
73
+ if (!originalScriptFilename) throw new Error('only support cssExtract');
74
+ var originalPublicPath = __RUNTIME_GLOBALS_PUBLIC_PATH__;
75
+ var originalSrcUrl = '/' === originalPublicPath[0] && '/' !== originalPublicPath[1] ? window.origin + originalPublicPath + originalScriptFilename : originalPublicPath + originalScriptFilename;
76
+ var originalQuery = getQueryFromUrl(originalSrcUrl);
77
+ var existRetryTimes = 0;
78
+ var tagName = isCssAsyncChunk ? 'link' : "script";
79
+ var rule = findMatchingRule(originalSrcUrl, tagName, asyncChunkRetry_rules);
80
+ if (!rule) return null;
81
+ var nextDomain = findCurrentDomain(originalSrcUrl, rule);
82
+ return {
88
83
  nextDomain: nextDomain,
89
- nextRetryUrl: getNextRetryUrl(currRetry.nextRetryUrl, currRetry.nextDomain, nextDomain, existRetryTimes, originalQuery),
84
+ nextRetryUrl: getNextRetryUrl(originalSrcUrl, nextDomain, nextDomain, existRetryTimes, originalQuery, rule),
90
85
  originalScriptFilename: originalScriptFilename,
91
86
  originalSrcUrl: originalSrcUrl,
92
- originalQuery: originalQuery
87
+ originalQuery: originalQuery,
88
+ rule: rule
93
89
  };
94
90
  }
95
- if (isCssAsyncChunk) {
96
- retryCssCollector[chunkId][nextExistRetryTimes] = nextRetry;
97
- globalCurrRetryingCss[chunkId] = nextRetry;
98
- } else {
99
- retryCollector[chunkId][nextExistRetryTimes] = nextRetry;
100
- globalCurrRetrying[chunkId] = nextRetry;
91
+ function asyncChunkRetry_nextRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
92
+ var currRetry = getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk);
93
+ var nextRetry;
94
+ var nextExistRetryTimes = existRetryTimes + 1;
95
+ if (0 === existRetryTimes || void 0 === currRetry) {
96
+ nextRetry = initRetry(chunkId, isCssAsyncChunk);
97
+ if (!nextRetry) return null;
98
+ if (isCssAsyncChunk) retryCssCollector[chunkId] = [];
99
+ else retryCollector[chunkId] = [];
100
+ } else {
101
+ var originalScriptFilename = currRetry.originalScriptFilename, originalSrcUrl = currRetry.originalSrcUrl, originalQuery = currRetry.originalQuery, rule = currRetry.rule;
102
+ var nextDomain = findNextDomain(currRetry.nextDomain, rule);
103
+ nextRetry = {
104
+ nextDomain: nextDomain,
105
+ nextRetryUrl: getNextRetryUrl(currRetry.nextRetryUrl, currRetry.nextDomain, nextDomain, existRetryTimes, originalQuery, rule),
106
+ originalScriptFilename: originalScriptFilename,
107
+ originalSrcUrl: originalSrcUrl,
108
+ originalQuery: originalQuery,
109
+ rule: rule
110
+ };
111
+ }
112
+ if (isCssAsyncChunk) {
113
+ retryCssCollector[chunkId][nextExistRetryTimes] = nextRetry;
114
+ globalCurrRetryingCss[chunkId] = nextRetry;
115
+ } else {
116
+ retryCollector[chunkId][nextExistRetryTimes] = nextRetry;
117
+ globalCurrRetrying[chunkId] = nextRetry;
118
+ }
119
+ return nextRetry;
101
120
  }
102
- return nextRetry;
103
- }
104
- // rewrite webpack runtime with nextRetry()
105
- var originalEnsureChunk = __RUNTIME_GLOBALS_ENSURE_CHUNK__;
106
- var originalGetChunkScriptFilename = __RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__;
107
- var originalGetCssFilename = __RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__ || __RUNTIME_GLOBALS_GET_CSS_FILENAME__ || function() {
108
- return null;
109
- };
110
- var originalLoadScript = __RUNTIME_GLOBALS_LOAD_SCRIPT__;
111
- var ERROR_PREFIX = '[@rsbuild/plugin-assets-retry] ';
112
- // if users want to support es5, add Promise polyfill first https://github.com/webpack/webpack/issues/12877
113
- function ensureChunk(chunkId) {
114
- // biome-ignore lint/style/noArguments: allowed
115
- var args = Array.prototype.slice.call(arguments);
116
- // Other webpack runtimes would add arguments for `__webpack_require__.e`,
117
- // So we use `arguments[10]` to avoid conflicts with other runtimes
118
- if (!args[10]) {
119
- args[10] = {
121
+ var originalEnsureChunk = __RUNTIME_GLOBALS_ENSURE_CHUNK__;
122
+ var originalGetChunkScriptFilename = __RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__;
123
+ var originalGetCssFilename = __RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__ || __RUNTIME_GLOBALS_GET_CSS_FILENAME__ || function() {
124
+ return null;
125
+ };
126
+ var originalLoadScript = __RUNTIME_GLOBALS_LOAD_SCRIPT__;
127
+ function ensureChunk(chunkId) {
128
+ var args = Array.prototype.slice.call(arguments);
129
+ if (!args[10]) args[10] = {
120
130
  count: 0,
121
131
  cssFailedCount: 0
122
132
  };
123
- }
124
- var callingCounter = args[10];
125
- var result = originalEnsureChunk.apply(null, args);
126
- try {
127
- var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
128
- var originalCssFilename = originalGetCssFilename(chunkId);
129
- // mark the async chunk name in the global variables and share it with initial chunk retry to avoid duplicate retrying
130
- if (typeof window !== 'undefined') {
131
- if (originalScriptFilename) {
132
- window.__RB_ASYNC_CHUNKS__[originalScriptFilename] = true;
133
- }
134
- if (originalCssFilename) {
135
- window.__RB_ASYNC_CHUNKS__[originalCssFilename] = true;
136
- }
137
- }
138
- } catch (e) {
139
- console.error(ERROR_PREFIX, 'get original script or CSS filename error', e);
140
- }
141
- // if __webpack_require__.e is polluted by other runtime codes, fallback to originalEnsureChunk
142
- if (!callingCounter || typeof callingCounter.count !== 'number' || typeof callingCounter.cssFailedCount !== 'number') {
143
- return result;
144
- }
145
- callingCounter.count += 1;
146
- return result.catch(function(error) {
147
- var _error_message;
148
- // the first calling is not retry
149
- // if the failed request is 4 in network panel, callingCounter.count === 4, the first one is the normal request, and existRetryTimes is 3, retried 3 times
150
- var existRetryTimesAll = callingCounter.count - 1;
151
- var cssExistRetryTimes = callingCounter.cssFailedCount;
152
- var jsExistRetryTimes = existRetryTimesAll - cssExistRetryTimes;
153
- var originalScriptFilename;
154
- var nextRetryUrl;
155
- var nextDomain;
156
- var isCssAsyncChunkLoadFailed = Boolean(error === null || error === void 0 ? void 0 : (_error_message = error.message) === null || _error_message === void 0 ? void 0 : _error_message.includes('CSS chunk'));
157
- if (isCssAsyncChunkLoadFailed) {
158
- callingCounter.cssFailedCount += 1;
159
- }
160
- var existRetryTimes = isCssAsyncChunkLoadFailed ? cssExistRetryTimes : jsExistRetryTimes;
133
+ var callingCounter = args[10];
134
+ var result = originalEnsureChunk.apply(null, args);
161
135
  try {
162
- var retryResult = nextRetry(chunkId, existRetryTimes, isCssAsyncChunkLoadFailed);
163
- originalScriptFilename = retryResult.originalScriptFilename;
164
- nextRetryUrl = retryResult.nextRetryUrl;
165
- nextDomain = retryResult.nextDomain;
136
+ var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
137
+ var originalCssFilename = originalGetCssFilename(chunkId);
138
+ if ('undefined' != typeof window) {
139
+ if (originalScriptFilename) window.__RB_ASYNC_CHUNKS__[originalScriptFilename] = true;
140
+ if (originalCssFilename) window.__RB_ASYNC_CHUNKS__[originalCssFilename] = true;
141
+ }
166
142
  } catch (e) {
167
- console.error(ERROR_PREFIX, 'failed to get nextRetryUrl', e);
168
- throw error;
143
+ console.error(ERROR_PREFIX, "get original script or CSS filename error", e);
169
144
  }
170
- var createContext = function(times) {
171
- return {
172
- times: times,
173
- domain: nextDomain,
174
- url: nextRetryUrl,
175
- tagName: isCssAsyncChunkLoadFailed ? 'link' : 'script',
176
- isAsyncChunk: true
177
- };
178
- };
179
- var context = createContext(existRetryTimes);
180
- if (existRetryTimes >= maxRetries) {
181
- var _error_message1;
182
- error.message = ((_error_message1 = error.message) === null || _error_message1 === void 0 ? void 0 : _error_message1.includes('retries:')) ? error.message : "Loading chunk ".concat(chunkId, ' from "').concat(originalScriptFilename, '" failed after ').concat(maxRetries, ' retries: "').concat(error.message, '"');
183
- if (typeof config.onFail === 'function') {
184
- config.onFail(context);
145
+ if (!callingCounter || 'number' != typeof callingCounter.count || 'number' != typeof callingCounter.cssFailedCount) return result;
146
+ callingCounter.count += 1;
147
+ return result["catch"](function(error) {
148
+ var _error_message;
149
+ var existRetryTimesAll = callingCounter.count - 1;
150
+ var cssExistRetryTimes = callingCounter.cssFailedCount;
151
+ var jsExistRetryTimes = existRetryTimesAll - cssExistRetryTimes;
152
+ var originalScriptFilename;
153
+ var nextRetryUrl;
154
+ var nextDomain;
155
+ var rule;
156
+ var isCssAsyncChunkLoadFailed = Boolean(null == error ? void 0 : null == (_error_message = error.message) ? void 0 : _error_message.includes('CSS chunk'));
157
+ if (isCssAsyncChunkLoadFailed) callingCounter.cssFailedCount += 1;
158
+ var existRetryTimes = isCssAsyncChunkLoadFailed ? cssExistRetryTimes : jsExistRetryTimes;
159
+ try {
160
+ var retryResult = asyncChunkRetry_nextRetry(chunkId, existRetryTimes, isCssAsyncChunkLoadFailed);
161
+ if (!retryResult) throw error;
162
+ originalScriptFilename = retryResult.originalScriptFilename;
163
+ nextRetryUrl = retryResult.nextRetryUrl;
164
+ nextDomain = retryResult.nextDomain;
165
+ rule = retryResult.rule;
166
+ } catch (e) {
167
+ if (e !== error) console.error(ERROR_PREFIX, 'failed to get nextRetryUrl', e);
168
+ throw error;
185
169
  }
186
- throw error;
187
- }
188
- // Filter by config.test and config.domain
189
- var tester = config.test;
190
- if (tester) {
191
- if (typeof tester === 'string') {
192
- var regexp = new RegExp(tester);
193
- tester = function(str) {
194
- return regexp.test(str);
170
+ var createContext = function(times) {
171
+ return {
172
+ times: times,
173
+ domain: nextDomain,
174
+ url: nextRetryUrl,
175
+ tagName: isCssAsyncChunkLoadFailed ? 'link' : "script",
176
+ isAsyncChunk: true
195
177
  };
196
- }
197
- if (typeof tester !== 'function' || !tester(nextRetryUrl)) {
178
+ };
179
+ var context = createContext(existRetryTimes);
180
+ if (existRetryTimes >= rule.max) {
181
+ var _error_message1;
182
+ error.message = (null == (_error_message1 = error.message) ? void 0 : _error_message1.includes('retries:')) ? error.message : "Loading chunk ".concat(chunkId, ' from "').concat(originalScriptFilename, '" failed after ').concat(rule.max, ' retries: "').concat(error.message, '"');
183
+ if ('function' == typeof rule.onFail) rule.onFail(context);
198
184
  throw error;
199
185
  }
200
- }
201
- if (config.domain && config.domain.indexOf(nextDomain) === -1) {
202
- throw error;
203
- }
204
- // Start retry
205
- if (typeof config.onRetry === 'function') {
206
- config.onRetry(context);
207
- }
208
- var _config_delay;
209
- var delayTime = typeof config.delay === 'function' ? config.delay(context) : (_config_delay = config.delay) !== null && _config_delay !== void 0 ? _config_delay : 0;
210
- var delayPromise = delayTime > 0 ? new Promise(function(resolve) {
211
- return setTimeout(resolve, delayTime);
212
- }) : Promise.resolve();
213
- return delayPromise.then(function() {
214
- return ensureChunk.apply(ensureChunk, args);
215
- }).then(function(result) {
216
- // when after retrying the third time
217
- // ensureChunk(chunkId, { count: 3 }), at that time, existRetryTimes === 2
218
- // at the end, callingCounter.count is 4
219
- var isLastSuccessRetry = (callingCounter === null || callingCounter === void 0 ? void 0 : callingCounter.count) === existRetryTimesAll + 2;
220
- if (typeof config.onSuccess === 'function' && isLastSuccessRetry) {
221
- var context = createContext(existRetryTimes + 1);
222
- config.onSuccess(context);
223
- }
224
- return result;
186
+ if ('function' == typeof rule.onRetry) rule.onRetry(context);
187
+ var delayTime = 'function' == typeof rule.delay ? rule.delay(context) : rule.delay;
188
+ var delayPromise = delayTime > 0 ? new Promise(function(resolve) {
189
+ return setTimeout(resolve, delayTime);
190
+ }) : Promise.resolve();
191
+ return delayPromise.then(function() {
192
+ return ensureChunk.apply(ensureChunk, args);
193
+ }).then(function(result) {
194
+ var isLastSuccessRetry = (null == callingCounter ? void 0 : callingCounter.count) === existRetryTimesAll + 2;
195
+ if ('function' == typeof rule.onSuccess && isLastSuccessRetry) {
196
+ var context = createContext(existRetryTimes + 1);
197
+ rule.onSuccess(context);
198
+ }
199
+ return result;
200
+ });
225
201
  });
226
- });
227
- }
228
- function loadScript() {
229
- // biome-ignore lint/style/noArguments: allowed
230
- var args = Array.prototype.slice.call(arguments);
231
- var retry = globalCurrRetrying[args[3]];
232
- if (retry) {
233
- args[0] = retry.nextRetryUrl;
234
202
  }
235
- return originalLoadScript.apply(null, args);
236
- }
237
- function loadStyleSheet(href, chunkId) {
238
- var retry = globalCurrRetryingCss[chunkId];
239
- return(// biome-ignore lint/complexity/useOptionalChain: for less code
240
- retry && retry.nextRetryUrl || __RUNTIME_GLOBALS_PUBLIC_PATH__ + href);
241
- }
242
- function registerAsyncChunkRetry() {
243
- // init global variables shared between initial-chunk-retry and async-chunk-retry
244
- if (typeof window !== 'undefined' && !window.__RB_ASYNC_CHUNKS__) {
245
- window.__RB_ASYNC_CHUNKS__ = {};
203
+ function loadScript() {
204
+ var args = Array.prototype.slice.call(arguments);
205
+ var retry = globalCurrRetrying[args[3]];
206
+ if (retry) args[0] = retry.nextRetryUrl;
207
+ return originalLoadScript.apply(null, args);
246
208
  }
247
- if (typeof __RUNTIME_GLOBALS_REQUIRE__ !== 'undefined') {
248
- try {
209
+ function loadStyleSheet(href, chunkId) {
210
+ var retry = globalCurrRetryingCss[chunkId];
211
+ return retry && retry.nextRetryUrl || __RUNTIME_GLOBALS_PUBLIC_PATH__ + href;
212
+ }
213
+ function registerAsyncChunkRetry() {
214
+ if ('undefined' != typeof window && !window.__RB_ASYNC_CHUNKS__) window.__RB_ASYNC_CHUNKS__ = {};
215
+ if ('undefined' != typeof __RUNTIME_GLOBALS_REQUIRE__) try {
249
216
  __RUNTIME_GLOBALS_ENSURE_CHUNK__ = ensureChunk;
250
217
  __RUNTIME_GLOBALS_LOAD_SCRIPT__ = loadScript;
251
218
  __RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__ = loadStyleSheet;
@@ -253,5 +220,5 @@ function registerAsyncChunkRetry() {
253
220
  console.error(ERROR_PREFIX, 'Register async chunk retry runtime failed', e);
254
221
  }
255
222
  }
256
- }
257
- registerAsyncChunkRetry();
223
+ registerAsyncChunkRetry();
224
+ })();
@@ -1 +1 @@
1
- var n=__RETRY_OPTIONS__,r=n.max||3,e={},t={};function i(r){for(var e=n.domain||[],t="",i=0;i<e.length;i++)if(-1!==r.indexOf(e[i])){t=e[i];break}return t||window.origin}var o=/[?#].*$/;function _(r,e,t,i,_){var a;return r.replace(e,t).replace(o,"")+(a=i+1,!0===n.addQuery?""!==_?"".concat(_,"&retry=").concat(a):"?retry=".concat(a):"function"==typeof n.addQuery?n.addQuery({times:a,originalQuery:_}):"")}var a={},l={},c=__RUNTIME_GLOBALS_ENSURE_CHUNK__,u=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,s=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||function(){return null},f=__RUNTIME_GLOBALS_LOAD_SCRIPT__,d="[@rsbuild/plugin-assets-retry] ";function y(o){var f=Array.prototype.slice.call(arguments);f[10]||(f[10]={count:0,cssFailedCount:0});var S=f[10],R=c.apply(null,f);try{var p=u(o),E=s(o);"undefined"!=typeof window&&(p&&(window.__RB_ASYNC_CHUNKS__[p]=!0),E&&(window.__RB_ASYNC_CHUNKS__[E]=!0))}catch(n){console.error(d,"get original script or CSS filename error",n)}return S&&"number"==typeof S.count&&"number"==typeof S.cssFailedCount?(S.count+=1,R.catch(function(c){var R,p,E,U,L,m,v=S.count-1,N=S.cssFailedCount,g=!!(null==c||null==(R=c.message)?void 0:R.includes("CSS chunk"));g&&(S.cssFailedCount+=1);var A=g?N:v-N;try{var C=function(r,o,c){var f,d,y,S=c?null==(f=t[r])?void 0:f[o]:null==(d=e[r])?void 0:d[o],R=o+1;if(0===o||void 0===S)y=function(n,r){var e,t=r?s(n):u(n);if(!t)throw Error("only support cssExtract");var o=__RUNTIME_GLOBALS_PUBLIC_PATH__,a="/"===o[0]&&"/"!==o[1]?window.origin+o+t:o+t,l=(e=a.split("?")[1])?"?".concat(e.split("#")[0]):"",c=i(a);return{nextDomain:c,nextRetryUrl:_(a,c,c,0,l),originalScriptFilename:t,originalSrcUrl:a,originalQuery:l}}(r,c),c?t[r]=[]:e[r]=[];else{var p,E,U,L,m=S.originalScriptFilename,v=S.originalSrcUrl,N=S.originalQuery,g=(p=S.nextDomain,E=n.domain||[],U=i(p),L=E.indexOf(U),E[(L+1)%E.length]||p);y={nextDomain:g,nextRetryUrl:_(S.nextRetryUrl,S.nextDomain,g,o,N),originalScriptFilename:m,originalSrcUrl:v,originalQuery:N}}return c?(t[r][R]=y,l[r]=y):(e[r][R]=y,a[r]=y),y}(o,A,g);p=C.originalScriptFilename,E=C.nextRetryUrl,U=C.nextDomain}catch(n){throw console.error(d,"failed to get nextRetryUrl",n),c}var T=function(n){return{times:n,domain:U,url:E,tagName:g?"link":"script",isAsyncChunk:!0}},I=T(A);if(A>=r)throw c.message=(null==(L=c.message)?void 0:L.includes("retries:"))?c.message:"Loading chunk ".concat(o,' from "').concat(p,'" failed after ').concat(r,' retries: "').concat(c.message,'"'),"function"==typeof n.onFail&&n.onFail(I),c;var w=n.test;if(w){if("string"==typeof w){var O=new RegExp(w);w=function(n){return O.test(n)}}if("function"!=typeof w||!w(E))throw c}if(n.domain&&-1===n.domain.indexOf(U))throw c;"function"==typeof n.onRetry&&n.onRetry(I);var x="function"==typeof n.delay?n.delay(I):null!=(m=n.delay)?m:0;return(x>0?new Promise(function(n){return setTimeout(n,x)}):Promise.resolve()).then(function(){return y.apply(y,f)}).then(function(r){var e=(null==S?void 0:S.count)===v+2;if("function"==typeof n.onSuccess&&e){var t=T(A+1);n.onSuccess(t)}return r})})):R}if("undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={}),"undefined"!=typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=y,__RUNTIME_GLOBALS_LOAD_SCRIPT__=function(){var n=Array.prototype.slice.call(arguments),r=a[n[3]];return r&&(n[0]=r.nextRetryUrl),f.apply(null,n)},__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__=function(n,r){var e=l[r];return e&&e.nextRetryUrl||__RUNTIME_GLOBALS_PUBLIC_PATH__+n}}catch(n){console.error(d,"Register async chunk retry runtime failed",n)}
1
+ !function(){"use strict";var n="[@rsbuild/plugin-assets-retry] ";function r(n,r){for(var e=r.domain,t=0;t<e.length;t++){var i=e[t];if(-1!==n.indexOf(i))return i}return window.origin}var e=/[?#].*$/;function t(n,r,t,i,o,_){var a;return n.replace(r,t).replace(e,"")+(a=i+1,!0===_.addQuery?""!==o?"".concat(o,"&retry=").concat(a):"?retry=".concat(a):"function"==typeof _.addQuery?_.addQuery({times:a,originalQuery:o}):"")}var i=__RETRY_OPTIONS__,o={},_={},a={},l={},u=__RUNTIME_GLOBALS_ENSURE_CHUNK__,c=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,s=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||function(){return null},f=__RUNTIME_GLOBALS_LOAD_SCRIPT__;function y(e){var f=Array.prototype.slice.call(arguments);f[10]||(f[10]={count:0,cssFailedCount:0});var d=f[10],S=u.apply(null,f);try{var p=c(e),R=s(e);"undefined"!=typeof window&&(p&&(window.__RB_ASYNC_CHUNKS__[p]=!0),R&&(window.__RB_ASYNC_CHUNKS__[R]=!0))}catch(r){console.error(n,"get original script or CSS filename error",r)}return d&&"number"==typeof d.count&&"number"==typeof d.cssFailedCount?(d.count+=1,S.catch(function(u){var S,p,R,m,E,U,g=d.count-1,v=d.cssFailedCount,L=!!(null==u||null==(S=u.message)?void 0:S.includes("CSS chunk"));L&&(d.cssFailedCount+=1);var N=L?v:g-v;try{var A=function(n,e,u){var f,y,d,S=u?null==(f=_[n])?void 0:f[e]:null==(y=o[n])?void 0:y[e],p=e+1;if(0===e||void 0===S){if(!(d=function(n,e){var o,_=e?s(n):c(n);if(!_)throw Error("only support cssExtract");var a=__RUNTIME_GLOBALS_PUBLIC_PATH__,l="/"===a[0]&&"/"!==a[1]?window.origin+a+_:a+_,u=(o=l.split("?")[1])?"?".concat(o.split("#")[0]):"",f=function(n,e,t){for(var i=0;i<t.length;i++){var o,_=t[i],a=_.test,l=!0;if((null!=(o=RegExp)&&"undefined"!=typeof Symbol&&o[Symbol.hasInstance]?!!o[Symbol.hasInstance](a):a instanceof o)?l=a.test(n):"string"==typeof a?l=new RegExp(a).test(n):"function"==typeof a&&(l=a(n)),_.domain&&_.domain.length>0){var u=r(n,_);_.domain.includes(u)||(l=!1)}if(_.type&&_.type.length>0&&!_.type.includes(e)&&(l=!1),l)return _}return null}(l,e?"link":"script",i);if(!f)return null;var y=r(l,f);return{nextDomain:y,nextRetryUrl:t(l,y,y,0,u,f),originalScriptFilename:_,originalSrcUrl:l,originalQuery:u,rule:f}}(n,u)))return null;u?_[n]=[]:o[n]=[]}else{var R,m,E,U,g=S.originalScriptFilename,v=S.originalSrcUrl,L=S.originalQuery,N=S.rule,A=(R=S.nextDomain,m=N.domain,E=r(R,N),-1===(U=m.indexOf(E))?E:m[(U+1)%m.length]);d={nextDomain:A,nextRetryUrl:t(S.nextRetryUrl,S.nextDomain,A,e,L,N),originalScriptFilename:g,originalSrcUrl:v,originalQuery:L,rule:N}}return u?(_[n][p]=d,l[n]=d):(o[n][p]=d,a[n]=d),d}(e,N,L);if(!A)throw u;p=A.originalScriptFilename,R=A.nextRetryUrl,m=A.nextDomain,E=A.rule}catch(r){throw r!==u&&console.error(n,"failed to get nextRetryUrl",r),u}var C=function(n){return{times:n,domain:m,url:R,tagName:L?"link":"script",isAsyncChunk:!0}},I=C(N);if(N>=E.max)throw u.message=(null==(U=u.message)?void 0:U.includes("retries:"))?u.message:"Loading chunk ".concat(e,' from "').concat(p,'" failed after ').concat(E.max,' retries: "').concat(u.message,'"'),"function"==typeof E.onFail&&E.onFail(I),u;"function"==typeof E.onRetry&&E.onRetry(I);var T="function"==typeof E.delay?E.delay(I):E.delay;return(T>0?new Promise(function(n){return setTimeout(n,T)}):Promise.resolve()).then(function(){return y.apply(y,f)}).then(function(n){var r=(null==d?void 0:d.count)===g+2;if("function"==typeof E.onSuccess&&r){var e=C(N+1);E.onSuccess(e)}return n})})):S}if("undefined"==typeof window||window.__RB_ASYNC_CHUNKS__||(window.__RB_ASYNC_CHUNKS__={}),"undefined"!=typeof __RUNTIME_GLOBALS_REQUIRE__)try{__RUNTIME_GLOBALS_ENSURE_CHUNK__=y,__RUNTIME_GLOBALS_LOAD_SCRIPT__=function(){var n=Array.prototype.slice.call(arguments),r=a[n[3]];return r&&(n[0]=r.nextRetryUrl),f.apply(null,n)},__RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__=function(n,r){var e=l[r];return e&&e.nextRetryUrl||__RUNTIME_GLOBALS_PUBLIC_PATH__+n}}catch(r){console.error(n,"Register async chunk retry runtime failed",r)}}();