@module-federation/retry-plugin 2.0.1 → 2.1.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.
package/dist/esm/index.js CHANGED
@@ -1,361 +1,302 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
1
+ import { createLogger } from "@module-federation/sdk";
3
2
 
4
- // packages/retry-plugin/src/constant.ts
5
- var defaultRetries = 3;
6
- var defaultRetryDelay = 1e3;
7
- var PLUGIN_IDENTIFIER = "[ Module Federation RetryPlugin ]";
8
- var ERROR_ABANDONED = "The request failed and has now been abandoned";
9
- var RUNTIME_008 = "RUNTIME-008";
3
+ //#region src/constant.ts
4
+ const defaultRetries = 3;
5
+ const defaultRetryDelay = 1e3;
6
+ const PLUGIN_IDENTIFIER = "[ Module Federation RetryPlugin ]";
7
+ const ERROR_ABANDONED = "The request failed and has now been abandoned";
8
+ const RUNTIME_008 = "RUNTIME-008";
10
9
 
11
- // packages/retry-plugin/src/logger.ts
12
- import { createLogger } from "@module-federation/sdk";
13
- var logger = createLogger(PLUGIN_IDENTIFIER);
14
- var logger_default = logger;
10
+ //#endregion
11
+ //#region src/logger.ts
12
+ const logger = createLogger(PLUGIN_IDENTIFIER);
15
13
 
16
- // packages/retry-plugin/src/utils.ts
14
+ //#endregion
15
+ //#region src/utils.ts
17
16
  function rewriteWithNextDomain(currentUrl, domains) {
18
- if (!domains || domains.length === 0)
19
- return null;
20
- try {
21
- const u = new URL(currentUrl);
22
- const currentHostname = u.hostname;
23
- const currentPort = u.port;
24
- const currentHost = `${currentHostname}${currentPort ? `:${currentPort}` : ""}`;
25
- const normalized = domains.map((d) => {
26
- try {
27
- const du = new URL(d.startsWith("http") ? d : `https://${d}`);
28
- return {
29
- hostname: du.hostname,
30
- port: du.port,
31
- protocol: du.protocol
32
- };
33
- } catch {
34
- return {
35
- hostname: d,
36
- port: "",
37
- protocol: u.protocol
38
- };
39
- }
40
- }).filter((d) => !!d.hostname);
41
- if (normalized.length === 0)
42
- return null;
43
- let idx = -1;
44
- for (let i = normalized.length - 1; i >= 0; i--) {
45
- const candHost = `${normalized[i].hostname}${normalized[i].port ? `:${normalized[i].port}` : ""}`;
46
- if (candHost === currentHost) {
47
- idx = i;
48
- break;
49
- }
50
- }
51
- const total = normalized.length;
52
- for (let step = 1; step <= total; step++) {
53
- const nextIdx = ((idx >= 0 ? idx : -1) + step) % total;
54
- const candidate = normalized[nextIdx];
55
- const candidateHost = `${candidate.hostname}${candidate.port ? `:${candidate.port}` : ""}`;
56
- if (candidateHost !== currentHost) {
57
- u.hostname = candidate.hostname;
58
- if (candidate.port !== void 0 && candidate.port !== null && candidate.port !== "") {
59
- u.port = candidate.port;
60
- } else {
61
- u.port = "";
62
- }
63
- u.protocol = candidate.protocol || u.protocol;
64
- return u.toString();
65
- }
66
- }
67
- return null;
68
- } catch {
69
- return null;
70
- }
17
+ if (!domains || domains.length === 0) return null;
18
+ try {
19
+ const u = new URL(currentUrl);
20
+ const currentHostname = u.hostname;
21
+ const currentPort = u.port;
22
+ const currentHost = `${currentHostname}${currentPort ? `:${currentPort}` : ""}`;
23
+ const normalized = domains.map((d) => {
24
+ try {
25
+ const du = new URL(d.startsWith("http") ? d : `https://${d}`);
26
+ return {
27
+ hostname: du.hostname,
28
+ port: du.port,
29
+ protocol: du.protocol
30
+ };
31
+ } catch {
32
+ return {
33
+ hostname: d,
34
+ port: "",
35
+ protocol: u.protocol
36
+ };
37
+ }
38
+ }).filter((d) => !!d.hostname);
39
+ if (normalized.length === 0) return null;
40
+ let idx = -1;
41
+ for (let i = normalized.length - 1; i >= 0; i--) if (`${normalized[i].hostname}${normalized[i].port ? `:${normalized[i].port}` : ""}` === currentHost) {
42
+ idx = i;
43
+ break;
44
+ }
45
+ const total = normalized.length;
46
+ for (let step = 1; step <= total; step++) {
47
+ const candidate = normalized[((idx >= 0 ? idx : -1) + step) % total];
48
+ if (`${candidate.hostname}${candidate.port ? `:${candidate.port}` : ""}` !== currentHost) {
49
+ u.hostname = candidate.hostname;
50
+ if (candidate.port !== void 0 && candidate.port !== null && candidate.port !== "") u.port = candidate.port;
51
+ else u.port = "";
52
+ u.protocol = candidate.protocol || u.protocol;
53
+ return u.toString();
54
+ }
55
+ }
56
+ return null;
57
+ } catch {
58
+ return null;
59
+ }
71
60
  }
