@module-federation/runtime-core 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703

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.
Files changed (221) hide show
  1. package/README.md +1 -1
  2. package/dist/_virtual/_rolldown/runtime.cjs +19 -0
  3. package/dist/_virtual/_rolldown/runtime.js +18 -0
  4. package/dist/constant.cjs +9 -0
  5. package/dist/constant.cjs.map +1 -0
  6. package/dist/constant.js +7 -0
  7. package/dist/constant.js.map +1 -0
  8. package/dist/core.cjs +150 -0
  9. package/dist/core.cjs.map +1 -0
  10. package/dist/core.d.ts +199 -0
  11. package/dist/core.js +150 -0
  12. package/dist/core.js.map +1 -0
  13. package/dist/global.cjs +175 -0
  14. package/dist/global.cjs.map +1 -0
  15. package/dist/global.d.ts +46 -0
  16. package/dist/global.js +155 -0
  17. package/dist/global.js.map +1 -0
  18. package/dist/helpers.cjs +44 -0
  19. package/dist/helpers.cjs.map +1 -0
  20. package/dist/helpers.d.ts +30 -0
  21. package/dist/helpers.js +44 -0
  22. package/dist/helpers.js.map +1 -0
  23. package/dist/index.cjs +62 -0
  24. package/dist/index.cjs.map +1 -0
  25. package/dist/index.d.ts +30 -1
  26. package/dist/index.js +22 -0
  27. package/dist/index.js.map +1 -0
  28. package/dist/module/index.cjs +268 -0
  29. package/dist/module/index.cjs.map +1 -0
  30. package/dist/module/index.d.ts +33 -0
  31. package/dist/module/index.js +268 -0
  32. package/dist/module/index.js.map +1 -0
  33. package/dist/plugins/generate-preload-assets.cjs +182 -0
  34. package/dist/plugins/generate-preload-assets.cjs.map +1 -0
  35. package/dist/plugins/generate-preload-assets.js +182 -0
  36. package/dist/plugins/generate-preload-assets.js.map +1 -0
  37. package/dist/plugins/snapshot/SnapshotHandler.cjs +258 -0
  38. package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -0
  39. package/dist/plugins/snapshot/SnapshotHandler.d.ts +92 -0
  40. package/dist/plugins/snapshot/SnapshotHandler.js +257 -0
  41. package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -0
  42. package/dist/plugins/snapshot/disabled.cjs +13 -0
  43. package/dist/plugins/snapshot/disabled.cjs.map +1 -0
  44. package/dist/plugins/snapshot/disabled.js +13 -0
  45. package/dist/plugins/snapshot/disabled.js.map +1 -0
  46. package/dist/plugins/snapshot/index.cjs +77 -0
  47. package/dist/plugins/snapshot/index.cjs.map +1 -0
  48. package/dist/plugins/snapshot/index.js +76 -0
  49. package/dist/plugins/snapshot/index.js.map +1 -0
  50. package/dist/remote/disabled.cjs +38 -0
  51. package/dist/remote/disabled.cjs.map +1 -0
  52. package/dist/remote/disabled.js +37 -0
  53. package/dist/remote/disabled.js.map +1 -0
  54. package/dist/remote/index.cjs +458 -0
  55. package/dist/remote/index.cjs.map +1 -0
  56. package/dist/remote/index.d.ts +147 -0
  57. package/dist/remote/index.js +458 -0
  58. package/dist/remote/index.js.map +1 -0
  59. package/dist/shared/disabled.cjs +33 -0
  60. package/dist/shared/disabled.cjs.map +1 -0
  61. package/dist/shared/disabled.js +33 -0
  62. package/dist/shared/disabled.js.map +1 -0
  63. package/dist/shared/index.cjs +477 -0
  64. package/dist/shared/index.cjs.map +1 -0
  65. package/dist/shared/index.d.ts +113 -0
  66. package/dist/shared/index.js +477 -0
  67. package/dist/shared/index.js.map +1 -0
  68. package/dist/type/config.d.ts +138 -0
  69. package/dist/type/index.cjs +13 -0
  70. package/dist/type/index.cjs.map +1 -0
  71. package/dist/type/index.d.ts +11 -0
  72. package/dist/type/index.js +8 -0
  73. package/dist/type/index.js.map +1 -0
  74. package/dist/type/plugin.d.ts +28 -0
  75. package/dist/type/preload.d.ts +60 -0
  76. package/dist/types.cjs +0 -0
  77. package/dist/types.d.ts +4 -1
  78. package/dist/types.js +1 -0
  79. package/dist/utils/context.cjs +45 -0
  80. package/dist/utils/context.cjs.map +1 -0
  81. package/dist/utils/context.d.ts +1 -0
  82. package/dist/utils/context.js +44 -0
  83. package/dist/utils/context.js.map +1 -0
  84. package/dist/utils/env.cjs +10 -0
  85. package/dist/utils/env.cjs.map +1 -0
  86. package/dist/utils/env.d.ts +1 -0
  87. package/dist/utils/env.js +10 -0
  88. package/dist/utils/env.js.map +1 -0
  89. package/dist/utils/hooks/asyncHook.cjs +26 -0
  90. package/dist/utils/hooks/asyncHook.cjs.map +1 -0
  91. package/dist/utils/hooks/asyncHook.d.ts +10 -0
  92. package/dist/utils/hooks/asyncHook.js +26 -0
  93. package/dist/utils/hooks/asyncHook.js.map +1 -0
  94. package/dist/utils/hooks/asyncWaterfallHooks.cjs +44 -0
  95. package/dist/utils/hooks/asyncWaterfallHooks.cjs.map +1 -0
  96. package/dist/utils/hooks/asyncWaterfallHooks.d.ts +12 -0
  97. package/dist/utils/hooks/asyncWaterfallHooks.js +44 -0
  98. package/dist/utils/hooks/asyncWaterfallHooks.js.map +1 -0
  99. package/dist/utils/hooks/index.cjs +5 -0
  100. package/dist/utils/hooks/index.js +7 -0
  101. package/dist/utils/hooks/pluginSystem.cjs +38 -0
  102. package/dist/utils/hooks/pluginSystem.cjs.map +1 -0
  103. package/dist/utils/hooks/pluginSystem.d.ts +16 -0
  104. package/dist/utils/hooks/pluginSystem.js +38 -0
  105. package/dist/utils/hooks/pluginSystem.js.map +1 -0
  106. package/dist/utils/hooks/syncHook.cjs +37 -0
  107. package/dist/utils/hooks/syncHook.cjs.map +1 -0
  108. package/dist/utils/hooks/syncHook.d.ts +16 -0
  109. package/dist/utils/hooks/syncHook.js +36 -0
  110. package/dist/utils/hooks/syncHook.js.map +1 -0
  111. package/dist/utils/hooks/syncWaterfallHook.cjs +40 -0
  112. package/dist/utils/hooks/syncWaterfallHook.cjs.map +1 -0
  113. package/dist/utils/hooks/syncWaterfallHook.d.ts +11 -0
  114. package/dist/utils/hooks/syncWaterfallHook.js +39 -0
  115. package/dist/utils/hooks/syncWaterfallHook.js.map +1 -0
  116. package/dist/utils/index.cjs +8 -0
  117. package/dist/utils/index.d.ts +4 -0
  118. package/dist/utils/index.js +9 -0
  119. package/dist/utils/load.cjs +280 -0
  120. package/dist/utils/load.cjs.map +1 -0
  121. package/dist/utils/load.d.ts +16 -0
  122. package/dist/utils/load.js +277 -0
  123. package/dist/utils/load.js.map +1 -0
  124. package/dist/utils/logger.cjs +34 -0
  125. package/dist/utils/logger.cjs.map +1 -0
  126. package/dist/utils/logger.d.ts +10 -0
  127. package/dist/utils/logger.js +31 -0
  128. package/dist/utils/logger.js.map +1 -0
  129. package/dist/utils/manifest.cjs +56 -0
  130. package/dist/utils/manifest.cjs.map +1 -0
  131. package/dist/utils/manifest.d.ts +10 -0
  132. package/dist/utils/manifest.js +53 -0
  133. package/dist/utils/manifest.js.map +1 -0
  134. package/dist/utils/plugin.cjs +50 -0
  135. package/dist/utils/plugin.cjs.map +1 -0
  136. package/dist/utils/plugin.d.ts +1 -0
  137. package/dist/utils/plugin.js +50 -0
  138. package/dist/utils/plugin.js.map +1 -0
  139. package/dist/utils/preload.cjs +221 -0
  140. package/dist/utils/preload.cjs.map +1 -0
  141. package/dist/utils/preload.d.ts +8 -0
  142. package/dist/utils/preload.js +218 -0
  143. package/dist/utils/preload.js.map +1 -0
  144. package/dist/utils/semver/compare.cjs +48 -0
  145. package/dist/utils/semver/compare.cjs.map +1 -0
  146. package/dist/utils/semver/compare.js +47 -0
  147. package/dist/utils/semver/compare.js.map +1 -0
  148. package/dist/utils/semver/constants.cjs +41 -0
  149. package/dist/utils/semver/constants.cjs.map +1 -0
  150. package/dist/utils/semver/constants.js +31 -0
  151. package/dist/utils/semver/constants.js.map +1 -0
  152. package/dist/utils/semver/index.cjs +68 -0
  153. package/dist/utils/semver/index.cjs.map +1 -0
  154. package/dist/utils/semver/index.d.ts +5 -0
  155. package/dist/utils/semver/index.js +68 -0
  156. package/dist/utils/semver/index.js.map +1 -0
  157. package/dist/utils/semver/parser.cjs +104 -0
  158. package/dist/utils/semver/parser.cjs.map +1 -0
  159. package/dist/utils/semver/parser.js +96 -0
  160. package/dist/utils/semver/parser.js.map +1 -0
  161. package/dist/utils/semver/utils.cjs +28 -0
  162. package/dist/utils/semver/utils.cjs.map +1 -0
  163. package/dist/utils/semver/utils.js +24 -0
  164. package/dist/utils/semver/utils.js.map +1 -0
  165. package/dist/utils/share.cjs +285 -0
  166. package/dist/utils/share.cjs.map +1 -0
  167. package/dist/utils/share.d.ts +24 -0
  168. package/dist/utils/share.js +279 -0
  169. package/dist/utils/share.js.map +1 -0
  170. package/dist/utils/tool.cjs +82 -0
  171. package/dist/utils/tool.cjs.map +1 -0
  172. package/dist/utils/tool.d.ts +8 -0
  173. package/dist/utils/tool.js +71 -0
  174. package/dist/utils/tool.js.map +1 -0
  175. package/package.json +16 -9
  176. package/dist/index.cjs.cjs +0 -3226
  177. package/dist/index.cjs.cjs.map +0 -1
  178. package/dist/index.cjs.d.ts +0 -1
  179. package/dist/index.esm.js +0 -3202
  180. package/dist/index.esm.js.map +0 -1
  181. package/dist/src/constant.d.ts +0 -2
  182. package/dist/src/core.d.ts +0 -115
  183. package/dist/src/global.d.ts +0 -42
  184. package/dist/src/helpers.d.ts +0 -38
  185. package/dist/src/index.d.ts +0 -14
  186. package/dist/src/module/index.d.ts +0 -22
  187. package/dist/src/plugins/generate-preload-assets.d.ts +0 -8
  188. package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +0 -60
  189. package/dist/src/plugins/snapshot/index.d.ts +0 -5
  190. package/dist/src/remote/index.d.ts +0 -109
  191. package/dist/src/shared/index.d.ts +0 -66
  192. package/dist/src/type/config.d.ts +0 -115
  193. package/dist/src/type/index.d.ts +0 -3
  194. package/dist/src/type/plugin.d.ts +0 -35
  195. package/dist/src/type/preload.d.ts +0 -26
  196. package/dist/src/types.d.ts +0 -1
  197. package/dist/src/utils/env.d.ts +0 -3
  198. package/dist/src/utils/hooks/asyncHook.d.ts +0 -6
  199. package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +0 -10
  200. package/dist/src/utils/hooks/index.d.ts +0 -6
  201. package/dist/src/utils/hooks/pluginSystem.d.ts +0 -16
  202. package/dist/src/utils/hooks/syncHook.d.ts +0 -12
  203. package/dist/src/utils/hooks/syncWaterfallHook.d.ts +0 -9
  204. package/dist/src/utils/index.d.ts +0 -6
  205. package/dist/src/utils/load.d.ts +0 -11
  206. package/dist/src/utils/logger.d.ts +0 -6
  207. package/dist/src/utils/manifest.d.ts +0 -7
  208. package/dist/src/utils/plugin.d.ts +0 -3
  209. package/dist/src/utils/preload.d.ts +0 -6
  210. package/dist/src/utils/semver/compare.d.ts +0 -9
  211. package/dist/src/utils/semver/constants.d.ts +0 -10
  212. package/dist/src/utils/semver/index.d.ts +0 -2
  213. package/dist/src/utils/semver/parser.d.ts +0 -9
  214. package/dist/src/utils/semver/utils.d.ts +0 -11
  215. package/dist/src/utils/share.d.ts +0 -27
  216. package/dist/src/utils/tool.d.ts +0 -18
  217. package/dist/types.cjs.cjs +0 -3
  218. package/dist/types.cjs.cjs.map +0 -1
  219. package/dist/types.cjs.d.ts +0 -1
  220. package/dist/types.esm.js +0 -2
  221. package/dist/types.esm.js.map +0 -1
