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