72
- __name(rewriteWithNextDomain, "rewriteWithNextDomain");
73
61
  function appendRetryCountQuery(url, retryIndex, key = "retryCount") {
74
- try {
75
- const u = new URL(url);
76
- u.searchParams.delete(key);
77
- u.searchParams.set(key, String(retryIndex));
78
- return u.toString();
79
- } catch {
80
- return url;
81
- }
62
+ try {
63
+ const u = new URL(url);
64
+ u.searchParams.delete(key);
65
+ u.searchParams.set(key, String(retryIndex));
66
+ return u.toString();
67
+ } catch {
68
+ return url;
69
+ }
82
70
  }
83
- __name(appendRetryCountQuery, "appendRetryCountQuery");
84
71
  function getRetryUrl(baseUrl, opts = {}) {
85
- const { domains, addQuery, retryIndex = 0, queryKey = "retryCount" } = opts;
86
- let cleanBaseUrl = baseUrl;
87
- try {
88
- const urlObj = new URL(baseUrl);
89
- urlObj.searchParams.delete(queryKey);
90
- cleanBaseUrl = urlObj.toString();
91
- } catch {
92
- }
93
- let nextUrl = rewriteWithNextDomain(cleanBaseUrl, domains) ?? cleanBaseUrl;
94
- if (retryIndex > 0 && addQuery) {
95
- try {
96
- const u = new URL(nextUrl);
97
- const originalUrl = new URL(baseUrl);
98
- originalUrl.searchParams.delete(queryKey);
99
- const originalQuery = originalUrl.search.startsWith("?") ? originalUrl.search.slice(1) : originalUrl.search;
100
- if (typeof addQuery === "function") {
101
- const newQuery = addQuery({
102
- times: retryIndex,
103
- originalQuery
104
- });
105
- u.search = newQuery ? `?${newQuery.replace(/^\?/, "")}` : "";
106
- nextUrl = u.toString();
107
- } else if (addQuery === true) {
108
- u.searchParams.delete(queryKey);
109
- u.searchParams.set(queryKey, String(retryIndex));
110
- nextUrl = u.toString();
111
- }
112
- } catch {
113
- if (addQuery === true) {
114
- nextUrl = appendRetryCountQuery(nextUrl, retryIndex, queryKey);
115
- }
116
- }
117
- }
118
- return nextUrl;
72
+ const { domains, addQuery, retryIndex = 0, queryKey = "retryCount" } = opts;
73
+ let cleanBaseUrl = baseUrl;
74
+ try {
75
+ const urlObj = new URL(baseUrl);
76
+ urlObj.searchParams.delete(queryKey);
77
+ cleanBaseUrl = urlObj.toString();
78
+ } catch {}
79
+ let nextUrl = rewriteWithNextDomain(cleanBaseUrl, domains) ?? cleanBaseUrl;
80
+ if (retryIndex > 0 && addQuery) try {
81
+ const u = new URL(nextUrl);
82
+ const originalUrl = new URL(baseUrl);
83
+ originalUrl.searchParams.delete(queryKey);
84
+ const originalQuery = originalUrl.search.startsWith("?") ? originalUrl.search.slice(1) : originalUrl.search;
85
+ if (typeof addQuery === "function") {
86
+ const newQuery = addQuery({
87
+ times: retryIndex,
88
+ originalQuery
89
+ });
90
+ u.search = newQuery ? `?${newQuery.replace(/^\?/, "")}` : "";
91
+ nextUrl = u.toString();
92
+ } else if (addQuery === true) {
93
+ u.searchParams.delete(queryKey);
94
+ u.searchParams.set(queryKey, String(retryIndex));
95
+ nextUrl = u.toString();
96
+ }
97
+ } catch {
98
+ if (addQuery === true) nextUrl = appendRetryCountQuery(nextUrl, retryIndex, queryKey);
99
+ }
100
+ return nextUrl;
119
101
  }
