@module-federation/retry-plugin 0.8.1 → 0.8.3

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,19 @@
1
1
  # @module-federation/retry-plugin
2
2
 
3
+ ## 0.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [8e172c8]
8
+ - @module-federation/sdk@0.8.3
9
+
10
+ ## 0.8.2
11
+
12
+ ### Patch Changes
13
+
14
+ - fa7a0bd: feat: add remote-entry script resource retry for retry-plugin
15
+ - @module-federation/sdk@0.8.2
16
+
3
17
  ## 0.8.1
4
18
 
5
19
  ### Patch Changes
package/dist/esm/index.js CHANGED
@@ -25,7 +25,7 @@ async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries,
25
25
  return response;
26
26
  } catch (error) {
27
27
  if (retryTimes <= 0) {
28
- logger_default.log(`>>>>>>>>> retry failed after ${retryTimes} times for url: ${url}, now will try fallbackUrl url <<<<<<<<<`);
28
+ logger_default.log(`[ Module Federation RetryPlugin ]: retry failed after ${retryTimes} times for url: ${url}, now will try fallbackUrl url`);
29
29
  if (fallback && typeof fallback === "function") {
30
30
  return fetchWithRetry({
31
31
  url: fallback(url),
@@ -53,6 +53,35 @@ async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries,
53
53
  }
54
54
  __name(fetchWithRetry, "fetchWithRetry");
55
55
 
56
+ // packages/retry-plugin/src/util.ts
57
+ function scriptCommonRetry({ scriptOption, moduleInfo, retryFn, beforeExecuteRetry = /* @__PURE__ */ __name(() => {
58
+ }, "beforeExecuteRetry") }) {
59
+ return async function(...args) {
60
+ let retryResponse;
61
+ const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay } = scriptOption || {};
62
+ if (scriptOption?.moduleName && scriptOption?.moduleName.some((m) => moduleInfo.name === m || moduleInfo?.alias === m) || scriptOption?.moduleName === void 0) {
63
+ let attempts = 0;
64
+ while (attempts - 1 < retryTimes) {
65
+ try {
66
+ beforeExecuteRetry && beforeExecuteRetry();
67
+ retryResponse = await retryFn(...args);
68
+ break;
69
+ } catch (error) {
70
+ attempts++;
71
+ if (attempts - 1 >= retryTimes) {
72
+ scriptOption?.cb && await new Promise((resolve) => scriptOption?.cb && scriptOption?.cb(resolve, error));
73
+ throw error;
74
+ }
75
+ logger_default.log(`[ Module Federation RetryPlugin ]: script resource retrying ${attempts} times`);
76
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
77
+ }
78
+ }
79
+ }
80
+ return retryResponse;
81
+ };
82
+ }
83
+ __name(scriptCommonRetry, "scriptCommonRetry");
84
+
56
85
  // packages/retry-plugin/src/index.ts
57
86
  var RetryPlugin = /* @__PURE__ */ __name(({ fetch: fetchOption, script: scriptOption }) => ({
58
87
  name: "retry-plugin",
@@ -82,26 +111,33 @@ var RetryPlugin = /* @__PURE__ */ __name(({ fetch: fetchOption, script: scriptOp
82
111
  }
83
112
  return fetch(url, options);
84
113
  },
114
+ async loadEntryError({ getRemoteEntry, origin, remoteInfo, remoteEntryExports, globalLoading, uniqueKey }) {
115
+ if (!scriptOption)
116
+ return;
117
+ const retryFn = getRemoteEntry;
118
+ const beforeExecuteRetry = /* @__PURE__ */ __name(() => delete globalLoading[uniqueKey], "beforeExecuteRetry");
119
+ const getRemoteEntryRetry = scriptCommonRetry({
120
+ scriptOption,
121
+ moduleInfo: remoteInfo,
122
+ retryFn,
123
+ beforeExecuteRetry
124
+ });
125
+ return getRemoteEntryRetry({
126
+ origin,
127
+ remoteInfo,
128
+ remoteEntryExports
129
+ });
130
+ },
85
131
  async getModuleFactory({ remoteEntryExports, expose, moduleInfo }) {
86
- let moduleFactory;
87
- const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay } = scriptOption || {};
88
- if (scriptOption?.moduleName && scriptOption?.moduleName.some((m) => moduleInfo.name === m || moduleInfo?.alias === m) || scriptOption?.moduleName === void 0) {
89
- let attempts = 0;
90
- while (attempts - 1 < retryTimes) {
91
- try {
92
- moduleFactory = await remoteEntryExports.get(expose);
93
- break;
94
- } catch (error) {
95
- attempts++;
96
- if (attempts - 1 >= retryTimes) {
97
- scriptOption?.cb && await new Promise((resolve) => scriptOption?.cb && scriptOption?.cb(resolve, error));
98
- throw error;
99
- }
100
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
101
- }
102
- }
103
- }
104
- return moduleFactory;
132
+ if (!scriptOption)
133
+ return;
134
+ const retryFn = remoteEntryExports.get;
135
+ const getRemoteEntryRetry = scriptCommonRetry({
136
+ scriptOption,
137
+ moduleInfo,
138
+ retryFn
139
+ });
140
+ return getRemoteEntryRetry(expose);
105
141
  }
106
142
  }), "RetryPlugin");
107
143
  export {
package/dist/index.js CHANGED
@@ -49,7 +49,7 @@ async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries,
49
49
  return response;
50
50
  } catch (error) {
51
51
  if (retryTimes <= 0) {
52
- logger_default.log(`>>>>>>>>> retry failed after ${retryTimes} times for url: ${url}, now will try fallbackUrl url <<<<<<<<<`);
52
+ logger_default.log(`[ Module Federation RetryPlugin ]: retry failed after ${retryTimes} times for url: ${url}, now will try fallbackUrl url`);
53
53
  if (fallback && typeof fallback === "function") {
54
54
  return fetchWithRetry({
55
55
  url: fallback(url),
@@ -77,6 +77,35 @@ async function fetchWithRetry({ url, options = {}, retryTimes = defaultRetries,
77
77
  }
78
78
  __name(fetchWithRetry, "fetchWithRetry");
79
79
 
80
+ // packages/retry-plugin/src/util.ts
81
+ function scriptCommonRetry({ scriptOption, moduleInfo, retryFn, beforeExecuteRetry = /* @__PURE__ */ __name(() => {
82
+ }, "beforeExecuteRetry") }) {
83
+ return async function(...args) {
84
+ let retryResponse;
85
+ const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay } = scriptOption || {};
86
+ if (scriptOption?.moduleName && scriptOption?.moduleName.some((m) => moduleInfo.name === m || moduleInfo?.alias === m) || scriptOption?.moduleName === void 0) {
87
+ let attempts = 0;
88
+ while (attempts - 1 < retryTimes) {
89
+ try {
90
+ beforeExecuteRetry && beforeExecuteRetry();
91
+ retryResponse = await retryFn(...args);
92
+ break;
93
+ } catch (error) {
94
+ attempts++;
95
+ if (attempts - 1 >= retryTimes) {
96
+ scriptOption?.cb && await new Promise((resolve) => scriptOption?.cb && scriptOption?.cb(resolve, error));
97
+ throw error;
98
+ }
99
+ logger_default.log(`[ Module Federation RetryPlugin ]: script resource retrying ${attempts} times`);
100
+ await new Promise((resolve) => setTimeout(resolve, retryDelay));
101
+ }
102
+ }
103
+ }
104
+ return retryResponse;
105
+ };
106
+ }
107
+ __name(scriptCommonRetry, "scriptCommonRetry");
108
+
80
109
  // packages/retry-plugin/src/index.ts
81
110
  var RetryPlugin = /* @__PURE__ */ __name(({ fetch: fetchOption, script: scriptOption }) => ({
82
111
  name: "retry-plugin",
@@ -106,26 +135,33 @@ var RetryPlugin = /* @__PURE__ */ __name(({ fetch: fetchOption, script: scriptOp
106
135
  }
107
136
  return fetch(url, options);
108
137
  },
138
+ async loadEntryError({ getRemoteEntry, origin, remoteInfo, remoteEntryExports, globalLoading, uniqueKey }) {
139
+ if (!scriptOption)
140
+ return;
141
+ const retryFn = getRemoteEntry;
142
+ const beforeExecuteRetry = /* @__PURE__ */ __name(() => delete globalLoading[uniqueKey], "beforeExecuteRetry");
143
+ const getRemoteEntryRetry = scriptCommonRetry({
144
+ scriptOption,
145
+ moduleInfo: remoteInfo,
146
+ retryFn,
147
+ beforeExecuteRetry
148
+ });
149
+ return getRemoteEntryRetry({
150
+ origin,
151
+ remoteInfo,
152
+ remoteEntryExports
153
+ });
154
+ },
109
155
  async getModuleFactory({ remoteEntryExports, expose, moduleInfo }) {
110
- let moduleFactory;
111
- const { retryTimes = defaultRetries, retryDelay = defaultRetryDelay } = scriptOption || {};
112
- if (scriptOption?.moduleName && scriptOption?.moduleName.some((m) => moduleInfo.name === m || moduleInfo?.alias === m) || scriptOption?.moduleName === void 0) {
113
- let attempts = 0;
114
- while (attempts - 1 < retryTimes) {
115
- try {
116
- moduleFactory = await remoteEntryExports.get(expose);
117
- break;
118
- } catch (error) {
119
- attempts++;
120
- if (attempts - 1 >= retryTimes) {
121
- scriptOption?.cb && await new Promise((resolve) => scriptOption?.cb && scriptOption?.cb(resolve, error));
122
- throw error;
123
- }
124
- await new Promise((resolve) => setTimeout(resolve, retryDelay));
125
- }
126
- }
127
- }
128
- return moduleFactory;
156
+ if (!scriptOption)
157
+ return;
158
+ const retryFn = remoteEntryExports.get;
159
+ const getRemoteEntryRetry = scriptCommonRetry({
160
+ scriptOption,
161
+ moduleInfo,
162
+ retryFn
163
+ });
164
+ return getRemoteEntryRetry(expose);
129
165
  }
130
166
  }), "RetryPlugin");
131
167
  // Annotate the CommonJS export names for ESM import in node:
package/dist/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@module-federation/retry-plugin",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "author": "danpeen <dapeen.feng@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/module-federation/core/",
12
+ "directory": "packages/retry-plugin"
13
+ },
9
14
  "publishConfig": {
10
15
  "access": "public"
11
16
  },
package/package.json CHANGED
@@ -1,11 +1,16 @@
1
1
  {
2
2
  "name": "@module-federation/retry-plugin",
3
- "version": "0.8.1",
3
+ "version": "0.8.3",
4
4
  "author": "danpeen <dapeen.feng@gmail.com>",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "license": "MIT",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/module-federation/core/",
12
+ "directory": "packages/retry-plugin"
13
+ },
9
14
  "publishConfig": {
10
15
  "access": "public"
11
16
  },
@@ -28,9 +33,9 @@
28
33
  }
29
34
  },
30
35
  "devDependencies": {
31
- "@module-federation/runtime": "0.8.1"
36
+ "@module-federation/runtime": "0.8.3"
32
37
  },
33
38
  "dependencies": {
34
- "@module-federation/sdk": "0.8.1"
39
+ "@module-federation/sdk": "0.8.3"
35
40
  }
36
41
  }