@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
package/dist/index.d.ts CHANGED
@@ -1 +1,30 @@
1
- export * from "./src/index";
1
+ import { Module as Module$2 } from "./module/index.js";
2
+ import { CurrentGlobal, Federation, Global, addGlobalSnapshot, getGlobalFederationConstructor, getGlobalSnapshot, getInfoWithoutType, registerGlobalPlugins, resetFederationGlobalInfo, setGlobalFederationConstructor, setGlobalFederationInstance } from "./global.js";
3
+ import { ModuleFederation } from "./core.js";
4
+ import { ModuleFederationRuntimePlugin, RuntimePluginHooks } from "./type/plugin.js";
5
+ import { UserOptions } from "./type/config.js";
6
+ import { index_d_exports } from "./type/index.js";
7
+ import { isStaticResourcesEqual, safeWrapper } from "./utils/tool.js";
8
+ import { matchRemoteWithNameAndExpose } from "./utils/manifest.js";
9
+ import { assert, error } from "./utils/logger.js";
10
+ import { getRemoteEntry, getRemoteInfo } from "./utils/load.js";
11
+ import { preloadAssets } from "./utils/preload.js";
12
+ import { getRegisteredShare } from "./utils/share.js";
13
+ import { IGlobalUtils, IShareUtils } from "./helpers.js";
14
+ import { satisfy } from "./utils/semver/index.js";
15
+ import { loadScript, loadScriptNode } from "@module-federation/sdk";
16
+
17
+ //#region src/index.d.ts
18
+ declare const helpers: {
19
+ global: IGlobalUtils;
20
+ share: IShareUtils;
21
+ utils: {
22
+ matchRemoteWithNameAndExpose: typeof matchRemoteWithNameAndExpose;
23
+ preloadAssets: typeof preloadAssets;
24
+ getRemoteInfo: typeof getRemoteInfo;
25
+ };
26
+ };
27
+ declare const Module: typeof Module$2;
28
+ //#endregion
29
+ export { CurrentGlobal, type Federation, Global, type IGlobalUtils, type IShareUtils, Module, ModuleFederation, type ModuleFederationRuntimePlugin, type RuntimePluginHooks, type UserOptions, addGlobalSnapshot, assert, error, getGlobalFederationConstructor, getGlobalSnapshot, getInfoWithoutType, getRegisteredShare, getRemoteEntry, getRemoteInfo, helpers, isStaticResourcesEqual, loadScript, loadScriptNode, matchRemoteWithNameAndExpose, registerGlobalPlugins, resetFederationGlobalInfo, safeWrapper, satisfy, setGlobalFederationConstructor, setGlobalFederationInstance, index_d_exports as types };
30
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { assert, error } from "./utils/logger.js";
2
+ import { isStaticResourcesEqual, safeWrapper } from "./utils/tool.js";
3
+ import { CurrentGlobal, Global, addGlobalSnapshot, getGlobalFederationConstructor, getGlobalSnapshot, getInfoWithoutType, registerGlobalPlugins, resetFederationGlobalInfo, setGlobalFederationConstructor, setGlobalFederationInstance } from "./global.js";
4
+ import { satisfy } from "./utils/semver/index.js";
5
+ import { getRegisteredShare } from "./utils/share.js";
6
+ import { matchRemoteWithNameAndExpose } from "./utils/manifest.js";
7
+ import { getRemoteEntry, getRemoteInfo } from "./utils/load.js";
8
+ import "./utils/index.js";
9
+ import helpers_default from "./helpers.js";
10
+ import { Module as Module$2 } from "./module/index.js";
11
+ import { UnavailableRemoteModule } from "./remote/disabled.js";
12
+ import { ModuleFederation } from "./core.js";
13
+ import { type_exports } from "./type/index.js";
14
+ import { loadScript, loadScriptNode } from "@module-federation/sdk";
15
+
16
+ //#region src/index.ts
17
+ const helpers = helpers_default;
18
+ const Module = typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" && FEDERATION_OPTIMIZE_NO_REMOTE ? UnavailableRemoteModule : Module$2;
19
+
20
+ //#endregion
21
+ export { CurrentGlobal, Global, Module, ModuleFederation, addGlobalSnapshot, assert, error, getGlobalFederationConstructor, getGlobalSnapshot, getInfoWithoutType, getRegisteredShare, getRemoteEntry, getRemoteInfo, helpers, isStaticResourcesEqual, loadScript, loadScriptNode, matchRemoteWithNameAndExpose, registerGlobalPlugins, resetFederationGlobalInfo, safeWrapper, satisfy, setGlobalFederationConstructor, setGlobalFederationInstance, type_exports as types };
22
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["helpersDefault","RemoteModule"],"sources":["../src/index.ts"],"sourcesContent":["import helpersDefault, { type IGlobalUtils, type IShareUtils } from './helpers';\nimport { Module as RemoteModule } from './module';\nimport { UnavailableRemoteModule } from './remote/disabled';\n\ndeclare const FEDERATION_OPTIMIZE_NO_REMOTE: boolean;\n\nconst helpers = helpersDefault;\nconst Module = (\n typeof FEDERATION_OPTIMIZE_NO_REMOTE === 'boolean' &&\n FEDERATION_OPTIMIZE_NO_REMOTE\n ? UnavailableRemoteModule\n : RemoteModule\n) as typeof RemoteModule;\n\nexport { ModuleFederation } from './core';\nexport {\n type Federation,\n CurrentGlobal,\n Global,\n getGlobalFederationConstructor,\n setGlobalFederationInstance,\n setGlobalFederationConstructor,\n resetFederationGlobalInfo,\n addGlobalSnapshot,\n getGlobalSnapshot,\n getInfoWithoutType,\n} from './global';\nexport type {\n UserOptions,\n ModuleFederationRuntimePlugin,\n RuntimePluginHooks,\n} from './type';\nexport { assert, error } from './utils/logger';\nexport { registerGlobalPlugins } from './global';\nexport {\n getRemoteEntry,\n getRemoteInfo,\n isStaticResourcesEqual,\n matchRemoteWithNameAndExpose,\n safeWrapper,\n} from './utils';\nexport { getRegisteredShare } from '../src/utils/share';\nexport { loadScript, loadScriptNode } from '@module-federation/sdk';\nexport { Module };\nexport * as types from './type';\nexport { helpers };\nexport { satisfy } from '../src/utils/semver';\nexport type { IGlobalUtils, IShareUtils };\n"],"mappings":";;;;;;;;;;;;;;;;AAMA,MAAM,UAAUA;AAChB,MAAM,SACJ,OAAO,kCAAkC,aACzC,gCACI,0BACAC"}
@@ -0,0 +1,268 @@
1
+ const require_logger = require('../utils/logger.cjs');
2
+ const require_tool = require('../utils/tool.cjs');
3
+ const require_manifest = require('../utils/manifest.cjs');
4
+ const require_load = require('../utils/load.cjs');
5
+ const require_context = require('../utils/context.cjs');
6
+ require('../utils/index.cjs');
7
+ let _module_federation_sdk = require("@module-federation/sdk");
8
+ let _module_federation_error_codes = require("@module-federation/error-codes");
9
+
10
+ //#region src/module/index.ts
11
+ function getAvailableExposeNames(remoteSnapshot) {
12
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
13
+ const exposes = remoteSnapshot.modules.map((module) => module.moduleName).filter(Boolean);
14
+ return exposes.length ? exposes.join(",") : void 0;
15
+ }
16
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
17
+ const localShareScopeMap = hostShareScopeMap;
18
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
19
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
20
+ shareScopeKeys.forEach((shareScopeKey) => {
21
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
22
+ });
23
+ const remoteEntryInitOptions = {
24
+ version: remoteInfo.version || "",
25
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
26
+ };
27
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
28
+ value: localShareScopeMap,
29
+ enumerable: false
30
+ });
31
+ return {
32
+ remoteEntryInitOptions,
33
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
34
+ initScope: rawInitScope ?? []
35
+ };
36
+ }
37
+ var Module = class {
38
+ constructor({ remoteInfo, host }) {
39
+ this.inited = false;
40
+ this.initing = false;
41
+ this.lib = void 0;
42
+ this.remoteInfo = remoteInfo;
43
+ this.host = host;
44
+ }
45
+ async getEntry(expose, resourceContext) {
46
+ const effectiveResourceContext = resourceContext || {
47
+ initiator: "loadRemote",
48
+ id: require_manifest.composeRemoteRequestId(this.remoteInfo.name, expose),
49
+ resourceType: "remoteEntry",
50
+ url: this.remoteInfo.entry,
51
+ expose
52
+ };
53
+ const remoteEntryExports = await require_load.getRemoteEntry({
54
+ origin: this.host,
55
+ remoteInfo: this.remoteInfo,
56
+ remoteEntryExports: this.remoteEntryExports,
57
+ resourceContext: effectiveResourceContext
58
+ });
59
+ require_logger.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${(0, _module_federation_sdk.safeToString)(this.remoteInfo)}`);
60
+ this.remoteEntryExports = remoteEntryExports;
61
+ return this.remoteEntryExports;
62
+ }
63
+ async init(id, remoteSnapshot, rawInitScope, expose, resourceContext) {
64
+ const remoteEntryExports = await this.getEntry(expose, resourceContext);
65
+ if (this.inited) {
66
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
67
+ id,
68
+ remoteInfo: this.remoteInfo,
69
+ remoteSnapshot,
70
+ remoteEntryExports,
71
+ cached: true,
72
+ origin: this.host
73
+ });
74
+ return remoteEntryExports;
75
+ }
76
+ if (this.initPromise) {
77
+ try {
78
+ await this.initPromise;
79
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
80
+ id,
81
+ remoteInfo: this.remoteInfo,
82
+ remoteSnapshot,
83
+ remoteEntryExports,
84
+ cached: true,
85
+ origin: this.host
86
+ });
87
+ } catch (initError) {
88
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
89
+ id,
90
+ remoteInfo: this.remoteInfo,
91
+ remoteSnapshot,
92
+ remoteEntryExports,
93
+ error: initError,
94
+ cached: true,
95
+ origin: this.host
96
+ });
97
+ throw initError;
98
+ }
99
+ return remoteEntryExports;
100
+ }
101
+ this.initing = true;
102
+ this.initPromise = (async () => {
103
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
104
+ id,
105
+ remoteInfo: this.remoteInfo,
106
+ remoteSnapshot,
107
+ origin: this.host
108
+ });
109
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
110
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
111
+ shareScope,
112
+ remoteEntryInitOptions,
113
+ initScope,
114
+ remoteInfo: this.remoteInfo,
115
+ origin: this.host
116
+ });
117
+ if (typeof remoteEntryExports?.init === "undefined") require_logger.error(_module_federation_error_codes.RUNTIME_002, _module_federation_error_codes.runtimeDescMap, {
118
+ hostName: this.host.name,
119
+ remoteName: this.remoteInfo.name,
120
+ remoteEntryUrl: this.remoteInfo.entry,
121
+ remoteEntryKey: this.remoteInfo.entryGlobalName
122
+ }, void 0, require_context.optionsToMFContext(this.host.options));
123
+ try {
124
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
125
+ } catch (initError) {
126
+ require_logger.error(_module_federation_error_codes.RUNTIME_015, _module_federation_error_codes.runtimeDescMap, {
127
+ hostName: this.host.name,
128
+ remoteName: this.remoteInfo.name,
129
+ remoteEntryUrl: this.remoteInfo.entry,
130
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
131
+ shareScope: this.remoteInfo.shareScope
132
+ }, `${initError}`, require_context.optionsToMFContext(this.host.options));
133
+ }
134
+ await this.host.hooks.lifecycle.initContainer.emit({
135
+ ...initContainerOptions,
136
+ id,
137
+ remoteSnapshot,
138
+ remoteEntryExports
139
+ });
140
+ this.inited = true;
141
+ })();
142
+ try {
143
+ await this.initPromise;
144
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
145
+ id,
146
+ remoteInfo: this.remoteInfo,
147
+ remoteSnapshot,
148
+ remoteEntryExports,
149
+ origin: this.host
150
+ });
151
+ } catch (initError) {
152
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
153
+ id,
154
+ remoteInfo: this.remoteInfo,
155
+ remoteSnapshot,
156
+ remoteEntryExports,
157
+ error: initError,
158
+ origin: this.host
159
+ });
160
+ throw initError;
161
+ } finally {
162
+ this.initing = false;
163
+ this.initPromise = void 0;
164
+ }
165
+ return remoteEntryExports;
166
+ }
167
+ async get(id, expose, options, remoteSnapshot) {
168
+ const { loadFactory = true } = options || { loadFactory: true };
169
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
170
+ this.lib = remoteEntryExports;
171
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
172
+ id,
173
+ expose,
174
+ moduleInfo: this.remoteInfo,
175
+ remoteEntryExports,
176
+ origin: this.host
177
+ });
178
+ let moduleFactory;
179
+ try {
180
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
181
+ remoteEntryExports,
182
+ expose,
183
+ moduleInfo: this.remoteInfo
184
+ });
185
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
186
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
187
+ if (!moduleFactory) require_logger.error(_module_federation_error_codes.RUNTIME_014, _module_federation_error_codes.runtimeDescMap, {
188
+ hostName: this.host.name,
189
+ remoteName: this.remoteInfo.name,
190
+ remoteEntryUrl: this.remoteInfo.entry,
191
+ expose,
192
+ requestId: id,
193
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
194
+ }, void 0, require_context.optionsToMFContext(this.host.options));
195
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
196
+ id,
197
+ expose,
198
+ moduleInfo: this.remoteInfo,
199
+ remoteEntryExports,
200
+ moduleFactory,
201
+ origin: this.host
202
+ });
203
+ } catch (getExposeError) {
204
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
205
+ id,
206
+ expose,
207
+ moduleInfo: this.remoteInfo,
208
+ remoteEntryExports,
209
+ error: getExposeError,
210
+ origin: this.host
211
+ });
212
+ throw getExposeError;
213
+ }
214
+ const symbolName = require_tool.processModuleAlias(this.remoteInfo.name, expose);
215
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
216
+ if (!loadFactory) return wrapModuleFactory;
217
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
218
+ id,
219
+ expose,
220
+ moduleInfo: this.remoteInfo,
221
+ loadFactory,
222
+ origin: this.host
223
+ });
224
+ try {
225
+ const exposeContent = await wrapModuleFactory();
226
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
227
+ id,
228
+ expose,
229
+ moduleInfo: this.remoteInfo,
230
+ loadFactory,
231
+ exposeModule: exposeContent,
232
+ origin: this.host
233
+ });
234
+ return exposeContent;
235
+ } catch (executeFactoryError) {
236
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
237
+ id,
238
+ expose,
239
+ moduleInfo: this.remoteInfo,
240
+ loadFactory,
241
+ error: executeFactoryError,
242
+ origin: this.host
243
+ });
244
+ throw executeFactoryError;
245
+ }
246
+ }
247
+ wraperFactory(moduleFactory, id) {
248
+ function defineModuleId(res, id) {
249
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
250
+ value: id,
251
+ enumerable: false
252
+ });
253
+ }
254
+ return () => {
255
+ const res = moduleFactory();
256
+ if (res instanceof Promise) return res.then((asyncRes) => {
257
+ defineModuleId(asyncRes, id);
258
+ return asyncRes;
259
+ });
260
+ defineModuleId(res, id);
261
+ return res;
262
+ };
263
+ }
264
+ };
265
+
266
+ //#endregion
267
+ exports.Module = Module;
268
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["composeRemoteRequestId","getRemoteEntry","RUNTIME_002","runtimeDescMap","optionsToMFContext","RUNTIME_015","RUNTIME_014","processModuleAlias"],"sources":["../../src/module/index.ts"],"sourcesContent":["import {\n assert,\n error,\n processModuleAlias,\n optionsToMFContext,\n composeRemoteRequestId,\n} from '../utils';\nimport { safeToString, ModuleInfo } from '@module-federation/sdk';\nimport {\n RUNTIME_002,\n RUNTIME_014,\n RUNTIME_015,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { getRemoteEntry } from '../utils/load';\nimport { ModuleFederation } from '../core';\nimport {\n RemoteEntryExports,\n RemoteInfo,\n InitScope,\n ShareScopeMap,\n ResourceLoadContext,\n} from '../type';\n\nexport type ModuleOptions = ConstructorParameters<typeof Module>[0];\nexport type RemoteModuleFactory = () => unknown | Promise<unknown>;\n\nfunction getAvailableExposeNames(\n remoteSnapshot?: ModuleInfo,\n): string | undefined {\n if (\n !remoteSnapshot ||\n !('modules' in remoteSnapshot) ||\n !Array.isArray(remoteSnapshot.modules)\n ) {\n return undefined;\n }\n\n const exposes = remoteSnapshot.modules\n .map((module) => module.moduleName)\n .filter(Boolean);\n\n return exposes.length ? exposes.join(',') : undefined;\n}\n\nexport function createRemoteEntryInitOptions(\n remoteInfo: RemoteInfo,\n hostShareScopeMap: ShareScopeMap,\n rawInitScope?: InitScope,\n): Record<string, any> {\n const localShareScopeMap = hostShareScopeMap;\n\n const shareScopeKeys = Array.isArray(remoteInfo.shareScope)\n ? remoteInfo.shareScope\n : [remoteInfo.shareScope];\n\n if (!shareScopeKeys.length) {\n shareScopeKeys.push('default');\n }\n shareScopeKeys.forEach((shareScopeKey) => {\n if (!localShareScopeMap[shareScopeKey]) {\n localShareScopeMap[shareScopeKey] = {};\n }\n });\n\n const remoteEntryInitOptions = {\n version: remoteInfo.version || '',\n shareScopeKeys: Array.isArray(remoteInfo.shareScope)\n ? shareScopeKeys\n : remoteInfo.shareScope || 'default',\n };\n\n // Help to find host instance\n Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {\n value: localShareScopeMap,\n // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed\n enumerable: false,\n });\n\n // TODO: compate legacy init params, should use shareScopeMap if exist\n const shareScope = localShareScopeMap[shareScopeKeys[0]];\n const initScope: InitScope = rawInitScope ?? [];\n\n return {\n remoteEntryInitOptions,\n shareScope,\n initScope,\n };\n}\n\nclass Module {\n remoteInfo: RemoteInfo;\n inited = false;\n initing = false;\n initPromise?: Promise<void>;\n remoteEntryExports?: RemoteEntryExports;\n lib: RemoteEntryExports | undefined = undefined;\n host: ModuleFederation;\n\n constructor({\n remoteInfo,\n host,\n }: {\n remoteInfo: RemoteInfo;\n host: ModuleFederation;\n }) {\n this.remoteInfo = remoteInfo;\n this.host = host;\n }\n\n async getEntry(\n expose?: string,\n resourceContext?: ResourceLoadContext,\n ): Promise<RemoteEntryExports> {\n const effectiveResourceContext = resourceContext || {\n initiator: 'loadRemote',\n id: composeRemoteRequestId(this.remoteInfo.name, expose),\n resourceType: 'remoteEntry' as const,\n url: this.remoteInfo.entry,\n expose,\n };\n const remoteEntryExports = await getRemoteEntry({\n origin: this.host,\n remoteInfo: this.remoteInfo,\n remoteEntryExports: this.remoteEntryExports,\n resourceContext: effectiveResourceContext,\n });\n\n assert(\n remoteEntryExports,\n `remoteEntryExports is undefined \\n ${safeToString(this.remoteInfo)}`,\n );\n\n this.remoteEntryExports = remoteEntryExports;\n return this.remoteEntryExports;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n\n async init(\n id?: string,\n remoteSnapshot?: ModuleInfo,\n rawInitScope?: InitScope,\n expose?: string,\n resourceContext?: ResourceLoadContext,\n ) {\n // Get remoteEntry.js\n const remoteEntryExports = await this.getEntry(expose, resourceContext);\n\n if (this.inited) {\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n cached: true,\n origin: this.host,\n });\n return remoteEntryExports;\n }\n\n if (this.initPromise) {\n try {\n await this.initPromise;\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n cached: true,\n origin: this.host,\n });\n } catch (initError) {\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n error: initError,\n cached: true,\n origin: this.host,\n });\n throw initError;\n }\n return remoteEntryExports;\n }\n\n this.initing = true;\n this.initPromise = (async () => {\n await this.host.loaderHook.lifecycle.beforeInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n origin: this.host,\n });\n\n const { remoteEntryInitOptions, shareScope, initScope } =\n createRemoteEntryInitOptions(\n this.remoteInfo,\n this.host.shareScopeMap,\n rawInitScope,\n );\n\n const initContainerOptions =\n await this.host.hooks.lifecycle.beforeInitContainer.emit({\n shareScope,\n // @ts-ignore shareScopeMap will be set by Object.defineProperty\n remoteEntryInitOptions,\n initScope,\n remoteInfo: this.remoteInfo,\n origin: this.host,\n });\n\n if (typeof remoteEntryExports?.init === 'undefined') {\n error(\n RUNTIME_002,\n runtimeDescMap,\n {\n hostName: this.host.name,\n remoteName: this.remoteInfo.name,\n remoteEntryUrl: this.remoteInfo.entry,\n remoteEntryKey: this.remoteInfo.entryGlobalName,\n },\n undefined,\n optionsToMFContext(this.host.options),\n );\n }\n\n try {\n await remoteEntryExports.init(\n initContainerOptions.shareScope,\n initContainerOptions.initScope,\n initContainerOptions.remoteEntryInitOptions,\n );\n } catch (initError) {\n error(\n RUNTIME_015,\n runtimeDescMap,\n {\n hostName: this.host.name,\n remoteName: this.remoteInfo.name,\n remoteEntryUrl: this.remoteInfo.entry,\n remoteEntryKey: this.remoteInfo.entryGlobalName,\n shareScope: this.remoteInfo.shareScope,\n },\n `${initError}`,\n optionsToMFContext(this.host.options),\n );\n }\n\n await this.host.hooks.lifecycle.initContainer.emit({\n ...initContainerOptions,\n id,\n remoteSnapshot,\n remoteEntryExports,\n });\n this.inited = true;\n })();\n\n try {\n await this.initPromise;\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n origin: this.host,\n });\n } catch (initError) {\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n error: initError,\n origin: this.host,\n });\n throw initError;\n } finally {\n this.initing = false;\n this.initPromise = undefined;\n }\n\n return remoteEntryExports;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n async get(\n id: string,\n expose: string,\n options?: { loadFactory?: boolean },\n remoteSnapshot?: ModuleInfo,\n ) {\n const { loadFactory = true } = options || { loadFactory: true };\n\n const remoteEntryExports = await this.init(\n id,\n remoteSnapshot,\n undefined,\n expose,\n );\n this.lib = remoteEntryExports;\n\n await this.host.loaderHook.lifecycle.beforeGetExpose.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n remoteEntryExports,\n origin: this.host,\n });\n\n let moduleFactory: RemoteModuleFactory | undefined;\n try {\n const hookModuleFactory =\n await this.host.loaderHook.lifecycle.getModuleFactory.emit({\n remoteEntryExports,\n expose,\n moduleInfo: this.remoteInfo,\n });\n moduleFactory =\n typeof hookModuleFactory === 'function' ? hookModuleFactory : undefined;\n\n // get exposeGetter\n if (!moduleFactory) {\n moduleFactory = await remoteEntryExports.get(expose);\n }\n\n if (!moduleFactory) {\n error(\n RUNTIME_014,\n runtimeDescMap,\n {\n hostName: this.host.name,\n remoteName: this.remoteInfo.name,\n remoteEntryUrl: this.remoteInfo.entry,\n expose,\n requestId: id,\n availableExposes: getAvailableExposeNames(remoteSnapshot),\n },\n undefined,\n optionsToMFContext(this.host.options),\n );\n }\n\n await this.host.loaderHook.lifecycle.afterGetExpose.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n remoteEntryExports,\n moduleFactory,\n origin: this.host,\n });\n } catch (getExposeError) {\n await this.host.loaderHook.lifecycle.afterGetExpose.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n remoteEntryExports,\n error: getExposeError,\n origin: this.host,\n });\n throw getExposeError;\n }\n\n // keep symbol for module name always one format\n const symbolName = processModuleAlias(this.remoteInfo.name, expose);\n const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);\n\n if (!loadFactory) {\n return wrapModuleFactory;\n }\n\n await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n loadFactory,\n origin: this.host,\n });\n\n try {\n const exposeContent = await wrapModuleFactory();\n\n await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n loadFactory,\n exposeModule: exposeContent,\n origin: this.host,\n });\n\n return exposeContent;\n } catch (executeFactoryError) {\n await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n loadFactory,\n error: executeFactoryError,\n origin: this.host,\n });\n throw executeFactoryError;\n }\n }\n\n private wraperFactory(moduleFactory: RemoteModuleFactory, id: string) {\n function defineModuleId(res: unknown, id: string) {\n if (\n res &&\n typeof res === 'object' &&\n Object.isExtensible(res) &&\n !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))\n ) {\n Object.defineProperty(res, Symbol.for('mf_module_id'), {\n value: id,\n enumerable: false,\n });\n }\n }\n\n return () => {\n const res = moduleFactory();\n\n if (res instanceof Promise) {\n return res.then((asyncRes) => {\n // This parameter is used for bridge debugging\n defineModuleId(asyncRes, id);\n return asyncRes;\n });\n }\n\n // This parameter is used for bridge debugging\n defineModuleId(res, id);\n return res;\n };\n }\n}\n\nexport { Module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AAI,eAAe,CAAC,CAEjE,QAAO,eAAe,KAAK,OAAO,IAAI,eAAe,EAAE;IACrD,OAAO;IACP,YAAY;IACb,CAAC;;AAIN,eAAa;GACX,MAAM,MAAM,eAAe;AAE3B,OAAI,eAAe,QACjB,QAAO,IAAI,MAAM,aAAa;AAE5B,mBAAe,UAAU,GAAG;AAC5B,WAAO;KACP;AAIJ,kBAAe,KAAK,GAAG;AACvB,UAAO"}
@@ -0,0 +1,33 @@
1
+ import { ModuleFederation } from "../core.js";
2
+ import { InitScope, RemoteEntryExports, RemoteInfo } from "../type/config.js";
3
+ import { ResourceLoadContext } from "../type/preload.js";
4
+ import { ModuleInfo } from "@module-federation/sdk";
5
+
6
+ //#region src/module/index.d.ts
7
+ type ModuleOptions = ConstructorParameters<typeof Module$1>[0];
8
+ type RemoteModuleFactory = () => unknown | Promise<unknown>;
9
+ declare class Module$1 {
10
+ remoteInfo: RemoteInfo;
11
+ inited: boolean;
12
+ initing: boolean;
13
+ initPromise?: Promise<void>;
14
+ remoteEntryExports?: RemoteEntryExports;
15
+ lib: RemoteEntryExports | undefined;
16
+ host: ModuleFederation;
17
+ constructor({
18
+ remoteInfo,
19
+ host
20
+ }: {
21
+ remoteInfo: RemoteInfo;
22
+ host: ModuleFederation;
23
+ });
24
+ getEntry(expose?: string, resourceContext?: ResourceLoadContext): Promise<RemoteEntryExports>;
25
+ init(id?: string, remoteSnapshot?: ModuleInfo, rawInitScope?: InitScope, expose?: string, resourceContext?: ResourceLoadContext): Promise<RemoteEntryExports>;
26
+ get(id: string, expose: string, options?: {
27
+ loadFactory?: boolean;
28
+ }, remoteSnapshot?: ModuleInfo): Promise<unknown>;
29
+ private wraperFactory;
30
+ }
31
+ //#endregion
32
+ export { Module$1 as Module, ModuleOptions, RemoteModuleFactory };
33
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,268 @@
1
+ import { assert, error } from "../utils/logger.js";
2
+ import { processModuleAlias } from "../utils/tool.js";
3
+ import { composeRemoteRequestId } from "../utils/manifest.js";
4
+ import { getRemoteEntry } from "../utils/load.js";
5
+ import { optionsToMFContext } from "../utils/context.js";
6
+ import "../utils/index.js";
7
+ import { safeToString } from "@module-federation/sdk";
8
+ import { RUNTIME_002, RUNTIME_014, RUNTIME_015, runtimeDescMap } from "@module-federation/error-codes";
9
+
10
+ //#region src/module/index.ts
11
+ function getAvailableExposeNames(remoteSnapshot) {
12
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
13
+ const exposes = remoteSnapshot.modules.map((module) => module.moduleName).filter(Boolean);
14
+ return exposes.length ? exposes.join(",") : void 0;
15
+ }
16
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
17
+ const localShareScopeMap = hostShareScopeMap;
18
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
19
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
20
+ shareScopeKeys.forEach((shareScopeKey) => {
21
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
22
+ });
23
+ const remoteEntryInitOptions = {
24
+ version: remoteInfo.version || "",
25
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
26
+ };
27
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
28
+ value: localShareScopeMap,
29
+ enumerable: false
30
+ });
31
+ return {
32
+ remoteEntryInitOptions,
33
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
34
+ initScope: rawInitScope ?? []
35
+ };
36
+ }
37
+ var Module$1 = class {
38
+ constructor({ remoteInfo, host }) {
39
+ this.inited = false;
40
+ this.initing = false;
41
+ this.lib = void 0;
42
+ this.remoteInfo = remoteInfo;
43
+ this.host = host;
44
+ }
45
+ async getEntry(expose, resourceContext) {
46
+ const effectiveResourceContext = resourceContext || {
47
+ initiator: "loadRemote",
48
+ id: composeRemoteRequestId(this.remoteInfo.name, expose),
49
+ resourceType: "remoteEntry",
50
+ url: this.remoteInfo.entry,
51
+ expose
52
+ };
53
+ const remoteEntryExports = await getRemoteEntry({
54
+ origin: this.host,
55
+ remoteInfo: this.remoteInfo,
56
+ remoteEntryExports: this.remoteEntryExports,
57
+ resourceContext: effectiveResourceContext
58
+ });
59
+ assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
60
+ this.remoteEntryExports = remoteEntryExports;
61
+ return this.remoteEntryExports;
62
+ }
63
+ async init(id, remoteSnapshot, rawInitScope, expose, resourceContext) {
64
+ const remoteEntryExports = await this.getEntry(expose, resourceContext);
65
+ if (this.inited) {
66
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
67
+ id,
68
+ remoteInfo: this.remoteInfo,
69
+ remoteSnapshot,
70
+ remoteEntryExports,
71
+ cached: true,
72
+ origin: this.host
73
+ });
74
+ return remoteEntryExports;
75
+ }
76
+ if (this.initPromise) {
77
+ try {
78
+ await this.initPromise;
79
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
80
+ id,
81
+ remoteInfo: this.remoteInfo,
82
+ remoteSnapshot,
83
+ remoteEntryExports,
84
+ cached: true,
85
+ origin: this.host
86
+ });
87
+ } catch (initError) {
88
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
89
+ id,
90
+ remoteInfo: this.remoteInfo,
91
+ remoteSnapshot,
92
+ remoteEntryExports,
93
+ error: initError,
94
+ cached: true,
95
+ origin: this.host
96
+ });
97
+ throw initError;
98
+ }
99
+ return remoteEntryExports;
100
+ }
101
+ this.initing = true;
102
+ this.initPromise = (async () => {
103
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
104
+ id,
105
+ remoteInfo: this.remoteInfo,
106
+ remoteSnapshot,
107
+ origin: this.host
108
+ });
109
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
110
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
111
+ shareScope,
112
+ remoteEntryInitOptions,
113
+ initScope,
114
+ remoteInfo: this.remoteInfo,
115
+ origin: this.host
116
+ });
117
+ if (typeof remoteEntryExports?.init === "undefined") error(RUNTIME_002, runtimeDescMap, {
118
+ hostName: this.host.name,
119
+ remoteName: this.remoteInfo.name,
120
+ remoteEntryUrl: this.remoteInfo.entry,
121
+ remoteEntryKey: this.remoteInfo.entryGlobalName
122
+ }, void 0, optionsToMFContext(this.host.options));
123
+ try {
124
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
125
+ } catch (initError) {
126
+ error(RUNTIME_015, runtimeDescMap, {
127
+ hostName: this.host.name,
128
+ remoteName: this.remoteInfo.name,
129
+ remoteEntryUrl: this.remoteInfo.entry,
130
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
131
+ shareScope: this.remoteInfo.shareScope
132
+ }, `${initError}`, optionsToMFContext(this.host.options));
133
+ }
134
+ await this.host.hooks.lifecycle.initContainer.emit({
135
+ ...initContainerOptions,
136
+ id,
137
+ remoteSnapshot,
138
+ remoteEntryExports
139
+ });
140
+ this.inited = true;
141
+ })();
142
+ try {
143
+ await this.initPromise;
144
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
145
+ id,
146
+ remoteInfo: this.remoteInfo,
147
+ remoteSnapshot,
148
+ remoteEntryExports,
149
+ origin: this.host
150
+ });
151
+ } catch (initError) {
152
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
153
+ id,
154
+ remoteInfo: this.remoteInfo,
155
+ remoteSnapshot,
156
+ remoteEntryExports,
157
+ error: initError,
158
+ origin: this.host
159
+ });
160
+ throw initError;
161
+ } finally {
162
+ this.initing = false;
163
+ this.initPromise = void 0;
164
+ }
165
+ return remoteEntryExports;
166
+ }
167
+ async get(id, expose, options, remoteSnapshot) {
168
+ const { loadFactory = true } = options || { loadFactory: true };
169
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
170
+ this.lib = remoteEntryExports;
171
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
172
+ id,
173
+ expose,
174
+ moduleInfo: this.remoteInfo,
175
+ remoteEntryExports,
176
+ origin: this.host
177
+ });
178
+ let moduleFactory;
179
+ try {
180
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
181
+ remoteEntryExports,
182
+ expose,
183
+ moduleInfo: this.remoteInfo
184
+ });
185
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
186
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
187
+ if (!moduleFactory) error(RUNTIME_014, runtimeDescMap, {
188
+ hostName: this.host.name,
189
+ remoteName: this.remoteInfo.name,
190
+ remoteEntryUrl: this.remoteInfo.entry,
191
+ expose,
192
+ requestId: id,
193
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
194
+ }, void 0, optionsToMFContext(this.host.options));
195
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
196
+ id,
197
+ expose,
198
+ moduleInfo: this.remoteInfo,
199
+ remoteEntryExports,
200
+ moduleFactory,
201
+ origin: this.host
202
+ });
203
+ } catch (getExposeError) {
204
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
205
+ id,
206
+ expose,
207
+ moduleInfo: this.remoteInfo,
208
+ remoteEntryExports,
209
+ error: getExposeError,
210
+ origin: this.host
211
+ });
212
+ throw getExposeError;
213
+ }
214
+ const symbolName = processModuleAlias(this.remoteInfo.name, expose);
215
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
216
+ if (!loadFactory) return wrapModuleFactory;
217
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
218
+ id,
219
+ expose,
220
+ moduleInfo: this.remoteInfo,
221
+ loadFactory,
222
+ origin: this.host
223
+ });
224
+ try {
225
+ const exposeContent = await wrapModuleFactory();
226
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
227
+ id,
228
+ expose,
229
+ moduleInfo: this.remoteInfo,
230
+ loadFactory,
231
+ exposeModule: exposeContent,
232
+ origin: this.host
233
+ });
234
+ return exposeContent;
235
+ } catch (executeFactoryError) {
236
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
237
+ id,
238
+ expose,
239
+ moduleInfo: this.remoteInfo,
240
+ loadFactory,
241
+ error: executeFactoryError,
242
+ origin: this.host
243
+ });
244
+ throw executeFactoryError;
245
+ }
246
+ }
247
+ wraperFactory(moduleFactory, id) {
248
+ function defineModuleId(res, id) {
249
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
250
+ value: id,
251
+ enumerable: false
252
+ });
253
+ }
254
+ return () => {
255
+ const res = moduleFactory();
256
+ if (res instanceof Promise) return res.then((asyncRes) => {
257
+ defineModuleId(asyncRes, id);
258
+ return asyncRes;
259
+ });
260
+ defineModuleId(res, id);
261
+ return res;
262
+ };
263
+ }
264
+ };
265
+
266
+ //#endregion
267
+ export { Module$1 as Module };
268
+ //# sourceMappingURL=index.js.map