120
- __name(getRetryUrl, "getRetryUrl");
102
+ /**
103
+ * Extract domain/host info from a URL and combine it with path/query from another URL
104
+ * This is useful for domain rotation while preserving original path and query parameters
105
+ * @param domainUrl - URL containing the target domain/host
106
+ * @param pathQueryUrl - URL containing the target path and query parameters
107
+ * @returns Combined URL with domain from domainUrl and path/query from pathQueryUrl
108
+ */
121
109
  function combineUrlDomainWithPathQuery(domainUrl, pathQueryUrl) {
122
- try {
123
- const domainUrlObj = new URL(domainUrl);
124
- const pathQueryUrlObj = new URL(pathQueryUrl);
125
- domainUrlObj.pathname = pathQueryUrlObj.pathname;
126
- domainUrlObj.search = pathQueryUrlObj.search;
127
- return domainUrlObj.toString();
128
- } catch {
129
- return pathQueryUrl;
130
- }
110
+ try {
111
+ const domainUrlObj = new URL(domainUrl);
112
+ const pathQueryUrlObj = new URL(pathQueryUrl);
113
+ domainUrlObj.pathname = pathQueryUrlObj.pathname;
114
+ domainUrlObj.search = pathQueryUrlObj.search;
115
+ return domainUrlObj.toString();
116
+ } catch {
117
+ return pathQueryUrl;
118
+ }
131
119
  }
132
- __name(combineUrlDomainWithPathQuery, "combineUrlDomainWithPathQuery");
133
120
 
134
- // packages/retry-plugin/src/fetch-retry.ts
121
+ //#endregion
122
+ //#region src/fetch-retry.ts
135
123
  function autoParseResponse(url, response) {
136
- try {
137
- const parsed = new URL(url);
138
- if (parsed.pathname.endsWith(".js") || parsed.pathname.endsWith(".cjs") || parsed.pathname.endsWith(".mjs")) {
139
- return response.text();
140
- }
141
- return response.json();
142
- } catch (error) {
143
- return response.json();
144
- }
124
+ try {
125
+ const parsed = new URL(url);
126
+ if (parsed.pathname.endsWith(".js") || parsed.pathname.endsWith(".cjs") || parsed.pathname.endsWith(".mjs")) return response.text();
127
+ return response.json();
128
+ } catch (error) {
129
+ return response.json();
130
+ }
145
131
  }
