@module-federation/retry-plugin 0.19.1 → 0.20.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @module-federation/retry-plugin
2
2
 
3
+ ## 0.20.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [37346d4]
8
+ - Updated dependencies [639a83b]
9
+ - @module-federation/sdk@0.20.0
10
+
3
11
  ## 0.19.1
4
12
 
5
13
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -6,6 +6,7 @@ var defaultRetries = 3;
6
6
  var defaultRetryDelay = 1e3;
7
7
  var PLUGIN_IDENTIFIER = "[ Module Federation RetryPlugin ]";
8
8
  var ERROR_ABANDONED = "The request failed and has now been abandoned";
9
+ var RUNTIME_008 = "RUNTIME-008";
9
10
 
10
11
  // packages/retry-plugin/src/logger.ts
11
12
  import { createLogger } from "@module-federation/sdk";
@@ -194,7 +195,7 @@ async function fetchRetry(params, lastRequestUrl, originalTotal) {
194
195
  });
195
196
  logger_default.log(`${PLUGIN_IDENTIFIER}: retry failed, no retries left for url: ${requestUrl}`);
196
197
  }
197
- throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED}`);
198
+ throw new Error(`${RUNTIME_008}: ${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${requestUrl}`);
198
199
  } else {
199
200
  const nextIndex = total - retryTimes + 1;
200
201
  const predictedBaseUrl = combineUrlDomainWithPathQuery(requestUrl, url);
@@ -230,10 +231,11 @@ function scriptRetry({ retryOptions, retryFn, beforeExecuteRetry = /* @__PURE__
230
231
  let originalUrl;
231
232
  const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay, domains, addQuery, onRetry, onSuccess, onError } = retryOptions || {};
232
233
  let attempts = 0;
233
- while (attempts < retryTimes) {
234
+ const maxAttempts = retryTimes;
235
+ while (attempts < maxAttempts) {
234
236
  try {
235
237
  beforeExecuteRetry();
236
- if (retryDelay > 0) {
238
+ if (retryDelay > 0 && attempts > 0) {
237
239
  await new Promise((resolve) => setTimeout(resolve, retryDelay));
238
240
  }
239
241
  const retryIndex = attempts + 1;
@@ -272,13 +274,13 @@ function scriptRetry({ retryOptions, retryFn, beforeExecuteRetry = /* @__PURE__
272
274
  } catch (error) {
273
275
  lastError = error;
274
276
  attempts++;
275
- if (attempts >= retryTimes) {
277
+ if (attempts >= maxAttempts) {
276
278
  onError && lastRequestUrl && onError({
277
279
  domains,
278
280
  url: lastRequestUrl,
279
281
  tagName: "script"
280
282
  });
281
- throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED}`);
283
+ throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${lastRequestUrl || "unknown"}`);
282
284
  }
283
285
  }
284
286
  }
@@ -290,7 +292,7 @@ __name(scriptRetry, "scriptRetry");
290
292
  // packages/retry-plugin/src/index.ts
291
293
  var RetryPlugin = /* @__PURE__ */ __name((params) => {
292
294
  if (params?.fetch || params?.script) {
293
- logger_default.warn(`${PLUGIN_IDENTIFIER}: fetch or script config is deprecated, please use the new config style. See docs: https://module-federation.io/plugin/plugins/retry-plugin.html`);
295
+ 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`);
294
296
  }
295
297
  const { fetchOptions = {}, retryTimes = defaultRetries, successTimes = 0, retryDelay = defaultRetryDelay, domains = [], manifestDomains = [], addQuery, onRetry, onSuccess, onError } = params || {};
296
298
  return {
package/dist/index.js CHANGED
@@ -34,6 +34,7 @@ var defaultRetries = 3;
34
34
  var defaultRetryDelay = 1e3;
35
35
  var PLUGIN_IDENTIFIER = "[ Module Federation RetryPlugin ]";
36
36
  var ERROR_ABANDONED = "The request failed and has now been abandoned";
37
+ var RUNTIME_008 = "RUNTIME-008";
37
38
 
38
39
  // packages/retry-plugin/src/logger.ts
39
40
  var import_sdk = require("@module-federation/sdk");
@@ -222,7 +223,7 @@ async function fetchRetry(params, lastRequestUrl, originalTotal) {
222
223
  });
223
224
  logger_default.log(`${PLUGIN_IDENTIFIER}: retry failed, no retries left for url: ${requestUrl}`);
224
225
  }
225
- throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED}`);
226
+ throw new Error(`${RUNTIME_008}: ${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${requestUrl}`);
226
227
  } else {
227
228
  const nextIndex = total - retryTimes + 1;
228
229
  const predictedBaseUrl = combineUrlDomainWithPathQuery(requestUrl, url);
@@ -258,10 +259,11 @@ function scriptRetry({ retryOptions, retryFn, beforeExecuteRetry = /* @__PURE__
258
259
  let originalUrl;
259
260
  const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay, domains, addQuery, onRetry, onSuccess, onError } = retryOptions || {};
260
261
  let attempts = 0;
261
- while (attempts < retryTimes) {
262
+ const maxAttempts = retryTimes;
263
+ while (attempts < maxAttempts) {
262
264
  try {
263
265
  beforeExecuteRetry();
264
- if (retryDelay > 0) {
266
+ if (retryDelay > 0 && attempts > 0) {
265
267
  await new Promise((resolve) => setTimeout(resolve, retryDelay));
266
268
  }
267
269
  const retryIndex = attempts + 1;
@@ -300,13 +302,13 @@ function scriptRetry({ retryOptions, retryFn, beforeExecuteRetry = /* @__PURE__
300
302
  } catch (error) {
301
303
  lastError = error;
302
304
  attempts++;
303
- if (attempts >= retryTimes) {
305
+ if (attempts >= maxAttempts) {
304
306
  onError && lastRequestUrl && onError({
305
307
  domains,
306
308
  url: lastRequestUrl,
307
309
  tagName: "script"
308
310
  });
309
- throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED}`);
311
+ throw new Error(`${PLUGIN_IDENTIFIER}: ${ERROR_ABANDONED} | url: ${lastRequestUrl || "unknown"}`);
310
312
  }
311
313
  }
312
314
  }
@@ -318,7 +320,7 @@ __name(scriptRetry, "scriptRetry");
318
320
  // packages/retry-plugin/src/index.ts
319
321
  var RetryPlugin = /* @__PURE__ */ __name((params) => {
320
322
  if (params?.fetch || params?.script) {
321
- logger_default.warn(`${PLUGIN_IDENTIFIER}: fetch or script config is deprecated, please use the new config style. See docs: https://module-federation.io/plugin/plugins/retry-plugin.html`);
323
+ 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`);
322
324
  }
323
325
  const { fetchOptions = {}, retryTimes = defaultRetries, successTimes = 0, retryDelay = defaultRetryDelay, domains = [], manifestDomains = [], addQuery, onRetry, onSuccess, onError } = params || {};
324
326
  return {
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/retry-plugin",
3
- "version": "0.19.1",
3
+ "version": "0.20.0",
4
4
  "author": "danpeen <dapeen.feng@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/retry-plugin",
3
- "version": "0.19.1",
3
+ "version": "0.20.0",
4
4
  "author": "danpeen <dapeen.feng@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -33,9 +33,9 @@
33
33
  }
34
34
  },
35
35
  "devDependencies": {
36
- "@module-federation/runtime": "0.19.1"
36
+ "@module-federation/runtime": "0.20.0"
37
37
  },
38
38
  "dependencies": {
39
- "@module-federation/sdk": "0.19.1"
39
+ "@module-federation/sdk": "0.20.0"
40
40
  }
41
41
  }