@rsbuild/plugin-assets-retry 1.2.3 → 1.3.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,197 @@
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) {
1
+ (function() {
2
+ "use strict";
3
+ var ERROR_PREFIX = '[@rsbuild/plugin-assets-retry] ';
4
+ function findCurrentDomain(url, config) {
5
+ var domains = config.domain;
6
+ var domain = '';
7
+ for(var i = 0; i < domains.length; i++)if (-1 !== url.indexOf(domains[i])) {
12
8
  domain = domains[i];
13
9
  break;
14
10
  }
11
+ return domain || window.origin;
15
12
  }
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);
13
+ function findNextDomain(url, config) {
14
+ var domains = config.domain;
15
+ var currentDomain = findCurrentDomain(url, config);
16
+ var index = domains.indexOf(currentDomain);
17
+ return domains[(index + 1) % domains.length] || url;
35
18
  }
36
- if (typeof config.addQuery === 'function') {
37
- return config.addQuery({
19
+ var postfixRE = /[?#].*$/;
20
+ function cleanUrl(url) {
21
+ return url.replace(postfixRE, '');
22
+ }
23
+ function getQueryFromUrl(url) {
24
+ var parts = url.split('?')[1];
25
+ return parts ? "?".concat(parts.split('#')[0]) : '';
26
+ }
27
+ function getUrlRetryQuery(existRetryTimes, originalQuery, config) {
28
+ if (true === config.addQuery) return '' !== originalQuery ? "".concat(originalQuery, "&retry=").concat(existRetryTimes) : "?retry=".concat(existRetryTimes);
29
+ if ('function' == typeof config.addQuery) return config.addQuery({
38
30
  times: existRetryTimes,
39
31
  originalQuery: originalQuery
40
32
  });
33
+ return '';
41
34
  }
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');
35
+ function getNextRetryUrl(currRetryUrl, domain, nextDomain, existRetryTimes, originalQuery, config) {
36
+ return cleanUrl(currRetryUrl.replace(domain, nextDomain)) + getUrlRetryQuery(existRetryTimes + 1, originalQuery, config);
59
37
  }
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] = [];
83
- }
84
- } else {
85
- var originalScriptFilename = currRetry.originalScriptFilename, originalSrcUrl = currRetry.originalSrcUrl, originalQuery = currRetry.originalQuery;
86
- var nextDomain = findNextDomain(currRetry.nextDomain);
87
- nextRetry = {
38
+ var asyncChunkRetry_config = __RETRY_OPTIONS__;
39
+ var maxRetries = asyncChunkRetry_config.max;
40
+ var retryCollector = {};
41
+ var retryCssCollector = {};
42
+ var globalCurrRetrying = {};
43
+ var globalCurrRetryingCss = {};
44
+ function getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
45
+ var _retryCssCollector_chunkId, _retryCollector_chunkId;
46
+ return isCssAsyncChunk ? null == (_retryCssCollector_chunkId = retryCssCollector[chunkId]) ? void 0 : _retryCssCollector_chunkId[existRetryTimes] : null == (_retryCollector_chunkId = retryCollector[chunkId]) ? void 0 : _retryCollector_chunkId[existRetryTimes];
47
+ }
48
+ function initRetry(chunkId, isCssAsyncChunk) {
49
+ var originalScriptFilename = isCssAsyncChunk ? originalGetCssFilename(chunkId) : originalGetChunkScriptFilename(chunkId);
50
+ if (!originalScriptFilename) throw new Error('only support cssExtract');
51
+ var originalPublicPath = __RUNTIME_GLOBALS_PUBLIC_PATH__;
52
+ var originalSrcUrl = '/' === originalPublicPath[0] && '/' !== originalPublicPath[1] ? window.origin + originalPublicPath + originalScriptFilename : originalPublicPath + originalScriptFilename;
53
+ var originalQuery = getQueryFromUrl(originalSrcUrl);
54
+ var existRetryTimes = 0;
55
+ var nextDomain = findCurrentDomain(originalSrcUrl, asyncChunkRetry_config);
56
+ return {
88
57
  nextDomain: nextDomain,
89
- nextRetryUrl: getNextRetryUrl(currRetry.nextRetryUrl, currRetry.nextDomain, nextDomain, existRetryTimes, originalQuery),
58
+ nextRetryUrl: getNextRetryUrl(originalSrcUrl, nextDomain, nextDomain, existRetryTimes, originalQuery, asyncChunkRetry_config),
90
59
  originalScriptFilename: originalScriptFilename,
91
60
  originalSrcUrl: originalSrcUrl,
92
61
  originalQuery: originalQuery
93
62
  };
94
63
  }
95
- if (isCssAsyncChunk) {
96
- retryCssCollector[chunkId][nextExistRetryTimes] = nextRetry;
97
- globalCurrRetryingCss[chunkId] = nextRetry;
98
- } else {
99
- retryCollector[chunkId][nextExistRetryTimes] = nextRetry;
100
- globalCurrRetrying[chunkId] = nextRetry;
64
+ function asyncChunkRetry_nextRetry(chunkId, existRetryTimes, isCssAsyncChunk) {
65
+ var currRetry = getCurrentRetry(chunkId, existRetryTimes, isCssAsyncChunk);
66
+ var nextRetry;
67
+ var nextExistRetryTimes = existRetryTimes + 1;
68
+ if (0 === existRetryTimes || void 0 === currRetry) {
69
+ nextRetry = initRetry(chunkId, isCssAsyncChunk);
70
+ if (isCssAsyncChunk) retryCssCollector[chunkId] = [];
71
+ else retryCollector[chunkId] = [];
72
+ } else {
73
+ var originalScriptFilename = currRetry.originalScriptFilename, originalSrcUrl = currRetry.originalSrcUrl, originalQuery = currRetry.originalQuery;
74
+ var nextDomain = findNextDomain(currRetry.nextDomain, asyncChunkRetry_config);
75
+ nextRetry = {
76
+ nextDomain: nextDomain,
77
+ nextRetryUrl: getNextRetryUrl(currRetry.nextRetryUrl, currRetry.nextDomain, nextDomain, existRetryTimes, originalQuery, asyncChunkRetry_config),
78
+ originalScriptFilename: originalScriptFilename,
79
+ originalSrcUrl: originalSrcUrl,
80
+ originalQuery: originalQuery
81
+ };
82
+ }
83
+ if (isCssAsyncChunk) {
84
+ retryCssCollector[chunkId][nextExistRetryTimes] = nextRetry;
85
+ globalCurrRetryingCss[chunkId] = nextRetry;
86
+ } else {
87
+ retryCollector[chunkId][nextExistRetryTimes] = nextRetry;
88
+ globalCurrRetrying[chunkId] = nextRetry;
89
+ }
90
+ return nextRetry;
101
91
  }
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] = {
92
+ var originalEnsureChunk = __RUNTIME_GLOBALS_ENSURE_CHUNK__;
93
+ var originalGetChunkScriptFilename = __RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__;
94
+ var originalGetCssFilename = __RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__ || __RUNTIME_GLOBALS_GET_CSS_FILENAME__ || function() {
95
+ return null;
96
+ };
97
+ var originalLoadScript = __RUNTIME_GLOBALS_LOAD_SCRIPT__;
98
+ function ensureChunk(chunkId) {
99
+ var args = Array.prototype.slice.call(arguments);
100
+ if (!args[10]) args[10] = {
120
101
  count: 0,
121
102
  cssFailedCount: 0
122
103
  };
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;
104
+ var callingCounter = args[10];
105
+ var result = originalEnsureChunk.apply(null, args);
161
106
  try {
162
- var retryResult = nextRetry(chunkId, existRetryTimes, isCssAsyncChunkLoadFailed);
163
- originalScriptFilename = retryResult.originalScriptFilename;
164
- nextRetryUrl = retryResult.nextRetryUrl;
165
- nextDomain = retryResult.nextDomain;
107
+ var originalScriptFilename = originalGetChunkScriptFilename(chunkId);
108
+ var originalCssFilename = originalGetCssFilename(chunkId);
109
+ if ('undefined' != typeof window) {
110
+ if (originalScriptFilename) window.__RB_ASYNC_CHUNKS__[originalScriptFilename] = true;
111
+ if (originalCssFilename) window.__RB_ASYNC_CHUNKS__[originalCssFilename] = true;
112
+ }
166
113
  } catch (e) {
167
- console.error(ERROR_PREFIX, 'failed to get nextRetryUrl', e);
168
- throw error;
114
+ console.error(ERROR_PREFIX, "get original script or CSS filename error", e);
169
115
  }
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);
116
+ if (!callingCounter || 'number' != typeof callingCounter.count || 'number' != typeof callingCounter.cssFailedCount) return result;
117
+ callingCounter.count += 1;
118
+ return result["catch"](function(error) {
119
+ var _error_message;
120
+ var existRetryTimesAll = callingCounter.count - 1;
121
+ var cssExistRetryTimes = callingCounter.cssFailedCount;
122
+ var jsExistRetryTimes = existRetryTimesAll - cssExistRetryTimes;
123
+ var originalScriptFilename;
124
+ var nextRetryUrl;
125
+ var nextDomain;
126
+ var isCssAsyncChunkLoadFailed = Boolean(null == error ? void 0 : null == (_error_message = error.message) ? void 0 : _error_message.includes('CSS chunk'));
127
+ if (isCssAsyncChunkLoadFailed) callingCounter.cssFailedCount += 1;
128
+ var existRetryTimes = isCssAsyncChunkLoadFailed ? cssExistRetryTimes : jsExistRetryTimes;
129
+ try {
130
+ var retryResult = asyncChunkRetry_nextRetry(chunkId, existRetryTimes, isCssAsyncChunkLoadFailed);
131
+ originalScriptFilename = retryResult.originalScriptFilename;
132
+ nextRetryUrl = retryResult.nextRetryUrl;
133
+ nextDomain = retryResult.nextDomain;
134
+ } catch (e) {
135
+ console.error(ERROR_PREFIX, 'failed to get nextRetryUrl', e);
136
+ throw error;
185
137
  }
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);
138
+ var createContext = function(times) {
139
+ return {
140
+ times: times,
141
+ domain: nextDomain,
142
+ url: nextRetryUrl,
143
+ tagName: isCssAsyncChunkLoadFailed ? 'link' : "script",
144
+ isAsyncChunk: true
195
145
  };
196
- }
197
- if (typeof tester !== 'function' || !tester(nextRetryUrl)) {
146
+ };
147
+ var context = createContext(existRetryTimes);
148
+ if (existRetryTimes >= maxRetries) {
149
+ var _error_message1;
150
+ 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(maxRetries, ' retries: "').concat(error.message, '"');
151
+ if ('function' == typeof asyncChunkRetry_config.onFail) asyncChunkRetry_config.onFail(context);
198
152
  throw error;
199
153
  }
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);
154
+ var tester = asyncChunkRetry_config.test;
155
+ if (tester) {
156
+ if ('string' == typeof tester) {
157
+ var regexp = new RegExp(tester);
158
+ tester = function(str) {
159
+ return regexp.test(str);
160
+ };
161
+ }
162
+ if ('function' != typeof tester || !tester(nextRetryUrl)) throw error;
223
163
  }
224
- return result;
164
+ if (asyncChunkRetry_config.domain && asyncChunkRetry_config.domain.length > 0 && -1 === asyncChunkRetry_config.domain.indexOf(nextDomain)) throw error;
165
+ if ('function' == typeof asyncChunkRetry_config.onRetry) asyncChunkRetry_config.onRetry(context);
166
+ var delayTime = 'function' == typeof asyncChunkRetry_config.delay ? asyncChunkRetry_config.delay(context) : asyncChunkRetry_config.delay;
167
+ var delayPromise = delayTime > 0 ? new Promise(function(resolve) {
168
+ return setTimeout(resolve, delayTime);
169
+ }) : Promise.resolve();
170
+ return delayPromise.then(function() {
171
+ return ensureChunk.apply(ensureChunk, args);
172
+ }).then(function(result) {
173
+ var isLastSuccessRetry = (null == callingCounter ? void 0 : callingCounter.count) === existRetryTimesAll + 2;
174
+ if ('function' == typeof asyncChunkRetry_config.onSuccess && isLastSuccessRetry) {
175
+ var context = createContext(existRetryTimes + 1);
176
+ asyncChunkRetry_config.onSuccess(context);
177
+ }
178
+ return result;
179
+ });
225
180
  });
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
181
  }
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__ = {};
182
+ function loadScript() {
183
+ var args = Array.prototype.slice.call(arguments);
184
+ var retry = globalCurrRetrying[args[3]];
185
+ if (retry) args[0] = retry.nextRetryUrl;
186
+ return originalLoadScript.apply(null, args);
246
187
  }
247
- if (typeof __RUNTIME_GLOBALS_REQUIRE__ !== 'undefined') {
248
- try {
188
+ function loadStyleSheet(href, chunkId) {
189
+ var retry = globalCurrRetryingCss[chunkId];
190
+ return retry && retry.nextRetryUrl || __RUNTIME_GLOBALS_PUBLIC_PATH__ + href;
191
+ }
192
+ function registerAsyncChunkRetry() {
193
+ if ('undefined' != typeof window && !window.__RB_ASYNC_CHUNKS__) window.__RB_ASYNC_CHUNKS__ = {};
194
+ if ('undefined' != typeof __RUNTIME_GLOBALS_REQUIRE__) try {
249
195
  __RUNTIME_GLOBALS_ENSURE_CHUNK__ = ensureChunk;
250
196
  __RUNTIME_GLOBALS_LOAD_SCRIPT__ = loadScript;
251
197
  __RUNTIME_GLOBALS_RSBUILD_LOAD_STYLESHEET__ = loadStyleSheet;
@@ -253,5 +199,5 @@ function registerAsyncChunkRetry() {
253
199
  console.error(ERROR_PREFIX, 'Register async chunk retry runtime failed', e);
254
200
  }
255
201
  }
256
- }
257
- registerAsyncChunkRetry();
202
+ registerAsyncChunkRetry();
203
+ })();
@@ -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="",i=0;i<e.length;i++)if(-1!==n.indexOf(e[i])){t=e[i];break}return t||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=i.max,_={},a={},c={},l={},u=__RUNTIME_GLOBALS_ENSURE_CHUNK__,s=__RUNTIME_GLOBALS_GET_CHUNK_SCRIPT_FILENAME__,f=__RUNTIME_GLOBALS_GET_MINI_CSS_EXTRACT_FILENAME__||__RUNTIME_GLOBALS_GET_CSS_FILENAME__||function(){return null},d=__RUNTIME_GLOBALS_LOAD_SCRIPT__;function y(e){var d=Array.prototype.slice.call(arguments);d[10]||(d[10]={count:0,cssFailedCount:0});var S=d[10],R=u.apply(null,d);try{var p=s(e),E=f(e);"undefined"!=typeof window&&(p&&(window.__RB_ASYNC_CHUNKS__[p]=!0),E&&(window.__RB_ASYNC_CHUNKS__[E]=!0))}catch(r){console.error(n,"get original script or CSS filename error",r)}return S&&"number"==typeof S.count&&"number"==typeof S.cssFailedCount?(S.count+=1,R.catch(function(u){var R,p,E,U,L,m=S.count-1,g=S.cssFailedCount,v=!!(null==u||null==(R=u.message)?void 0:R.includes("CSS chunk"));v&&(S.cssFailedCount+=1);var N=v?g:m-g;try{var A=function(n,e,o){var u,d,y,S=o?null==(u=a[n])?void 0:u[e]:null==(d=_[n])?void 0:d[e],R=e+1;if(0===e||void 0===S)y=function(n,e){var o,_=e?f(n):s(n);if(!_)throw Error("only support cssExtract");var a=__RUNTIME_GLOBALS_PUBLIC_PATH__,c="/"===a[0]&&"/"!==a[1]?window.origin+a+_:a+_,l=(o=c.split("?")[1])?"?".concat(o.split("#")[0]):"",u=r(c,i);return{nextDomain:u,nextRetryUrl:t(c,u,u,0,l,i),originalScriptFilename:_,originalSrcUrl:c,originalQuery:l}}(n,o),o?a[n]=[]:_[n]=[];else{var p,E,U,L,m=S.originalScriptFilename,g=S.originalSrcUrl,v=S.originalQuery,N=(p=S.nextDomain,E=i.domain,U=r(p,i),L=E.indexOf(U),E[(L+1)%E.length]||p);y={nextDomain:N,nextRetryUrl:t(S.nextRetryUrl,S.nextDomain,N,e,v,i),originalScriptFilename:m,originalSrcUrl:g,originalQuery:v}}return o?(a[n][R]=y,l[n]=y):(_[n][R]=y,c[n]=y),y}(e,N,v);p=A.originalScriptFilename,E=A.nextRetryUrl,U=A.nextDomain}catch(r){throw console.error(n,"failed to get nextRetryUrl",r),u}var C=function(n){return{times:n,domain:U,url:E,tagName:v?"link":"script",isAsyncChunk:!0}},T=C(N);if(N>=o)throw u.message=(null==(L=u.message)?void 0:L.includes("retries:"))?u.message:"Loading chunk ".concat(e,' from "').concat(p,'" failed after ').concat(o,' retries: "').concat(u.message,'"'),"function"==typeof i.onFail&&i.onFail(T),u;var I=i.test;if(I){if("string"==typeof I){var w=new RegExp(I);I=function(n){return w.test(n)}}if("function"!=typeof I||!I(E))throw u}if(i.domain&&i.domain.length>0&&-1===i.domain.indexOf(U))throw u;"function"==typeof i.onRetry&&i.onRetry(T);var O="function"==typeof i.delay?i.delay(T):i.delay;return(O>0?new Promise(function(n){return setTimeout(n,O)}):Promise.resolve()).then(function(){return y.apply(y,d)}).then(function(n){var r=(null==S?void 0:S.count)===m+2;if("function"==typeof i.onSuccess&&r){var e=C(N+1);i.onSuccess(e)}return n})})):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=c[n[3]];return r&&(n[0]=r.nextRetryUrl),d.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)}}();