146
- __name(autoParseResponse, "autoParseResponse");
147
132
  async function fetchRetry(params, lastRequestUrl, originalTotal) {
148
- const {
149
- url,
150
- fetchOptions = {},
151
- retryTimes = defaultRetries,
152
- retryDelay = defaultRetryDelay,
153
- // List of retry domains when resource loading fails. In the domains array, the first item is the default domain for static resources, and the subsequent items are backup domains. When a request to a domain fails, the system will find that domain in the array and replace it with the next domain in the array.
154
- domains,
155
- // Whether to add query parameters during resource retry to avoid being affected by browser and CDN cache. When set to true, retry=${times} will be added to the query, requesting in the order of retry=1, retry=2, retry=3.
156
- addQuery,
157
- onRetry,
158
- onSuccess,
159
- onError
160
- } = params;
161
- if (!url) {
162
- throw new Error(`${PLUGIN_IDENTIFIER}: url is required in fetchWithRetry`);
163
- }
164
- const total = originalTotal ?? params.retryTimes ?? defaultRetries;
165
- const isFirstAttempt = !lastRequestUrl;
166
- let baseUrl = url;
167
- if (!isFirstAttempt && lastRequestUrl) {
168
- baseUrl = combineUrlDomainWithPathQuery(lastRequestUrl, url);
169
- }
170
- let requestUrl = baseUrl;
171
- if (!isFirstAttempt) {
172
- requestUrl = getRetryUrl(baseUrl, {
173
- domains,
174
- addQuery,
175
- retryIndex: total - retryTimes,
176
- queryKey: "retryCount"
177
- });
178
- }
179
- try {
180
- if (!isFirstAttempt && retryDelay > 0) {
181
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
182
- }
183
- const response = await fetch(requestUrl, fetchOptions);
184
- const responseClone = response.clone();
185
- if (!response.ok) {
186
- throw new Error(`${PLUGIN_IDENTIFIER}: Request failed: ${response.status} ${response.statusText || ""} | url: ${requestUrl}`);
187
- }
188
- await autoParseResponse(requestUrl, responseClone).catch((error) => {
189
- throw new Error(`${PLUGIN_IDENTIFIER}: JSON parse failed: ${error?.message || String(error)} | url: ${requestUrl}`);
190
- });
191
- if (!isFirstAttempt) {
192
- onSuccess && requestUrl && onSuccess({
193
- domains,
194
- url: requestUrl,
195
- tagName: "fetch"
196
- });
197
- }
198
- return response;
199
- } catch (error) {
200
- if (retryTimes <= 0) {
201
- const attemptedRetries = total - retryTimes;
202
- if (!isFirstAttempt && attemptedRetries > 0) {
203
- onError && onError({
204
- domains,
205
- url: requestUrl,
206
- tagName: "fetch"
207
- });
208
- logger_default.log(`${PLUGIN_IDENTIFIER}: retry failed, no retries left for url: ${requestUrl}`);
209
- }
210
- throw new Error(`${RUNTIME_008}: ${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${requestUrl}`);
211
- } else {
212
- const nextIndex = total - retryTimes + 1;
213
- const predictedBaseUrl = combineUrlDomainWithPathQuery(requestUrl, url);
214
- const predictedNextUrl = getRetryUrl(predictedBaseUrl, {
215
- domains,
216
- addQuery,
217
- retryIndex: nextIndex,
218
- queryKey: "retryCount"
219
- });
220
- onRetry && onRetry({
221
- times: nextIndex,
222
- domains,
223
- url: predictedNextUrl,
224
- tagName: "fetch"
225
- });
226
- logger_default.log(`${PLUGIN_IDENTIFIER}: Trying again. Number of retries left: ${retryTimes - 1}`);
227
- return await fetchRetry({
228
- ...params,
229
- retryTimes: retryTimes - 1
230
- }, requestUrl, total);
231
- }
232
- }
133
+ const { url, fetchOptions = {}, retryTimes = defaultRetries, retryDelay = defaultRetryDelay, domains, addQuery, onRetry, onSuccess, onError } = params;
134
+ if (!url) throw new Error(`${PLUGIN_IDENTIFIER}: url is required in fetchWithRetry`);
135
+ const total = originalTotal ?? params.retryTimes ?? defaultRetries;
136
+ const isFirstAttempt = !lastRequestUrl;
137
+ let baseUrl = url;
138
+ if (!isFirstAttempt && lastRequestUrl) baseUrl = combineUrlDomainWithPathQuery(lastRequestUrl, url);
139
+ let requestUrl = baseUrl;
140
+ if (!isFirstAttempt) requestUrl = getRetryUrl(baseUrl, {
141
+ domains,
142
+ addQuery,
143
+ retryIndex: total - retryTimes,
144
+ queryKey: "retryCount"
145
+ });
146
+ try {
147
+ if (!isFirstAttempt && retryDelay > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
148
+ const response = await fetch(requestUrl, fetchOptions);
149
+ const responseClone = response.clone();
150
+ if (!response.ok) throw new Error(`${PLUGIN_IDENTIFIER}: Request failed: ${response.status} ${response.statusText || ""} | url: ${requestUrl}`);
151
+ await autoParseResponse(requestUrl, responseClone).catch((error) => {
152
+ throw new Error(`${PLUGIN_IDENTIFIER}: JSON parse failed: ${error?.message || String(error)} | url: ${requestUrl}`);
153
+ });
154
+ if (!isFirstAttempt) onSuccess && requestUrl && onSuccess({
155
+ domains,
156
+ url: requestUrl,
157
+ tagName: "fetch"
158
+ });
159
+ return response;
160
+ } catch (error) {
161
+ if (retryTimes <= 0) {
162
+ const attemptedRetries = total - retryTimes;
163
+ if (!isFirstAttempt && attemptedRetries > 0) {
164
+ onError && onError({
165
+ domains,
166
+ url: requestUrl,
167
+ tagName: "fetch"
168
+ });
169
+ logger.log(`${PLUGIN_IDENTIFIER}: retry failed, no retries left for url: ${requestUrl}`);
170
+ }
171
+ throw new Error(`${RUNTIME_008}: ${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${requestUrl}`);
172
+ } else {
173
+ const nextIndex = total - retryTimes + 1;
174
+ const predictedNextUrl = getRetryUrl(combineUrlDomainWithPathQuery(requestUrl, url), {
175
+ domains,
176
+ addQuery,
177
+ retryIndex: nextIndex,
178
+ queryKey: "retryCount"
179
+ });
180
+ onRetry && onRetry({
181
+ times: nextIndex,
182
+ domains,
183
+ url: predictedNextUrl,
184
+ tagName: "fetch"
185
+ });
186
+ logger.log(`${PLUGIN_IDENTIFIER}: Trying again. Number of retries left: ${retryTimes - 1}`);
187
+ return await fetchRetry({
188
+ ...params,
189
+ retryTimes: retryTimes - 1
190
+ }, requestUrl, total);
191
+ }
192
+ }
233
193
  }
234
- __name(fetchRetry, "fetchRetry");
235
194
 
236
- // packages/retry-plugin/src/script-retry.ts
237
- function scriptRetry({ retryOptions, retryFn, beforeExecuteRetry = /* @__PURE__ */ __name(() => {
238
- }, "beforeExecuteRetry") }) {
239
- return async function(params) {
240
- let retryWrapper;
241
- let lastError;
242
- let lastRequestUrl;
243
- let originalUrl;
244
- const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay, domains, addQuery, onRetry, onSuccess, onError } = retryOptions || {};
245
- let attempts = 0;
246
- const maxAttempts = retryTimes;
247
- while (attempts < maxAttempts) {
248
- try {
249
- beforeExecuteRetry();
250
- if (retryDelay > 0 && attempts > 0) {
251
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
252
- }
253
- const retryIndex = attempts + 1;
254
- retryWrapper = await retryFn({
255
- ...params,
256
- getEntryUrl: (url) => {
257
- if (!originalUrl) {
258
- originalUrl = url;
259
- }
260
- let baseUrl = originalUrl;
261
- if (lastRequestUrl) {
262
- baseUrl = combineUrlDomainWithPathQuery(lastRequestUrl, originalUrl);
263
- }
264
- const next = getRetryUrl(baseUrl, {
265
- domains,
266
- addQuery,
267
- retryIndex,
268
- queryKey: "retryCount"
269
- });
270
- onRetry && onRetry({
271
- times: retryIndex,
272
- domains,
273
- url: next,
274
- tagName: "script"
275
- });
276
- lastRequestUrl = next;
277
- return next;
278
- }
279
- });
280
- onSuccess && lastRequestUrl && onSuccess({
281
- domains,
282
- url: lastRequestUrl,
283
- tagName: "script"
284
- });
285
- break;
286
- } catch (error) {
287
- lastError = error;
288
- attempts++;
289
- if (attempts >= maxAttempts) {
290
- onError && lastRequestUrl && onError({
291
- domains,
292
- url: lastRequestUrl,
293
- tagName: "script"
294
- });
295
- throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${lastRequestUrl || "unknown"}`);
296
- }
297
- }
298
- }
299
- return retryWrapper;
300
- };
195
+ //#endregion
196
+ //#region src/script-retry.ts
197
+ function scriptRetry({ retryOptions, retryFn, beforeExecuteRetry = () => {} }) {
198
+ return async function(params) {
199
+ let retryWrapper;
200
+ let lastRequestUrl;
201
+ let originalUrl;
202
+ const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay, domains, addQuery, onRetry, onSuccess, onError } = retryOptions || {};
203
+ let attempts = 0;
204
+ const maxAttempts = retryTimes;
205
+ while (attempts < maxAttempts) try {
206
+ beforeExecuteRetry();
207
+ if (retryDelay > 0 && attempts > 0) await new Promise((resolve) => setTimeout(resolve, retryDelay));
208
+ const retryIndex = attempts + 1;
209
+ retryWrapper = await retryFn({
210
+ ...params,
211
+ getEntryUrl: (url) => {
212
+ if (!originalUrl) originalUrl = url;
213
+ let baseUrl = originalUrl;
214
+ if (lastRequestUrl) baseUrl = combineUrlDomainWithPathQuery(lastRequestUrl, originalUrl);
215
+ const next = getRetryUrl(baseUrl, {
216
+ domains,
217
+ addQuery,
218
+ retryIndex,
219
+ queryKey: "retryCount"
220
+ });
221
+ onRetry && onRetry({
222
+ times: retryIndex,
223
+ domains,
224
+ url: next,
225
+ tagName: "script"
226
+ });
227
+ lastRequestUrl = next;
228
+ return next;
229
+ }
230
+ });
231
+ onSuccess && lastRequestUrl && onSuccess({
232
+ domains,
233
+ url: lastRequestUrl,
234
+ tagName: "script"
235
+ });
236
+ break;
237
+ } catch (error) {
238
+ attempts++;
239
+ if (attempts >= maxAttempts) {
240
+ onError && lastRequestUrl && onError({
241
+ domains,
242
+ url: lastRequestUrl,
243
+ tagName: "script"
244
+ });
245
+ throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${lastRequestUrl || "unknown"}`);
246
+ }
247
+ }
248
+ return retryWrapper;
249
+ };
301
250
  }