@@ -0,0 +1,277 @@
1
+ import { error } from "./logger.js";
2
+ import { getRemoteEntryExports, globalLoading } from "../global.js";
3
+ import { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from "../constant.js";
4
+ import { composeKeyWithSeparator, isBrowserEnvValue, loadScript, loadScriptNode } from "@module-federation/sdk";
5
+ import { RUNTIME_001, RUNTIME_008, runtimeDescMap } from "@module-federation/error-codes";
6
+
7
+ //#region src/utils/load.ts
8
+ const importCallback = ".then(callbacks[0]).catch(callbacks[1])";
9
+ const remoteEntryLoadingOrigins = /* @__PURE__ */ new WeakMap();
10
+ const esmRemoteEntryLoadErrorMessages = [
11
+ "Failed to fetch dynamically imported module",
12
+ "Importing a module script failed",
13
+ "error loading dynamically imported module"
14
+ ];
15
+ function isEsmRemoteEntryLoadError(err) {
16
+ if (!(err instanceof TypeError)) return false;
17
+ return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) => err.message.includes(loadErrorMessage));
18
+ }
19
+ function isEsmRemoteType(type) {
20
+ return type === "esm" || type === "module";
21
+ }
22
+ async function loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl }) {
23
+ return new Promise((resolve, reject) => {
24
+ const rejectEntry = (loadError) => {
25
+ if (isEsmRemoteEntryLoadError(loadError)) {
26
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
27
+ try {
28
+ error(RUNTIME_008, runtimeDescMap, {
29
+ remoteName: name,
30
+ resourceUrl: url
31
+ }, originalMsg);
32
+ } catch (runtimeError) {
33
+ reject(runtimeError);
34
+ return;
35
+ }
36
+ }
37
+ reject(loadError);
38
+ };
39
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
40
+ try {
41
+ if (!remoteEntryExports) if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== "undefined") new Function("callbacks", `import("${url}")${importCallback}`)([resolve, rejectEntry]);
42
+ else import(
43
+ /* webpackIgnore: true */
44
+ /* @vite-ignore */
45
+ url
46
+ ).then(resolve).catch(rejectEntry);
47
+ else resolve(remoteEntryExports);
48
+ } catch (e) {
49
+ error(`Failed to load ESM entry from "${url}". ${e instanceof Error ? e.message : String(e)}`);
50
+ }
51
+ });
52
+ }
53
+ async function loadSystemJsEntry({ entry, remoteEntryExports }) {
54
+ return new Promise((resolve, reject) => {
55
+ try {
56
+ if (!remoteEntryExports) if (typeof __system_context__ === "undefined") System.import(entry).then(resolve).catch(reject);
57
+ else new Function("callbacks", `System.import("${entry}")${importCallback}`)([resolve, reject]);
58
+ else resolve(remoteEntryExports);
59
+ } catch (e) {
60
+ error(`Failed to load SystemJS entry from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
61
+ }
62
+ });
63
+ }
64
+ function handleRemoteEntryLoaded(name, globalName, entry) {
65
+ const { remoteEntryKey, entryExports } = getRemoteEntryExports(name, globalName);
66
+ if (!entryExports) error(RUNTIME_001, runtimeDescMap, {
67
+ remoteName: name,
68
+ remoteEntryUrl: entry,
69
+ remoteEntryKey
70
+ });
71
+ return entryExports;
72
+ }
73
+ async function loadEntryScript({ name, globalName, entry, remoteInfo, loaderHook, getEntryUrl, resourceContext }) {
74
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
75
+ if (remoteEntryExports) return remoteEntryExports;
76
+ const url = getEntryUrl ? getEntryUrl(entry) : entry;
77
+ return loadScript(url, {
78
+ attrs: {},
79
+ createScriptHook: (url, attrs) => {
80
+ const res = loaderHook.lifecycle.createScript.emit({
81
+ url,
82
+ attrs,
83
+ remoteInfo,
84
+ resourceContext: resourceContext ? {
85
+ ...resourceContext,
86
+ url
87
+ } : void 0
88
+ });
89
+ if (!res) return;
90
+ if (res instanceof HTMLScriptElement) return res;
91
+ if ("script" in res || "timeout" in res) return res;
92
+ }
93
+ }).then(() => {
94
+ return handleRemoteEntryLoaded(name, globalName, entry);
95
+ }, (loadError) => {
96
+ const originalMsg = loadError instanceof Error ? loadError.message : String(loadError);
97
+ error(RUNTIME_008, runtimeDescMap, {
98
+ remoteName: name,
99
+ resourceUrl: url
100
+ }, originalMsg);
101
+ });
102
+ }
103
+ async function loadEntryDom({ remoteInfo, remoteEntryExports, loaderHook, getEntryUrl, resourceContext }) {
104
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
105
+ if (isEsmRemoteType(type)) return loadEsmEntry({
106
+ entry,
107
+ remoteEntryExports,
108
+ name,
109
+ getEntryUrl
110
+ });
111
+ if (type === "system") return loadSystemJsEntry({
112
+ entry,
113
+ remoteEntryExports
114
+ });
115
+ return loadEntryScript({
116
+ entry,
117
+ globalName,
118
+ name,
119
+ remoteInfo,
120
+ loaderHook,
121
+ getEntryUrl,
122
+ resourceContext
123
+ });
124
+ }
125
+ async function loadEntryNode({ remoteInfo, loaderHook, resourceContext }) {
126
+ const { entry, entryGlobalName: globalName, name, type } = remoteInfo;
127
+ const { entryExports: remoteEntryExports } = getRemoteEntryExports(name, globalName);
128
+ if (remoteEntryExports) return remoteEntryExports;
129
+ return loadScriptNode(entry, {
130
+ attrs: {
131
+ name,
132
+ globalName,
133
+ type
134
+ },
135
+ loaderHook: { createScriptHook: (url, attrs = {}) => {
136
+ const res = loaderHook.lifecycle.createScript.emit({
137
+ url,
138
+ attrs,
139
+ remoteInfo,
140
+ resourceContext: resourceContext ? {
141
+ ...resourceContext,
142
+ url
143
+ } : void 0
144
+ });
145
+ if (!res) return;
146
+ if ("url" in res) return res;
147
+ } }
148
+ }).then(() => {
149
+ return handleRemoteEntryLoaded(name, globalName, entry);
150
+ }).catch((e) => {
151
+ error(`Failed to load Node.js entry for remote "${name}" from "${entry}". ${e instanceof Error ? e.message : String(e)}`);
152
+ });
153
+ }
154
+ function getRemoteEntryUniqueKey(remoteInfo) {
155
+ const { entry, name } = remoteInfo;
156
+ return composeKeyWithSeparator(name, entry);
157
+ }
158
+ async function getRemoteEntry(params) {
159
+ const { origin, remoteEntryExports, remoteInfo, getEntryUrl, resourceContext, _inErrorHandling = false } = params;
160
+ const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);
161
+ if (remoteEntryExports) {
162
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
163
+ origin,
164
+ remoteInfo,
165
+ remoteEntryExports,
166
+ resourceContext,
167
+ cached: true
168
+ });
169
+ return remoteEntryExports;
170
+ }
171
+ if (!globalLoading[uniqueKey]) {
172
+ const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;
173
+ const loaderHook = origin.loaderHook;
174
+ const loading = loadEntryHook.emit({
175
+ origin,
176
+ loaderHook,
177
+ remoteInfo,
178
+ remoteEntryExports,
179
+ resourceContext
180
+ }).then((res) => {
181
+ if (res) return res;
182
+ return (typeof ENV_TARGET !== "undefined" ? ENV_TARGET === "web" : isBrowserEnvValue) ? loadEntryDom({
183
+ remoteInfo,
184
+ remoteEntryExports,
185
+ loaderHook,
186
+ getEntryUrl,
187
+ resourceContext
188
+ }) : loadEntryNode({
189
+ remoteInfo,
190
+ loaderHook,
191
+ resourceContext
192
+ });
193
+ }).then(async (res) => {
194
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
195
+ origin,
196
+ remoteInfo,
197
+ remoteEntryExports: res,
198
+ resourceContext
199
+ });
200
+ return res;
201
+ }).catch(async (loadError) => {
202
+ const isScriptExecutionError = loadError instanceof Error && loadError.message.includes("ScriptExecutionError");
203
+ if (loadError instanceof Error && loadError.message.includes(RUNTIME_008) && !isScriptExecutionError && !_inErrorHandling) {
204
+ const wrappedGetRemoteEntry = (params) => {
205
+ return getRemoteEntry({
206
+ ...params,
207
+ _inErrorHandling: true
208
+ });
209
+ };
210
+ const recoveredRemoteEntryExports = await origin.loaderHook.lifecycle.loadEntryError.emit({
211
+ getRemoteEntry: wrappedGetRemoteEntry,
212
+ origin,
213
+ remoteInfo,
214
+ remoteEntryExports,
215
+ globalLoading,
216
+ uniqueKey
217
+ });
218
+ if (recoveredRemoteEntryExports) {
219
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
220
+ origin,
221
+ remoteInfo,
222
+ remoteEntryExports: recoveredRemoteEntryExports,
223
+ resourceContext,
224
+ error: loadError,
225
+ recovered: true
226
+ });
227
+ return recoveredRemoteEntryExports;
228
+ }
229
+ }
230
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
231
+ origin,
232
+ remoteInfo,
233
+ resourceContext,
234
+ error: loadError
235
+ });
236
+ throw loadError;
237
+ });
238
+ globalLoading[uniqueKey] = loading;
239
+ loading.then(void 0, () => {
240
+ if (globalLoading[uniqueKey] === loading) delete globalLoading[uniqueKey];
241
+ });
242
+ remoteEntryLoadingOrigins.set(loading, origin);
243
+ }
244
+ const remoteEntryLoading = globalLoading[uniqueKey];
245
+ if (remoteEntryLoadingOrigins.get(remoteEntryLoading) !== origin) try {
246
+ const result = await remoteEntryLoading;
247
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
248
+ origin,
249
+ remoteInfo,
250
+ remoteEntryExports: result,
251
+ resourceContext
252
+ });
253
+ return result;
254
+ } catch (loadError) {
255
+ await origin.loaderHook.lifecycle.afterLoadEntry.emit({
256
+ origin,
257
+ remoteInfo,
258
+ resourceContext,
259
+ error: loadError
260
+ });
261
+ throw loadError;
262
+ }
263
+ return remoteEntryLoading;
264
+ }
265
+ function getRemoteInfo(remote) {
266
+ return {
267
+ ...remote,
268
+ entry: "entry" in remote ? remote.entry : "",
269
+ type: remote.type || DEFAULT_REMOTE_TYPE,
270
+ entryGlobalName: remote.entryGlobalName || remote.name,
271
+ shareScope: remote.shareScope || DEFAULT_SCOPE
272
+ };
273
+ }
274
+
275
+ //#endregion
276
+ export { getRemoteEntry, getRemoteEntryUniqueKey, getRemoteInfo, isEsmRemoteType };
277
+ //# sourceMappingURL=load.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load.js","names":[],"sources":["../../src/utils/load.ts"],"sourcesContent":["import {\n loadScript,\n loadScriptNode,\n composeKeyWithSeparator,\n isBrowserEnvValue,\n} from '@module-federation/sdk';\nimport { DEFAULT_REMOTE_TYPE, DEFAULT_SCOPE } from '../constant';\nimport { ModuleFederation } from '../core';\nimport { globalLoading, getRemoteEntryExports } from '../global';\nimport {\n Remote,\n RemoteEntryExports,\n RemoteInfo,\n ResourceLoadContext,\n} from '../type';\nimport { assert, error } from './logger';\nimport {\n RUNTIME_001,\n RUNTIME_008,\n runtimeDescMap,\n} from '@module-federation/error-codes';\n\n// Declare the ENV_TARGET constant that will be defined by DefinePlugin\ndeclare const ENV_TARGET: 'web' | 'node';\nconst importCallback = '.then(callbacks[0]).catch(callbacks[1])';\nconst remoteEntryLoadingOrigins = new WeakMap<\n Promise<RemoteEntryExports | void>,\n ModuleFederation\n>();\n\nconst esmRemoteEntryLoadErrorMessages = [\n 'Failed to fetch dynamically imported module',\n 'Importing a module script failed',\n 'error loading dynamically imported module',\n];\n\nfunction isEsmRemoteEntryLoadError(err: unknown): boolean {\n if (!(err instanceof TypeError)) {\n return false;\n }\n\n return esmRemoteEntryLoadErrorMessages.some((loadErrorMessage) =>\n err.message.includes(loadErrorMessage),\n );\n}\n\nexport function isEsmRemoteType(type: RemoteInfo['type']): boolean {\n return type === 'esm' || type === 'module';\n}\n\nasync function loadEsmEntry({\n entry,\n remoteEntryExports,\n name,\n getEntryUrl,\n}: {\n entry: string;\n remoteEntryExports: RemoteEntryExports | undefined;\n name: string;\n getEntryUrl?: (url: string) => string;\n}): Promise<RemoteEntryExports> {\n return new Promise<RemoteEntryExports>((resolve, reject) => {\n const rejectEntry = (loadError: unknown) => {\n if (isEsmRemoteEntryLoadError(loadError)) {\n const originalMsg =\n loadError instanceof Error ? loadError.message : String(loadError);\n try {\n error(\n RUNTIME_008,\n runtimeDescMap,\n {\n remoteName: name,\n resourceUrl: url,\n },\n originalMsg,\n );\n } catch (runtimeError) {\n reject(runtimeError);\n return;\n }\n }\n\n reject(loadError);\n };\n\n const url = getEntryUrl ? getEntryUrl(entry) : entry;\n try {\n if (!remoteEntryExports) {\n if (typeof FEDERATION_ALLOW_NEW_FUNCTION !== 'undefined') {\n new Function('callbacks', `import(\"${url}\")${importCallback}`)([\n resolve,\n rejectEntry,\n ]);\n } else {\n import(/* webpackIgnore: true */ /* @vite-ignore */ url)\n .then(resolve)\n .catch(rejectEntry);\n }\n } else {\n resolve(remoteEntryExports);\n }\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n error(`Failed to load ESM entry from \"${url}\". ${msg}`);\n }\n });\n}\n\nasync function loadSystemJsEntry({\n entry,\n remoteEntryExports,\n}: {\n entry: string;\n remoteEntryExports: RemoteEntryExports | undefined;\n}): Promise<RemoteEntryExports> {\n return new Promise<RemoteEntryExports>((resolve, reject) => {\n try {\n if (!remoteEntryExports) {\n //@ts-ignore\n if (typeof __system_context__ === 'undefined') {\n //@ts-ignore\n System.import(entry).then(resolve).catch(reject);\n } else {\n new Function(\n 'callbacks',\n `System.import(\"${entry}\")${importCallback}`,\n )([resolve, reject]);\n }\n } else {\n resolve(remoteEntryExports);\n }\n } catch (e) {\n const msg = e instanceof Error ? e.message : String(e);\n error(`Failed to load SystemJS entry from \"${entry}\". ${msg}`);\n }\n });\n}\n\nfunction handleRemoteEntryLoaded(\n name: string,\n globalName: string,\n entry: string,\n): RemoteEntryExports {\n const { remoteEntryKey, entryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (!entryExports) {\n error(RUNTIME_001, runtimeDescMap, {\n remoteName: name,\n remoteEntryUrl: entry,\n remoteEntryKey,\n });\n }\n\n return entryExports;\n}\n\nasync function loadEntryScript({\n name,\n globalName,\n entry,\n remoteInfo,\n loaderHook,\n getEntryUrl,\n resourceContext,\n}: {\n name: string;\n globalName: string;\n entry: string;\n remoteInfo: RemoteInfo;\n loaderHook: ModuleFederation['loaderHook'];\n getEntryUrl?: (url: string) => string;\n resourceContext?: ResourceLoadContext;\n}): Promise<RemoteEntryExports> {\n const { entryExports: remoteEntryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n // if getEntryUrl is passed, use the getEntryUrl to get the entry url\n const url = getEntryUrl ? getEntryUrl(entry) : entry;\n return loadScript(url, {\n attrs: {},\n createScriptHook: (url, attrs) => {\n const res = loaderHook.lifecycle.createScript.emit({\n url,\n attrs,\n remoteInfo,\n resourceContext: resourceContext\n ? {\n ...resourceContext,\n url,\n }\n : undefined,\n });\n\n if (!res) return;\n\n if (res instanceof HTMLScriptElement) {\n return res;\n }\n\n if ('script' in res || 'timeout' in res) {\n return res;\n }\n\n return;\n },\n }).then(\n () => {\n // loadScript resolved: script was fetched, executed without throwing, and\n // did not trigger a ScriptExecutionError listener. Now verify the global was registered.\n return handleRemoteEntryLoaded(name, globalName, entry);\n },\n (loadError: unknown) => {\n // loadScript rejected — one of three causes, all with descriptive messages:\n // ScriptNetworkError — URL unreachable, 404, CORS, etc.\n // ScriptExecutionError — script fetched OK but IIFE threw during execution\n // timeout — script took too long to load\n // Errors thrown inside handleRemoteEntryLoaded above are NOT caught here.\n const originalMsg =\n loadError instanceof Error ? loadError.message : String(loadError);\n error(\n RUNTIME_008,\n runtimeDescMap,\n {\n remoteName: name,\n resourceUrl: url,\n },\n originalMsg,\n );\n },\n );\n}\nasync function loadEntryDom({\n remoteInfo,\n remoteEntryExports,\n loaderHook,\n getEntryUrl,\n resourceContext,\n}: {\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports;\n loaderHook: ModuleFederation['loaderHook'];\n getEntryUrl?: (url: string) => string;\n resourceContext?: ResourceLoadContext;\n}) {\n const { entry, entryGlobalName: globalName, name, type } = remoteInfo;\n if (isEsmRemoteType(type)) {\n return loadEsmEntry({ entry, remoteEntryExports, name, getEntryUrl });\n }\n\n if (type === 'system') {\n return loadSystemJsEntry({ entry, remoteEntryExports });\n }\n\n return loadEntryScript({\n entry,\n globalName,\n name,\n remoteInfo,\n loaderHook,\n getEntryUrl,\n resourceContext,\n });\n}\n\nasync function loadEntryNode({\n remoteInfo,\n loaderHook,\n resourceContext,\n}: {\n remoteInfo: RemoteInfo;\n loaderHook: ModuleFederation['loaderHook'];\n resourceContext?: ResourceLoadContext;\n}) {\n const { entry, entryGlobalName: globalName, name, type } = remoteInfo;\n const { entryExports: remoteEntryExports } = getRemoteEntryExports(\n name,\n globalName,\n );\n\n if (remoteEntryExports) {\n return remoteEntryExports;\n }\n\n return loadScriptNode(entry, {\n attrs: { name, globalName, type },\n loaderHook: {\n createScriptHook: (url: string, attrs: Record<string, any> = {}) => {\n const res = loaderHook.lifecycle.createScript.emit({\n url,\n attrs,\n remoteInfo,\n resourceContext: resourceContext\n ? {\n ...resourceContext,\n url,\n }\n : undefined,\n });\n\n if (!res) return;\n\n if ('url' in res) {\n return res;\n }\n\n return;\n },\n },\n })\n .then(() => {\n return handleRemoteEntryLoaded(name, globalName, entry);\n })\n .catch((e) => {\n const msg = e instanceof Error ? e.message : String(e);\n error(\n `Failed to load Node.js entry for remote \"${name}\" from \"${entry}\". ${msg}`,\n );\n });\n}\n\nexport function getRemoteEntryUniqueKey(remoteInfo: RemoteInfo): string {\n const { entry, name } = remoteInfo;\n return composeKeyWithSeparator(name, entry);\n}\n\nexport async function getRemoteEntry(params: {\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n getEntryUrl?: (url: string) => string;\n _inErrorHandling?: boolean; // Add flag to prevent recursion\n resourceContext?: ResourceLoadContext;\n}): Promise<RemoteEntryExports | false | void> {\n const {\n origin,\n remoteEntryExports,\n remoteInfo,\n getEntryUrl,\n resourceContext,\n _inErrorHandling = false,\n } = params;\n const uniqueKey = getRemoteEntryUniqueKey(remoteInfo);\n\n if (remoteEntryExports) {\n await origin.loaderHook.lifecycle.afterLoadEntry.emit({\n origin,\n remoteInfo,\n remoteEntryExports,\n resourceContext,\n cached: true,\n });\n return remoteEntryExports;\n }\n\n if (!globalLoading[uniqueKey]) {\n const loadEntryHook = origin.remoteHandler.hooks.lifecycle.loadEntry;\n const loaderHook = origin.loaderHook;\n const loading = loadEntryHook\n .emit({\n origin,\n loaderHook,\n remoteInfo,\n remoteEntryExports,\n resourceContext,\n })\n .then((res) => {\n if (res) {\n return res;\n }\n const isWebEnvironment =\n typeof ENV_TARGET !== 'undefined'\n ? ENV_TARGET === 'web'\n : isBrowserEnvValue;\n\n return isWebEnvironment\n ? loadEntryDom({\n remoteInfo,\n remoteEntryExports,\n loaderHook,\n getEntryUrl,\n resourceContext,\n })\n : loadEntryNode({ remoteInfo, loaderHook, resourceContext });\n })\n .then(async (res) => {\n await origin.loaderHook.lifecycle.afterLoadEntry.emit({\n origin,\n remoteInfo,\n remoteEntryExports: res,\n resourceContext,\n });\n return res;\n })\n .catch(async (loadError) => {\n const isScriptExecutionError =\n loadError instanceof Error &&\n loadError.message.includes('ScriptExecutionError');\n const isScriptLoadError =\n loadError instanceof Error &&\n loadError.message.includes(RUNTIME_008) &&\n !isScriptExecutionError;\n\n if (isScriptLoadError && !_inErrorHandling) {\n const wrappedGetRemoteEntry = (\n params: Parameters<typeof getRemoteEntry>[0],\n ) => {\n return getRemoteEntry({ ...params, _inErrorHandling: true });\n };\n\n const recoveredRemoteEntryExports =\n await origin.loaderHook.lifecycle.loadEntryError.emit({\n getRemoteEntry: wrappedGetRemoteEntry,\n origin,\n remoteInfo,\n remoteEntryExports,\n globalLoading,\n uniqueKey,\n });\n\n if (recoveredRemoteEntryExports) {\n await origin.loaderHook.lifecycle.afterLoadEntry.emit({\n origin,\n remoteInfo,\n remoteEntryExports: recoveredRemoteEntryExports,\n resourceContext,\n error: loadError,\n recovered: true,\n });\n return recoveredRemoteEntryExports;\n }\n }\n\n await origin.loaderHook.lifecycle.afterLoadEntry.emit({\n origin,\n remoteInfo,\n resourceContext,\n error: loadError,\n });\n throw loadError;\n });\n\n globalLoading[uniqueKey] = loading;\n // Clear rejected entries so a later call can retry. Keep the original\n // promise identity in the cache (do not replace with a cleanup thenable).\n // Identity check: an older rejection must not delete a newer in-flight request.\n loading.then(undefined, () => {\n if (globalLoading[uniqueKey] === loading) {\n delete globalLoading[uniqueKey];\n }\n });\n remoteEntryLoadingOrigins.set(loading, origin);\n }\n\n const remoteEntryLoading = globalLoading[uniqueKey];\n if (remoteEntryLoadingOrigins.get(remoteEntryLoading) !== origin) {\n try {\n const result = await remoteEntryLoading;\n await origin.loaderHook.lifecycle.afterLoadEntry.emit({\n origin,\n remoteInfo,\n remoteEntryExports: result,\n resourceContext,\n });\n return result;\n } catch (loadError) {\n await origin.loaderHook.lifecycle.afterLoadEntry.emit({\n origin,\n remoteInfo,\n resourceContext,\n error: loadError,\n });\n throw loadError;\n }\n }\n\n return remoteEntryLoading;\n}\n\nexport function getRemoteInfo(remote: Remote): RemoteInfo {\n return {\n ...remote,\n entry: 'entry' in remote ? remote.entry : '',\n type: remote.type || DEFAULT_REMOTE_TYPE,\n entryGlobalName: remote.entryGlobalName || remote.name,\n shareScope: remote.shareScope || DEFAULT_SCOPE,\n };\n}\n"],"mappings":";;;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QAAM,OAAO,WAAW,UAAU,eAAe,KAAK;GACpD;GACA;GACA;GACA,OAAO;GACR,CAAC;AACF,QAAM;;AAIV,QAAO;;AAGT,SAAgB,cAAc,QAA4B;AACxD,QAAO;EACL,GAAG;EACH,OAAO,WAAW,SAAS,OAAO,QAAQ;EAC1C,MAAM,OAAO,QAAQ;EACrB,iBAAiB,OAAO,mBAAmB,OAAO;EAClD,YAAY,OAAO,cAAc;EAClC"}
@@ -0,0 +1,34 @@
1
+ let _module_federation_sdk = require("@module-federation/sdk");
2
+ let _module_federation_error_codes_browser = require("@module-federation/error-codes/browser");
3
+
4
+ //#region src/utils/logger.ts
5
+ const LOG_CATEGORY = "[ Federation Runtime ]";
6
+ const logger = (0, _module_federation_sdk.createLogger)(LOG_CATEGORY);
7
+ function assert(condition, msgOrCode, descMap, args, context) {
8
+ if (!condition) if (descMap !== void 0) error(msgOrCode, descMap, args, void 0, context);
9
+ else error(msgOrCode);
10
+ }
11
+ function error(msgOrCode, descMap, args, originalErrorMsg, context) {
12
+ if (descMap !== void 0) return (0, _module_federation_error_codes_browser.logAndReport)(msgOrCode, descMap, args ?? {}, (msg) => {
13
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
14
+ }, originalErrorMsg, context);
15
+ const msg = msgOrCode;
16
+ if (msg instanceof Error) {
17
+ if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
18
+ throw msg;
19
+ }
20
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
21
+ }
22
+ function warn(msg) {
23
+ if (msg instanceof Error) {
24
+ if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
25
+ logger.warn(msg);
26
+ } else logger.warn(msg);
27
+ }
28
+
29
+ //#endregion
30
+ exports.assert = assert;
31
+ exports.error = error;
32
+ exports.logger = logger;
33
+ exports.warn = warn;
34
+ //# sourceMappingURL=logger.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.cjs","names":[],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { createLogger } from '@module-federation/sdk';\nimport type { MFContext } from '@module-federation/error-codes';\nimport { logAndReport } from '@module-federation/error-codes/browser';\n\nconst LOG_CATEGORY = '[ Federation Runtime ]';\n// FIXME: pre-bundle ?\nconst logger = createLogger(LOG_CATEGORY);\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function assert(condition: any, msg: string): asserts condition;\nexport function assert(\n condition: any,\n code: string,\n descMap: Record<string, string>,\n args?: Record<string, unknown>,\n context?: Partial<MFContext>,\n): asserts condition;\nexport function assert(\n condition: any,\n msgOrCode: string,\n descMap?: Record<string, string>,\n args?: Record<string, unknown>,\n context?: Partial<MFContext>,\n): asserts condition {\n if (!condition) {\n if (descMap !== undefined) {\n error(msgOrCode, descMap, args, undefined, context);\n } else {\n error(msgOrCode);\n }\n }\n}\n\nexport function error(msg: string | Error | unknown): never;\nexport function error(\n code: string,\n descMap: Record<string, string>,\n args?: Record<string, unknown>,\n originalErrorMsg?: string,\n context?: Partial<MFContext>,\n): never;\nexport function error(\n msgOrCode: string | Error | unknown,\n descMap?: Record<string, string>,\n args?: Record<string, unknown>,\n originalErrorMsg?: string,\n context?: Partial<MFContext>,\n): never {\n if (descMap !== undefined) {\n return logAndReport(\n msgOrCode as string,\n descMap,\n args ?? {},\n (msg) => {\n throw new Error(`${LOG_CATEGORY}: ${msg}`);\n },\n originalErrorMsg,\n context,\n );\n }\n const msg = msgOrCode;\n if (msg instanceof Error) {\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n throw msg;\n }\n throw new Error(`${LOG_CATEGORY}: ${msg}`);\n}\n\nexport function warn(msg: Parameters<typeof console.warn>[0]): void {\n if (msg instanceof Error) {\n // Check if the message already starts with the log category to avoid duplication\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n logger.warn(msg);\n } else {\n logger.warn(msg);\n }\n}\n\nexport { logger };\n"],"mappings":";;;;AAIA,MAAM,eAAe;AAErB,MAAM,kDAAsB,aAAa;AAWzC,SAAgB,OACd,WACA,WACA,SACA,MACA,SACmB;AACnB,KAAI,CAAC,UACH,KAAI,YAAY,OACd,OAAM,WAAW,SAAS,MAAM,QAAW,QAAQ;KAEnD,OAAM,UAAU;;AAatB,SAAgB,MACd,WACA,SACA,MACA,kBACA,SACO;AACP,KAAI,YAAY,OACd,iEACE,WACA,SACA,QAAQ,EAAE,GACT,QAAQ;AACP,QAAM,IAAI,MAAM,GAAG,aAAa,IAAI,MAAM;IAE5C,kBACA,QACD;CAEH,MAAM,MAAM;AACZ,KAAI,eAAe,OAAO;AACxB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,QAAM;;AAER,OAAM,IAAI,MAAM,GAAG,aAAa,IAAI,MAAM;;AAG5C,SAAgB,KAAK,KAA+C;AAClE,KAAI,eAAe,OAAO;AAExB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,SAAO,KAAK,IAAI;OAEhB,QAAO,KAAK,IAAI"}
@@ -0,0 +1,10 @@
1
+ import { MFContext } from "@module-federation/error-codes";
2
+
3
+ //#region src/utils/logger.d.ts
4
+ declare function assert(condition: any, msg: string): asserts condition;
5
+ declare function assert(condition: any, code: string, descMap: Record<string, string>, args?: Record<string, unknown>, context?: Partial<MFContext>): asserts condition;
6
+ declare function error(msg: string | Error | unknown): never;
7
+ declare function error(code: string, descMap: Record<string, string>, args?: Record<string, unknown>, originalErrorMsg?: string, context?: Partial<MFContext>): never;
8
+ //#endregion
9
+ export { assert, error };
10
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1,31 @@
1
+ import { createLogger } from "@module-federation/sdk";
2
+ import { logAndReport } from "@module-federation/error-codes/browser";
3
+
4
+ //#region src/utils/logger.ts
5
+ const LOG_CATEGORY = "[ Federation Runtime ]";
6
+ const logger = createLogger(LOG_CATEGORY);
7
+ function assert(condition, msgOrCode, descMap, args, context) {
8
+ if (!condition) if (descMap !== void 0) error(msgOrCode, descMap, args, void 0, context);
9
+ else error(msgOrCode);
10
+ }
11
+ function error(msgOrCode, descMap, args, originalErrorMsg, context) {
12
+ if (descMap !== void 0) return logAndReport(msgOrCode, descMap, args ?? {}, (msg) => {
13
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
14
+ }, originalErrorMsg, context);
15
+ const msg = msgOrCode;
16
+ if (msg instanceof Error) {
17
+ if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
18
+ throw msg;
19
+ }
20
+ throw new Error(`${LOG_CATEGORY}: ${msg}`);
21
+ }
22
+ function warn$1(msg) {
23
+ if (msg instanceof Error) {
24
+ if (!msg.message.startsWith(LOG_CATEGORY)) msg.message = `${LOG_CATEGORY}: ${msg.message}`;
25
+ logger.warn(msg);
26
+ } else logger.warn(msg);
27
+ }
28
+
29
+ //#endregion
30
+ export { assert, error, logger, warn$1 as warn };
31
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","names":["warn"],"sources":["../../src/utils/logger.ts"],"sourcesContent":["import { createLogger } from '@module-federation/sdk';\nimport type { MFContext } from '@module-federation/error-codes';\nimport { logAndReport } from '@module-federation/error-codes/browser';\n\nconst LOG_CATEGORY = '[ Federation Runtime ]';\n// FIXME: pre-bundle ?\nconst logger = createLogger(LOG_CATEGORY);\n\n// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\nexport function assert(condition: any, msg: string): asserts condition;\nexport function assert(\n condition: any,\n code: string,\n descMap: Record<string, string>,\n args?: Record<string, unknown>,\n context?: Partial<MFContext>,\n): asserts condition;\nexport function assert(\n condition: any,\n msgOrCode: string,\n descMap?: Record<string, string>,\n args?: Record<string, unknown>,\n context?: Partial<MFContext>,\n): asserts condition {\n if (!condition) {\n if (descMap !== undefined) {\n error(msgOrCode, descMap, args, undefined, context);\n } else {\n error(msgOrCode);\n }\n }\n}\n\nexport function error(msg: string | Error | unknown): never;\nexport function error(\n code: string,\n descMap: Record<string, string>,\n args?: Record<string, unknown>,\n originalErrorMsg?: string,\n context?: Partial<MFContext>,\n): never;\nexport function error(\n msgOrCode: string | Error | unknown,\n descMap?: Record<string, string>,\n args?: Record<string, unknown>,\n originalErrorMsg?: string,\n context?: Partial<MFContext>,\n): never {\n if (descMap !== undefined) {\n return logAndReport(\n msgOrCode as string,\n descMap,\n args ?? {},\n (msg) => {\n throw new Error(`${LOG_CATEGORY}: ${msg}`);\n },\n originalErrorMsg,\n context,\n );\n }\n const msg = msgOrCode;\n if (msg instanceof Error) {\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n throw msg;\n }\n throw new Error(`${LOG_CATEGORY}: ${msg}`);\n}\n\nexport function warn(msg: Parameters<typeof console.warn>[0]): void {\n if (msg instanceof Error) {\n // Check if the message already starts with the log category to avoid duplication\n if (!msg.message.startsWith(LOG_CATEGORY)) {\n msg.message = `${LOG_CATEGORY}: ${msg.message}`;\n }\n logger.warn(msg);\n } else {\n logger.warn(msg);\n }\n}\n\nexport { logger };\n"],"mappings":";;;;AAIA,MAAM,eAAe;AAErB,MAAM,SAAS,aAAa,aAAa;AAWzC,SAAgB,OACd,WACA,WACA,SACA,MACA,SACmB;AACnB,KAAI,CAAC,UACH,KAAI,YAAY,OACd,OAAM,WAAW,SAAS,MAAM,QAAW,QAAQ;KAEnD,OAAM,UAAU;;AAatB,SAAgB,MACd,WACA,SACA,MACA,kBACA,SACO;AACP,KAAI,YAAY,OACd,QAAO,aACL,WACA,SACA,QAAQ,EAAE,GACT,QAAQ;AACP,QAAM,IAAI,MAAM,GAAG,aAAa,IAAI,MAAM;IAE5C,kBACA,QACD;CAEH,MAAM,MAAM;AACZ,KAAI,eAAe,OAAO;AACxB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,QAAM;;AAER,OAAM,IAAI,MAAM,GAAG,aAAa,IAAI,MAAM;;AAG5C,SAAgBA,OAAK,KAA+C;AAClE,KAAI,eAAe,OAAO;AAExB,MAAI,CAAC,IAAI,QAAQ,WAAW,aAAa,CACvC,KAAI,UAAU,GAAG,aAAa,IAAI,IAAI;AAExC,SAAO,KAAK,IAAI;OAEhB,QAAO,KAAK,IAAI"}
@@ -0,0 +1,56 @@
1
+
2
+ //#region src/utils/manifest.ts
3
+ function composeRemoteRequestId(remoteName, expose) {
4
+ if (!expose || expose === ".") return remoteName;
5
+ return `${remoteName}/${expose.replace(/^\.\//, "")}`;
6
+ }
7
+ function matchRemoteWithNameAndExpose(remotes, id) {
8
+ for (const remote of remotes) {
9
+ const isNameMatched = id.startsWith(remote.name);
10
+ let expose = id.replace(remote.name, "");
11
+ if (isNameMatched) {
12
+ if (expose.startsWith("/")) {
13
+ const pkgNameOrAlias = remote.name;
14
+ expose = `.${expose}`;
15
+ return {
16
+ pkgNameOrAlias,
17
+ expose,
18
+ remote
19
+ };
20
+ } else if (expose === "") return {
21
+ pkgNameOrAlias: remote.name,
22
+ expose: ".",
23
+ remote
24
+ };
25
+ }
26
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
27
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
28
+ if (remote.alias && isAliasMatched) {
29
+ if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
30
+ const pkgNameOrAlias = remote.alias;
31
+ exposeWithAlias = `.${exposeWithAlias}`;
32
+ return {
33
+ pkgNameOrAlias,
34
+ expose: exposeWithAlias,
35
+ remote
36
+ };
37
+ } else if (exposeWithAlias === "") return {
38
+ pkgNameOrAlias: remote.alias,
39
+ expose: ".",
40
+ remote
41
+ };
42
+ }
43
+ }
44
+ }
45
+ function matchRemote(remotes, nameOrAlias) {
46
+ for (const remote of remotes) {
47
+ if (nameOrAlias === remote.name) return remote;
48
+ if (remote.alias && nameOrAlias === remote.alias) return remote;
49
+ }
50
+ }
51
+
52
+ //#endregion
53
+ exports.composeRemoteRequestId = composeRemoteRequestId;
54
+ exports.matchRemote = matchRemote;
55
+ exports.matchRemoteWithNameAndExpose = matchRemoteWithNameAndExpose;
56
+ //# sourceMappingURL=manifest.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.cjs","names":[],"sources":["../../src/utils/manifest.ts"],"sourcesContent":["import { Remote } from '../type';\n\nexport function composeRemoteRequestId(\n remoteName: string,\n expose?: string,\n): string {\n if (!expose || expose === '.') {\n return remoteName;\n }\n\n return `${remoteName}/${expose.replace(/^\\.\\//, '')}`;\n}\n\n// Function to match a remote with its name and expose\n// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n// id: alias(app1) + expose(button) = app1/button\n// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\nexport function matchRemoteWithNameAndExpose(\n remotes: Array<Remote>,\n id: string,\n):\n | {\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n }\n | undefined {\n for (const remote of remotes) {\n // match pkgName\n const isNameMatched = id.startsWith(remote.name);\n let expose = id.replace(remote.name, '');\n if (isNameMatched) {\n if (expose.startsWith('/')) {\n const pkgNameOrAlias = remote.name;\n expose = `.${expose}`;\n return {\n pkgNameOrAlias,\n expose,\n remote,\n };\n } else if (expose === '') {\n return {\n pkgNameOrAlias: remote.name,\n expose: '.',\n remote,\n };\n }\n }\n\n // match alias\n const isAliasMatched = remote.alias && id.startsWith(remote.alias);\n let exposeWithAlias = remote.alias && id.replace(remote.alias, '');\n if (remote.alias && isAliasMatched) {\n if (exposeWithAlias && exposeWithAlias.startsWith('/')) {\n const pkgNameOrAlias = remote.alias;\n exposeWithAlias = `.${exposeWithAlias}`;\n return {\n pkgNameOrAlias,\n expose: exposeWithAlias,\n remote,\n };\n } else if (exposeWithAlias === '') {\n return {\n pkgNameOrAlias: remote.alias,\n expose: '.',\n remote,\n };\n }\n }\n }\n\n return;\n}\n\n// Function to match a remote with its name or alias\nexport function matchRemote(\n remotes: Array<Remote>,\n nameOrAlias: string,\n): Remote | undefined {\n for (const remote of remotes) {\n const isNameMatched = nameOrAlias === remote.name;\n if (isNameMatched) {\n return remote;\n }\n\n const isAliasMatched = remote.alias && nameOrAlias === remote.alias;\n if (isAliasMatched) {\n return remote;\n }\n }\n return;\n}\n"],"mappings":";;AAEA,SAAgB,uBACd,YACA,QACQ;AACR,KAAI,CAAC,UAAU,WAAW,IACxB,QAAO;AAGT,QAAO,GAAG,WAAW,GAAG,OAAO,QAAQ,SAAS,GAAG;;AAOrD,SAAgB,6BACd,SACA,IAOY;AACZ,MAAK,MAAM,UAAU,SAAS;EAE5B,MAAM,gBAAgB,GAAG,WAAW,OAAO,KAAK;EAChD,IAAI,SAAS,GAAG,QAAQ,OAAO,MAAM,GAAG;AACxC,MAAI,eACF;OAAI,OAAO,WAAW,IAAI,EAAE;IAC1B,MAAM,iBAAiB,OAAO;AAC9B,aAAS,IAAI;AACb,WAAO;KACL;KACA;KACA;KACD;cACQ,WAAW,GACpB,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;EAKL,MAAM,iBAAiB,OAAO,SAAS,GAAG,WAAW,OAAO,MAAM;EAClE,IAAI,kBAAkB,OAAO,SAAS,GAAG,QAAQ,OAAO,OAAO,GAAG;AAClE,MAAI,OAAO,SAAS,gBAClB;OAAI,mBAAmB,gBAAgB,WAAW,IAAI,EAAE;IACtD,MAAM,iBAAiB,OAAO;AAC9B,sBAAkB,IAAI;AACtB,WAAO;KACL;KACA,QAAQ;KACR;KACD;cACQ,oBAAoB,GAC7B,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;;;AAST,SAAgB,YACd,SACA,aACoB;AACpB,MAAK,MAAM,UAAU,SAAS;AAE5B,MADsB,gBAAgB,OAAO,KAE3C,QAAO;AAIT,MADuB,OAAO,SAAS,gBAAgB,OAAO,MAE5D,QAAO"}
@@ -0,0 +1,10 @@
1
+ import { Remote } from "../type/config.js";
2
+ //#region src/utils/manifest.d.ts
3
+ declare function matchRemoteWithNameAndExpose(remotes: Array<Remote>, id: string): {
4
+ pkgNameOrAlias: string;
5
+ expose: string;
6
+ remote: Remote;
7
+ } | undefined;
8
+ //#endregion
9
+ export { matchRemoteWithNameAndExpose };
10
+ //# sourceMappingURL=manifest.d.ts.map
@@ -0,0 +1,53 @@
1
+ //#region src/utils/manifest.ts
2
+ function composeRemoteRequestId(remoteName, expose) {
3
+ if (!expose || expose === ".") return remoteName;
4
+ return `${remoteName}/${expose.replace(/^\.\//, "")}`;
5
+ }
6
+ function matchRemoteWithNameAndExpose(remotes, id) {
7
+ for (const remote of remotes) {
8
+ const isNameMatched = id.startsWith(remote.name);
9
+ let expose = id.replace(remote.name, "");
10
+ if (isNameMatched) {
11
+ if (expose.startsWith("/")) {
12
+ const pkgNameOrAlias = remote.name;
13
+ expose = `.${expose}`;
14
+ return {
15
+ pkgNameOrAlias,
16
+ expose,
17
+ remote
18
+ };
19
+ } else if (expose === "") return {
20
+ pkgNameOrAlias: remote.name,
21
+ expose: ".",
22
+ remote
23
+ };
24
+ }
25
+ const isAliasMatched = remote.alias && id.startsWith(remote.alias);
26
+ let exposeWithAlias = remote.alias && id.replace(remote.alias, "");
27
+ if (remote.alias && isAliasMatched) {
28
+ if (exposeWithAlias && exposeWithAlias.startsWith("/")) {
29
+ const pkgNameOrAlias = remote.alias;
30
+ exposeWithAlias = `.${exposeWithAlias}`;
31
+ return {
32
+ pkgNameOrAlias,
33
+ expose: exposeWithAlias,
34
+ remote
35
+ };
36
+ } else if (exposeWithAlias === "") return {
37
+ pkgNameOrAlias: remote.alias,
38
+ expose: ".",
39
+ remote
40
+ };
41
+ }
42
+ }
43
+ }
44
+ function matchRemote(remotes, nameOrAlias) {
45
+ for (const remote of remotes) {
46
+ if (nameOrAlias === remote.name) return remote;
47
+ if (remote.alias && nameOrAlias === remote.alias) return remote;
48
+ }
49
+ }
50
+
51
+ //#endregion
52
+ export { composeRemoteRequestId, matchRemote, matchRemoteWithNameAndExpose };
53
+ //# sourceMappingURL=manifest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"manifest.js","names":[],"sources":["../../src/utils/manifest.ts"],"sourcesContent":["import { Remote } from '../type';\n\nexport function composeRemoteRequestId(\n remoteName: string,\n expose?: string,\n): string {\n if (!expose || expose === '.') {\n return remoteName;\n }\n\n return `${remoteName}/${expose.replace(/^\\.\\//, '')}`;\n}\n\n// Function to match a remote with its name and expose\n// id: pkgName(@federation/app1) + expose(button) = @federation/app1/button\n// id: alias(app1) + expose(button) = app1/button\n// id: alias(app1/utils) + expose(loadash/sort) = app1/utils/loadash/sort\nexport function matchRemoteWithNameAndExpose(\n remotes: Array<Remote>,\n id: string,\n):\n | {\n pkgNameOrAlias: string;\n expose: string;\n remote: Remote;\n }\n | undefined {\n for (const remote of remotes) {\n // match pkgName\n const isNameMatched = id.startsWith(remote.name);\n let expose = id.replace(remote.name, '');\n if (isNameMatched) {\n if (expose.startsWith('/')) {\n const pkgNameOrAlias = remote.name;\n expose = `.${expose}`;\n return {\n pkgNameOrAlias,\n expose,\n remote,\n };\n } else if (expose === '') {\n return {\n pkgNameOrAlias: remote.name,\n expose: '.',\n remote,\n };\n }\n }\n\n // match alias\n const isAliasMatched = remote.alias && id.startsWith(remote.alias);\n let exposeWithAlias = remote.alias && id.replace(remote.alias, '');\n if (remote.alias && isAliasMatched) {\n if (exposeWithAlias && exposeWithAlias.startsWith('/')) {\n const pkgNameOrAlias = remote.alias;\n exposeWithAlias = `.${exposeWithAlias}`;\n return {\n pkgNameOrAlias,\n expose: exposeWithAlias,\n remote,\n };\n } else if (exposeWithAlias === '') {\n return {\n pkgNameOrAlias: remote.alias,\n expose: '.',\n remote,\n };\n }\n }\n }\n\n return;\n}\n\n// Function to match a remote with its name or alias\nexport function matchRemote(\n remotes: Array<Remote>,\n nameOrAlias: string,\n): Remote | undefined {\n for (const remote of remotes) {\n const isNameMatched = nameOrAlias === remote.name;\n if (isNameMatched) {\n return remote;\n }\n\n const isAliasMatched = remote.alias && nameOrAlias === remote.alias;\n if (isAliasMatched) {\n return remote;\n }\n }\n return;\n}\n"],"mappings":";AAEA,SAAgB,uBACd,YACA,QACQ;AACR,KAAI,CAAC,UAAU,WAAW,IACxB,QAAO;AAGT,QAAO,GAAG,WAAW,GAAG,OAAO,QAAQ,SAAS,GAAG;;AAOrD,SAAgB,6BACd,SACA,IAOY;AACZ,MAAK,MAAM,UAAU,SAAS;EAE5B,MAAM,gBAAgB,GAAG,WAAW,OAAO,KAAK;EAChD,IAAI,SAAS,GAAG,QAAQ,OAAO,MAAM,GAAG;AACxC,MAAI,eACF;OAAI,OAAO,WAAW,IAAI,EAAE;IAC1B,MAAM,iBAAiB,OAAO;AAC9B,aAAS,IAAI;AACb,WAAO;KACL;KACA;KACA;KACD;cACQ,WAAW,GACpB,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;EAKL,MAAM,iBAAiB,OAAO,SAAS,GAAG,WAAW,OAAO,MAAM;EAClE,IAAI,kBAAkB,OAAO,SAAS,GAAG,QAAQ,OAAO,OAAO,GAAG;AAClE,MAAI,OAAO,SAAS,gBAClB;OAAI,mBAAmB,gBAAgB,WAAW,IAAI,EAAE;IACtD,MAAM,iBAAiB,OAAO;AAC9B,sBAAkB,IAAI;AACtB,WAAO;KACL;KACA,QAAQ;KACR;KACD;cACQ,oBAAoB,GAC7B,QAAO;IACL,gBAAgB,OAAO;IACvB,QAAQ;IACR;IACD;;;;AAST,SAAgB,YACd,SACA,aACoB;AACpB,MAAK,MAAM,UAAU,SAAS;AAE5B,MADsB,gBAAgB,OAAO,KAE3C,QAAO;AAIT,MADuB,OAAO,SAAS,gBAAgB,OAAO,MAE5D,QAAO"}
@@ -0,0 +1,50 @@
1
+ const require_logger = require('./logger.cjs');
2
+ const require_tool = require('./tool.cjs');
3
+ const require_global = require('../global.cjs');
4
+
5
+ //#region src/utils/plugin.ts
6
+ function getPluginsToRegister(plugins) {
7
+ const pluginsByName = /* @__PURE__ */ new Map();
8
+ [...plugins || [], ...require_global.getGlobalHostPlugins()].forEach((plugin) => {
9
+ if (!plugin) return;
10
+ require_logger.assert(require_tool.isPlainObject(plugin), "Plugin configuration is invalid.");
11
+ require_logger.assert(plugin.name, "A name must be provided by the plugin.");
12
+ if (!pluginsByName.has(plugin.name)) pluginsByName.set(plugin.name, plugin);
13
+ });
14
+ return Array.from(pluginsByName.values());
15
+ }
16
+ function getInstancePlugin(plugin, instanceHooks) {
17
+ if (instanceHooks === void 0) return plugin;
18
+ return {
19
+ ...instanceHooks,
20
+ name: plugin.name,
21
+ version: plugin.version
22
+ };
23
+ }
24
+ function registerPlugins(plugins, instance) {
25
+ const registeredPlugins = /* @__PURE__ */ new Map();
26
+ instance.options.plugins.forEach((plugin) => {
27
+ if (plugin) registeredPlugins.set(plugin.name, plugin);
28
+ });
29
+ const hookInstances = [
30
+ instance.hooks,
31
+ instance.remoteHandler.hooks,
32
+ instance.sharedHandler.hooks,
33
+ instance.snapshotHandler.hooks,
34
+ instance.loaderHook,
35
+ instance.bridgeHook
36
+ ];
37
+ getPluginsToRegister(plugins).forEach((plugin) => {
38
+ registeredPlugins.set(plugin.name, plugin);
39
+ if (instance.hooks.registerPlugins[plugin.name]) return;
40
+ const instancePlugin = getInstancePlugin(plugin, plugin.apply?.(instance));
41
+ hookInstances.forEach((hookInstance) => {
42
+ hookInstance.applyPlugin(instancePlugin);
43
+ });
44
+ });
45
+ return Array.from(registeredPlugins.values());
46
+ }
47
+
48
+ //#endregion
49
+ exports.registerPlugins = registerPlugins;
50
+ //# sourceMappingURL=plugin.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.cjs","names":["getGlobalHostPlugins","isPlainObject"],"sources":["../../src/utils/plugin.ts"],"sourcesContent":["import { ModuleFederation } from '../core';\nimport {\n ModuleFederationRuntimePlugin,\n RuntimePluginHooks,\n UserOptions,\n} from '../type';\nimport { getGlobalHostPlugins } from '../global';\nimport { assert } from './logger';\nimport { isPlainObject } from './tool';\n\nfunction getPluginsToRegister(\n plugins: UserOptions['plugins'],\n): Array<ModuleFederationRuntimePlugin> {\n const pluginsByName = new Map<string, ModuleFederationRuntimePlugin>();\n\n [...(plugins || []), ...getGlobalHostPlugins()].forEach((plugin) => {\n if (!plugin) {\n return;\n }\n\n assert(isPlainObject(plugin), 'Plugin configuration is invalid.');\n assert(plugin.name, 'A name must be provided by the plugin.');\n\n if (!pluginsByName.has(plugin.name)) {\n pluginsByName.set(plugin.name, plugin);\n }\n });\n\n return Array.from(pluginsByName.values());\n}\n\nfunction getInstancePlugin(\n plugin: ModuleFederationRuntimePlugin,\n instanceHooks: void | RuntimePluginHooks,\n): ModuleFederationRuntimePlugin {\n if (instanceHooks === undefined) {\n return plugin;\n }\n\n return {\n ...instanceHooks,\n name: plugin.name,\n version: plugin.version,\n };\n}\n\nexport function registerPlugins(\n plugins: UserOptions['plugins'],\n instance: ModuleFederation,\n) {\n const registeredPlugins = new Map<string, ModuleFederationRuntimePlugin>();\n instance.options.plugins.forEach((plugin) => {\n if (plugin) {\n registeredPlugins.set(plugin.name, plugin);\n }\n });\n const hookInstances = [\n instance.hooks,\n instance.remoteHandler.hooks,\n instance.sharedHandler.hooks,\n instance.snapshotHandler.hooks,\n instance.loaderHook,\n instance.bridgeHook,\n ];\n\n getPluginsToRegister(plugins).forEach((plugin) => {\n registeredPlugins.set(plugin.name, plugin);\n\n if (instance.hooks.registerPlugins[plugin.name]) {\n return;\n }\n\n const instancePlugin = getInstancePlugin(plugin, plugin.apply?.(instance));\n hookInstances.forEach((hookInstance) => {\n hookInstance.applyPlugin(instancePlugin);\n });\n });\n\n return Array.from(registeredPlugins.values());\n}\n"],"mappings":";;;;;AAUA,SAAS,qBACP,SACsC;CACtC,MAAM,gCAAgB,IAAI,KAA4C;AAEtE,EAAC,GAAI,WAAW,EAAE,EAAG,GAAGA,qCAAsB,CAAC,CAAC,SAAS,WAAW;AAClE,MAAI,CAAC,OACH;AAGF,wBAAOC,2BAAc,OAAO,EAAE,mCAAmC;AACjE,wBAAO,OAAO,MAAM,yCAAyC;AAE7D,MAAI,CAAC,cAAc,IAAI,OAAO,KAAK,CACjC,eAAc,IAAI,OAAO,MAAM,OAAO;GAExC;AAEF,QAAO,MAAM,KAAK,cAAc,QAAQ,CAAC;;AAG3C,SAAS,kBACP,QACA,eAC+B;AAC/B,KAAI,kBAAkB,OACpB,QAAO;AAGT,QAAO;EACL,GAAG;EACH,MAAM,OAAO;EACb,SAAS,OAAO;EACjB;;AAGH,SAAgB,gBACd,SACA,UACA;CACA,MAAM,oCAAoB,IAAI,KAA4C;AAC1E,UAAS,QAAQ,QAAQ,SAAS,WAAW;AAC3C,MAAI,OACF,mBAAkB,IAAI,OAAO,MAAM,OAAO;GAE5C;CACF,MAAM,gBAAgB;EACpB,SAAS;EACT,SAAS,cAAc;EACvB,SAAS,cAAc;EACvB,SAAS,gBAAgB;EACzB,SAAS;EACT,SAAS;EACV;AAED,sBAAqB,QAAQ,CAAC,SAAS,WAAW;AAChD,oBAAkB,IAAI,OAAO,MAAM,OAAO;AAE1C,MAAI,SAAS,MAAM,gBAAgB,OAAO,MACxC;EAGF,MAAM,iBAAiB,kBAAkB,QAAQ,OAAO,QAAQ,SAAS,CAAC;AAC1E,gBAAc,SAAS,iBAAiB;AACtC,gBAAa,YAAY,eAAe;IACxC;GACF;AAEF,QAAO,MAAM,KAAK,kBAAkB,QAAQ,CAAC"}
@@ -0,0 +1 @@
1
+ export { };