302
- __name(scriptRetry, "scriptRetry");
303
251
 
304
- // packages/retry-plugin/src/index.ts
305
- var RetryPlugin = /* @__PURE__ */ __name((params) => {
306
- if (params?.fetch || params?.script) {
307
- logger_default.warn(`${PLUGIN_IDENTIFIER}: params is ${params}, fetch or script config is deprecated, please use the new config style. See docs: https://module-federation.io/plugin/plugins/retry-plugin.html`);
308
- }
309
- const { fetchOptions = {}, retryTimes = defaultRetries, successTimes = 0, retryDelay = defaultRetryDelay, domains = [], manifestDomains = [], addQuery, onRetry, onSuccess, onError } = params || {};
310
- return {
311
- name: "retry-plugin",
312
- async fetch(manifestUrl, options) {
313
- return fetchRetry({
314
- url: manifestUrl,
315
- fetchOptions: {
316
- ...options,
317
- ...fetchOptions
318
- },
319
- domains: manifestDomains || domains,
320
- addQuery,
321
- onRetry,
322
- onSuccess,
323
- onError,
324
- retryTimes,
325
- successTimes,
326
- retryDelay
327
- });
328
- },
329
- async loadEntryError({ getRemoteEntry, origin, remoteInfo, remoteEntryExports, globalLoading, uniqueKey }) {
330
- const beforeExecuteRetry = /* @__PURE__ */ __name(() => {
331
- delete globalLoading[uniqueKey];
332
- }, "beforeExecuteRetry");
333
- const getRemoteEntryRetry = scriptRetry({
334
- retryOptions: {
335
- retryTimes,
336
- retryDelay,
337
- domains,
338
- addQuery,
339
- onRetry,
340
- onSuccess,
341
- onError
342
- },
343
- retryFn: getRemoteEntry,
344
- beforeExecuteRetry
345
- });
346
- const result = await getRemoteEntryRetry({
347
- origin,
348
- remoteInfo,
349
- remoteEntryExports
350
- });
351
- return result;
352
- }
353
- };
354
- }, "RetryPlugin");
355
- export {
356
- RetryPlugin,
357
- appendRetryCountQuery,
358
- combineUrlDomainWithPathQuery,
359
- getRetryUrl,
360
- rewriteWithNextDomain
252
+ //#endregion
253
+ //#region src/index.ts
254
+ const RetryPlugin = (params) => {
255
+ if (params?.fetch || params?.script) logger.warn(`${PLUGIN_IDENTIFIER}: params is ${params}, fetch or script config is deprecated, please use the new config style. See docs: https://module-federation.io/plugin/plugins/retry-plugin.html`);
256
+ const { fetchOptions = {}, retryTimes = defaultRetries, successTimes = 0, retryDelay = defaultRetryDelay, domains = [], manifestDomains = [], addQuery, onRetry, onSuccess, onError } = params || {};
257
+ return {
258
+ name: "retry-plugin",
259
+ async fetch(manifestUrl, options) {
260
+ return fetchRetry({
261
+ url: manifestUrl,
262
+ fetchOptions: {
263
+ ...options,
264
+ ...fetchOptions
265
+ },
266
+ domains: manifestDomains || domains,
267
+ addQuery,
268
+ onRetry,
269
+ onSuccess,
270
+ onError,
271
+ retryTimes,
272
+ successTimes,
273
+ retryDelay
274
+ });
275
+ },
276
+ async loadEntryError({ getRemoteEntry, origin, remoteInfo, remoteEntryExports, globalLoading, uniqueKey }) {
277
+ const beforeExecuteRetry = () => {
278
+ delete globalLoading[uniqueKey];
279
+ };
280
+ return await scriptRetry({
281
+ retryOptions: {
282
+ retryTimes,
283
+ retryDelay,
284
+ domains,
285
+ addQuery,
286
+ onRetry,
287
+ onSuccess,
288
+ onError
289
+ },
290
+ retryFn: getRemoteEntry,
291
+ beforeExecuteRetry
292
+ })({
293
+ origin,
294
+ remoteInfo,
295
+ remoteEntryExports
296
+ });
297
+ }
298
+ };
361
299
  };
300
+
301
+ //#endregion
302
+ export { RetryPlugin, appendRetryCountQuery, combineUrlDomainWithPathQuery, getRetryUrl, rewriteWithNextDomain };