@module-federation/runtime-core 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (209) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +19 -0
  2. package/dist/_virtual/_rolldown/runtime.js +18 -0
  3. package/dist/constant.cjs +9 -0
  4. package/dist/constant.cjs.map +1 -0
  5. package/dist/constant.js +7 -0
  6. package/dist/constant.js.map +1 -0
  7. package/dist/core.cjs +153 -0
  8. package/dist/core.cjs.map +1 -0
  9. package/dist/core.d.ts +129 -0
  10. package/dist/core.js +153 -0
  11. package/dist/core.js.map +1 -0
  12. package/dist/global.cjs +160 -0
  13. package/dist/global.cjs.map +1 -0
  14. package/dist/global.d.ts +45 -0
  15. package/dist/global.js +142 -0
  16. package/dist/global.js.map +1 -0
  17. package/dist/helpers.cjs +44 -0
  18. package/dist/helpers.cjs.map +1 -0
  19. package/dist/helpers.d.ts +30 -0
  20. package/dist/helpers.js +44 -0
  21. package/dist/helpers.js.map +1 -0
  22. package/dist/index.cjs +60 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.d.ts +29 -1
  25. package/dist/index.js +20 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/module/index.cjs +129 -0
  28. package/dist/module/index.cjs.map +1 -0
  29. package/dist/module/index.d.ts +31 -0
  30. package/dist/module/index.js +129 -0
  31. package/dist/module/index.js.map +1 -0
  32. package/dist/plugins/generate-preload-assets.cjs +182 -0
  33. package/dist/plugins/generate-preload-assets.cjs.map +1 -0
  34. package/dist/plugins/generate-preload-assets.js +182 -0
  35. package/dist/plugins/generate-preload-assets.js.map +1 -0
  36. package/dist/plugins/snapshot/SnapshotHandler.cjs +190 -0
  37. package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -0
  38. package/dist/plugins/snapshot/SnapshotHandler.d.ts +66 -0
  39. package/dist/plugins/snapshot/SnapshotHandler.js +189 -0
  40. package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -0
  41. package/dist/plugins/snapshot/index.cjs +63 -0
  42. package/dist/plugins/snapshot/index.cjs.map +1 -0
  43. package/dist/plugins/snapshot/index.js +62 -0
  44. package/dist/plugins/snapshot/index.js.map +1 -0
  45. package/dist/remote/index.cjs +304 -0
  46. package/dist/remote/index.cjs.map +1 -0
  47. package/dist/remote/index.d.ts +119 -0
  48. package/dist/remote/index.js +304 -0
  49. package/dist/remote/index.js.map +1 -0
  50. package/dist/shared/index.cjs +303 -0
  51. package/dist/shared/index.cjs.map +1 -0
  52. package/dist/shared/index.d.ts +82 -0
  53. package/dist/shared/index.js +303 -0
  54. package/dist/shared/index.js.map +1 -0
  55. package/dist/type/config.d.ts +130 -0
  56. package/dist/type/index.cjs +13 -0
  57. package/dist/type/index.cjs.map +1 -0
  58. package/dist/type/index.d.ts +11 -0
  59. package/dist/type/index.js +8 -0
  60. package/dist/type/index.js.map +1 -0
  61. package/dist/type/plugin.d.ts +27 -0
  62. package/dist/type/preload.d.ts +31 -0
  63. package/dist/types.cjs +0 -0
  64. package/dist/types.d.ts +4 -1
  65. package/dist/types.js +1 -0
  66. package/dist/utils/context.cjs +45 -0
  67. package/dist/utils/context.cjs.map +1 -0
  68. package/dist/utils/context.d.ts +1 -0
  69. package/dist/utils/context.js +44 -0
  70. package/dist/utils/context.js.map +1 -0
  71. package/dist/utils/env.cjs +10 -0
  72. package/dist/utils/env.cjs.map +1 -0
  73. package/dist/utils/env.d.ts +1 -0
  74. package/dist/utils/env.js +10 -0
  75. package/dist/utils/env.js.map +1 -0
  76. package/dist/utils/hooks/asyncHook.cjs +23 -0
  77. package/dist/utils/hooks/asyncHook.cjs.map +1 -0
  78. package/dist/utils/hooks/asyncHook.d.ts +10 -0
  79. package/dist/utils/hooks/asyncHook.js +23 -0
  80. package/dist/utils/hooks/asyncHook.js.map +1 -0
  81. package/dist/utils/hooks/asyncWaterfallHooks.cjs +42 -0
  82. package/dist/utils/hooks/asyncWaterfallHooks.cjs.map +1 -0
  83. package/dist/utils/hooks/asyncWaterfallHooks.d.ts +12 -0
  84. package/dist/utils/hooks/asyncWaterfallHooks.js +42 -0
  85. package/dist/utils/hooks/asyncWaterfallHooks.js.map +1 -0
  86. package/dist/utils/hooks/index.cjs +5 -0
  87. package/dist/utils/hooks/index.d.ts +5 -0
  88. package/dist/utils/hooks/index.js +7 -0
  89. package/dist/utils/hooks/pluginSystem.cjs +37 -0
  90. package/dist/utils/hooks/pluginSystem.cjs.map +1 -0
  91. package/dist/utils/hooks/pluginSystem.d.ts +19 -0
  92. package/dist/utils/hooks/pluginSystem.js +37 -0
  93. package/dist/utils/hooks/pluginSystem.js.map +1 -0
  94. package/dist/utils/hooks/syncHook.cjs +36 -0
  95. package/dist/utils/hooks/syncHook.cjs.map +1 -0
  96. package/dist/utils/hooks/syncHook.d.ts +16 -0
  97. package/dist/utils/hooks/syncHook.js +35 -0
  98. package/dist/utils/hooks/syncHook.js.map +1 -0
  99. package/dist/utils/hooks/syncWaterfallHook.cjs +39 -0
  100. package/dist/utils/hooks/syncWaterfallHook.cjs.map +1 -0
  101. package/dist/utils/hooks/syncWaterfallHook.d.ts +11 -0
  102. package/dist/utils/hooks/syncWaterfallHook.js +38 -0
  103. package/dist/utils/hooks/syncWaterfallHook.js.map +1 -0
  104. package/dist/utils/index.cjs +8 -0
  105. package/dist/utils/index.d.ts +4 -0
  106. package/dist/utils/index.js +9 -0
  107. package/dist/utils/load.cjs +179 -0
  108. package/dist/utils/load.cjs.map +1 -0
  109. package/dist/utils/load.d.ts +14 -0
  110. package/dist/utils/load.js +177 -0
  111. package/dist/utils/load.js.map +1 -0
  112. package/dist/utils/logger.cjs +34 -0
  113. package/dist/utils/logger.cjs.map +1 -0
  114. package/dist/utils/logger.d.ts +10 -0
  115. package/dist/utils/logger.js +31 -0
  116. package/dist/utils/logger.js.map +1 -0
  117. package/dist/utils/manifest.cjs +51 -0
  118. package/dist/utils/manifest.cjs.map +1 -0
  119. package/dist/utils/manifest.d.ts +10 -0
  120. package/dist/utils/manifest.js +49 -0
  121. package/dist/utils/manifest.js.map +1 -0
  122. package/dist/utils/plugin.cjs +27 -0
  123. package/dist/utils/plugin.cjs.map +1 -0
  124. package/dist/utils/plugin.d.ts +1 -0
  125. package/dist/utils/plugin.js +27 -0
  126. package/dist/utils/plugin.js.map +1 -0
  127. package/dist/utils/preload.cjs +146 -0
  128. package/dist/utils/preload.cjs.map +1 -0
  129. package/dist/utils/preload.d.ts +8 -0
  130. package/dist/utils/preload.js +143 -0
  131. package/dist/utils/preload.js.map +1 -0
  132. package/dist/utils/semver/compare.cjs +48 -0
  133. package/dist/utils/semver/compare.cjs.map +1 -0
  134. package/dist/utils/semver/compare.js +47 -0
  135. package/dist/utils/semver/compare.js.map +1 -0
  136. package/dist/utils/semver/constants.cjs +41 -0
  137. package/dist/utils/semver/constants.cjs.map +1 -0
  138. package/dist/utils/semver/constants.js +31 -0
  139. package/dist/utils/semver/constants.js.map +1 -0
  140. package/dist/utils/semver/index.cjs +68 -0
  141. package/dist/utils/semver/index.cjs.map +1 -0
  142. package/dist/utils/semver/index.d.ts +5 -0
  143. package/dist/utils/semver/index.js +68 -0
  144. package/dist/utils/semver/index.js.map +1 -0
  145. package/dist/utils/semver/parser.cjs +104 -0
  146. package/dist/utils/semver/parser.cjs.map +1 -0
  147. package/dist/utils/semver/parser.js +96 -0
  148. package/dist/utils/semver/parser.js.map +1 -0
  149. package/dist/utils/semver/utils.cjs +28 -0
  150. package/dist/utils/semver/utils.cjs.map +1 -0
  151. package/dist/utils/semver/utils.js +24 -0
  152. package/dist/utils/semver/utils.js.map +1 -0
  153. package/dist/utils/share.cjs +284 -0
  154. package/dist/utils/share.cjs.map +1 -0
  155. package/dist/utils/share.d.ts +23 -0
  156. package/dist/utils/share.js +278 -0
  157. package/dist/utils/share.js.map +1 -0
  158. package/dist/utils/tool.cjs +82 -0
  159. package/dist/utils/tool.cjs.map +1 -0
  160. package/dist/utils/tool.d.ts +8 -0
  161. package/dist/utils/tool.js +71 -0
  162. package/dist/utils/tool.js.map +1 -0
  163. package/package.json +16 -9
  164. package/dist/index.cjs.cjs +0 -3442
  165. package/dist/index.cjs.cjs.map +0 -1
  166. package/dist/index.cjs.d.ts +0 -1
  167. package/dist/index.esm.js +0 -3418
  168. package/dist/index.esm.js.map +0 -1
  169. package/dist/src/constant.d.ts +0 -2
  170. package/dist/src/core.d.ts +0 -119
  171. package/dist/src/global.d.ts +0 -42
  172. package/dist/src/helpers.d.ts +0 -38
  173. package/dist/src/index.d.ts +0 -14
  174. package/dist/src/module/index.d.ts +0 -25
  175. package/dist/src/plugins/generate-preload-assets.d.ts +0 -8
  176. package/dist/src/plugins/snapshot/SnapshotHandler.d.ts +0 -60
  177. package/dist/src/plugins/snapshot/index.d.ts +0 -5
  178. package/dist/src/remote/index.d.ts +0 -109
  179. package/dist/src/shared/index.d.ts +0 -75
  180. package/dist/src/type/config.d.ts +0 -128
  181. package/dist/src/type/index.d.ts +0 -3
  182. package/dist/src/type/plugin.d.ts +0 -35
  183. package/dist/src/type/preload.d.ts +0 -26
  184. package/dist/src/types.d.ts +0 -1
  185. package/dist/src/utils/env.d.ts +0 -3
  186. package/dist/src/utils/hooks/asyncHook.d.ts +0 -6
  187. package/dist/src/utils/hooks/asyncWaterfallHooks.d.ts +0 -10
  188. package/dist/src/utils/hooks/index.d.ts +0 -6
  189. package/dist/src/utils/hooks/pluginSystem.d.ts +0 -16
  190. package/dist/src/utils/hooks/syncHook.d.ts +0 -12
  191. package/dist/src/utils/hooks/syncWaterfallHook.d.ts +0 -9
  192. package/dist/src/utils/index.d.ts +0 -6
  193. package/dist/src/utils/load.d.ts +0 -11
  194. package/dist/src/utils/logger.d.ts +0 -6
  195. package/dist/src/utils/manifest.d.ts +0 -7
  196. package/dist/src/utils/plugin.d.ts +0 -3
  197. package/dist/src/utils/preload.d.ts +0 -6
  198. package/dist/src/utils/semver/compare.d.ts +0 -9
  199. package/dist/src/utils/semver/constants.d.ts +0 -10
  200. package/dist/src/utils/semver/index.d.ts +0 -2
  201. package/dist/src/utils/semver/parser.d.ts +0 -9
  202. package/dist/src/utils/semver/utils.d.ts +0 -11
  203. package/dist/src/utils/share.d.ts +0 -45
  204. package/dist/src/utils/tool.d.ts +0 -18
  205. package/dist/types.cjs.cjs +0 -3
  206. package/dist/types.cjs.cjs.map +0 -1
  207. package/dist/types.cjs.d.ts +0 -1
  208. package/dist/types.esm.js +0 -2
  209. package/dist/types.esm.js.map +0 -1
@@ -0,0 +1,160 @@
1
+ const require_logger = require('./utils/logger.cjs');
2
+ const require_tool = require('./utils/tool.cjs');
3
+ let _module_federation_sdk = require("@module-federation/sdk");
4
+
5
+ //#region src/global.ts
6
+ const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
7
+ const nativeGlobal = (() => {
8
+ try {
9
+ return document.defaultView;
10
+ } catch {
11
+ return CurrentGlobal;
12
+ }
13
+ })();
14
+ const Global = nativeGlobal;
15
+ function definePropertyGlobalVal(target, key, val) {
16
+ Object.defineProperty(target, key, {
17
+ value: val,
18
+ configurable: false,
19
+ writable: true
20
+ });
21
+ }
22
+ function includeOwnProperty(target, key) {
23
+ return Object.hasOwnProperty.call(target, key);
24
+ }
25
+ if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
26
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
27
+ function setGlobalDefaultVal(target) {
28
+ if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
29
+ if (!includeOwnProperty(target, "__FEDERATION__")) {
30
+ definePropertyGlobalVal(target, "__FEDERATION__", {
31
+ __GLOBAL_PLUGIN__: [],
32
+ __INSTANCES__: [],
33
+ moduleInfo: {},
34
+ __SHARE__: {},
35
+ __MANIFEST_LOADING__: {},
36
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map()
37
+ });
38
+ definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
39
+ }
40
+ target.__FEDERATION__.__GLOBAL_PLUGIN__ ??= [];
41
+ target.__FEDERATION__.__INSTANCES__ ??= [];
42
+ target.__FEDERATION__.moduleInfo ??= {};
43
+ target.__FEDERATION__.__SHARE__ ??= {};
44
+ target.__FEDERATION__.__MANIFEST_LOADING__ ??= {};
45
+ target.__FEDERATION__.__PRELOADED_MAP__ ??= /* @__PURE__ */ new Map();
46
+ }
47
+ setGlobalDefaultVal(CurrentGlobal);
48
+ setGlobalDefaultVal(nativeGlobal);
49
+ function resetFederationGlobalInfo() {
50
+ CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
51
+ CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
52
+ CurrentGlobal.__FEDERATION__.moduleInfo = {};
53
+ CurrentGlobal.__FEDERATION__.__SHARE__ = {};
54
+ CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
55
+ Object.keys(globalLoading).forEach((key) => {
56
+ delete globalLoading[key];
57
+ });
58
+ }
59
+ function setGlobalFederationInstance(FederationInstance) {
60
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
61
+ }
62
+ function getGlobalFederationConstructor() {
63
+ return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
64
+ }
65
+ function setGlobalFederationConstructor(FederationConstructor, isDebug = (0, _module_federation_sdk.isDebugMode)()) {
66
+ if (isDebug) {
67
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
68
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.2.0";
69
+ }
70
+ }
71
+ function getInfoWithoutType(target, key) {
72
+ if (typeof key === "string") if (target[key]) return {
73
+ value: target[key],
74
+ key
75
+ };
76
+ else {
77
+ const targetKeys = Object.keys(target);
78
+ for (const targetKey of targetKeys) {
79
+ const [targetTypeOrName, _] = targetKey.split(":");
80
+ const nKey = `${targetTypeOrName}:${key}`;
81
+ const typeWithKeyRes = target[nKey];
82
+ if (typeWithKeyRes) return {
83
+ value: typeWithKeyRes,
84
+ key: nKey
85
+ };
86
+ }
87
+ return {
88
+ value: void 0,
89
+ key
90
+ };
91
+ }
92
+ else require_logger.error(`getInfoWithoutType: "key" must be a string, got ${typeof key} (${JSON.stringify(key)}).`);
93
+ }
94
+ const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
95
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
96
+ const getModuleInfo = getInfoWithoutType(snapshot, require_tool.getFMId(moduleInfo)).value;
97
+ if (getModuleInfo && !getModuleInfo.version && "version" in moduleInfo && moduleInfo["version"]) getModuleInfo.version = moduleInfo["version"];
98
+ if (getModuleInfo) return getModuleInfo;
99
+ if ("version" in moduleInfo && moduleInfo["version"]) {
100
+ const { version, ...resModuleInfo } = moduleInfo;
101
+ const moduleKeyWithoutVersion = require_tool.getFMId(resModuleInfo);
102
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
103
+ if (getModuleInfoWithoutVersion?.version === version) return getModuleInfoWithoutVersion;
104
+ }
105
+ };
106
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo) => getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
107
+ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo) => {
108
+ const moduleKey = require_tool.getFMId(remoteInfo);
109
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
110
+ return nativeGlobal.__FEDERATION__.moduleInfo;
111
+ };
112
+ const addGlobalSnapshot = (moduleInfos) => {
113
+ nativeGlobal.__FEDERATION__.moduleInfo = {
114
+ ...nativeGlobal.__FEDERATION__.moduleInfo,
115
+ ...moduleInfos
116
+ };
117
+ return () => {
118
+ const keys = Object.keys(moduleInfos);
119
+ for (const key of keys) delete nativeGlobal.__FEDERATION__.moduleInfo[key];
120
+ };
121
+ };
122
+ const getRemoteEntryExports = (name, globalName) => {
123
+ const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
124
+ return {
125
+ remoteEntryKey,
126
+ entryExports: CurrentGlobal[remoteEntryKey]
127
+ };
128
+ };
129
+ const registerGlobalPlugins = (plugins) => {
130
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
131
+ plugins.forEach((plugin) => {
132
+ if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) __GLOBAL_PLUGIN__.push(plugin);
133
+ else require_logger.warn(`The plugin ${plugin.name} has been registered.`);
134
+ });
135
+ };
136
+ const getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
137
+ const getPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
138
+ const setPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
139
+
140
+ //#endregion
141
+ exports.CurrentGlobal = CurrentGlobal;
142
+ exports.Global = Global;
143
+ exports.addGlobalSnapshot = addGlobalSnapshot;
144
+ exports.getGlobalFederationConstructor = getGlobalFederationConstructor;
145
+ exports.getGlobalHostPlugins = getGlobalHostPlugins;
146
+ exports.getGlobalSnapshot = getGlobalSnapshot;
147
+ exports.getGlobalSnapshotInfoByModuleInfo = getGlobalSnapshotInfoByModuleInfo;
148
+ exports.getInfoWithoutType = getInfoWithoutType;
149
+ exports.getPreloaded = getPreloaded;
150
+ exports.getRemoteEntryExports = getRemoteEntryExports;
151
+ exports.getTargetSnapshotInfoByModuleInfo = getTargetSnapshotInfoByModuleInfo;
152
+ exports.globalLoading = globalLoading;
153
+ exports.nativeGlobal = nativeGlobal;
154
+ exports.registerGlobalPlugins = registerGlobalPlugins;
155
+ exports.resetFederationGlobalInfo = resetFederationGlobalInfo;
156
+ exports.setGlobalFederationConstructor = setGlobalFederationConstructor;
157
+ exports.setGlobalFederationInstance = setGlobalFederationInstance;
158
+ exports.setGlobalSnapshotInfoByModuleInfo = setGlobalSnapshotInfoByModuleInfo;
159
+ exports.setPreloaded = setPreloaded;
160
+ //# sourceMappingURL=global.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.cjs","names":["getFMId"],"sources":["../src/global.ts"],"sourcesContent":["import { ModuleFederation } from './core';\nimport {\n RemoteEntryExports,\n GlobalShareScopeMap,\n Remote,\n Optional,\n} from './type';\nimport { getFMId } from './utils/tool';\nimport {\n GlobalModuleInfo,\n ModuleInfo,\n isDebugMode,\n} from '@module-federation/sdk';\nimport { warn, error } from './utils/logger';\nimport { ModuleFederationRuntimePlugin } from './type/plugin';\n\nexport interface Federation {\n __GLOBAL_PLUGIN__: Array<ModuleFederationRuntimePlugin>;\n __DEBUG_CONSTRUCTOR_VERSION__?: string;\n moduleInfo: GlobalModuleInfo;\n __DEBUG_CONSTRUCTOR__?: typeof ModuleFederation;\n __INSTANCES__: Array<ModuleFederation>;\n __SHARE__: GlobalShareScopeMap;\n __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;\n __PRELOADED_MAP__: Map<string, boolean>;\n}\nexport const CurrentGlobal =\n typeof globalThis === 'object' ? globalThis : window;\nexport const nativeGlobal: typeof global = (() => {\n try {\n // get real window (incase of sandbox)\n return document.defaultView;\n } catch {\n // node env\n return CurrentGlobal;\n }\n})() as typeof global;\n\nexport const Global = nativeGlobal;\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __FEDERATION__: Federation,\n __VMOK__: Federation,\n // eslint-disable-next-line no-var\n __GLOBAL_LOADING_REMOTE_ENTRY__: Record<\n string,\n undefined | Promise<RemoteEntryExports | void>\n >;\n}\n\nfunction definePropertyGlobalVal(\n target: typeof CurrentGlobal,\n key: string,\n val: any,\n) {\n Object.defineProperty(target, key, {\n value: val,\n configurable: false,\n writable: true,\n });\n}\n\nfunction includeOwnProperty(target: typeof CurrentGlobal, key: string) {\n return Object.hasOwnProperty.call(target, key);\n}\n\n// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.\n// The sandbox in the microfrontend does not replicate the value of 'configurable'.\n// If there is no loading content on the global object, this section defines the loading object.\nif (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {\n definePropertyGlobalVal(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});\n}\n\nexport const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;\n\nfunction setGlobalDefaultVal(target: typeof CurrentGlobal) {\n if (\n includeOwnProperty(target, '__VMOK__') &&\n !includeOwnProperty(target, '__FEDERATION__')\n ) {\n definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);\n }\n\n if (!includeOwnProperty(target, '__FEDERATION__')) {\n definePropertyGlobalVal(target, '__FEDERATION__', {\n __GLOBAL_PLUGIN__: [],\n __INSTANCES__: [],\n moduleInfo: {},\n __SHARE__: {},\n __MANIFEST_LOADING__: {},\n __PRELOADED_MAP__: new Map(),\n });\n\n definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);\n }\n\n target.__FEDERATION__.__GLOBAL_PLUGIN__ ??= [];\n target.__FEDERATION__.__INSTANCES__ ??= [];\n target.__FEDERATION__.moduleInfo ??= {};\n target.__FEDERATION__.__SHARE__ ??= {};\n target.__FEDERATION__.__MANIFEST_LOADING__ ??= {};\n target.__FEDERATION__.__PRELOADED_MAP__ ??= new Map();\n}\n\nsetGlobalDefaultVal(CurrentGlobal);\nsetGlobalDefaultVal(nativeGlobal);\n\nexport function resetFederationGlobalInfo(): void {\n CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];\n CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];\n CurrentGlobal.__FEDERATION__.moduleInfo = {};\n CurrentGlobal.__FEDERATION__.__SHARE__ = {};\n CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};\n\n Object.keys(globalLoading).forEach((key) => {\n delete globalLoading[key];\n });\n}\n\nexport function setGlobalFederationInstance(\n FederationInstance: ModuleFederation,\n): void {\n CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);\n}\n\nexport function getGlobalFederationConstructor():\n | typeof ModuleFederation\n | undefined {\n return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;\n}\n\nexport function setGlobalFederationConstructor(\n FederationConstructor: typeof ModuleFederation | undefined,\n isDebug = isDebugMode(),\n): void {\n if (isDebug) {\n CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;\n CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = __VERSION__;\n }\n}\n\nexport function getInfoWithoutType<T extends object>(\n target: T,\n key: keyof T,\n): { value: T[keyof T] | undefined; key: string } {\n if (typeof key === 'string') {\n const keyRes = target[key];\n if (keyRes) {\n return {\n value: target[key],\n key: key as string,\n };\n } else {\n const targetKeys = Object.keys(target);\n for (const targetKey of targetKeys) {\n const [targetTypeOrName, _] = targetKey.split(':');\n const nKey = `${targetTypeOrName}:${key}` as unknown as keyof T;\n const typeWithKeyRes = target[nKey];\n if (typeWithKeyRes) {\n return {\n value: typeWithKeyRes,\n key: nKey as string,\n };\n }\n }\n return {\n value: undefined,\n key: key as string,\n };\n }\n } else {\n error(\n `getInfoWithoutType: \"key\" must be a string, got ${typeof key} (${JSON.stringify(key)}).`,\n );\n }\n}\n\nexport const getGlobalSnapshot = (): GlobalModuleInfo =>\n nativeGlobal.__FEDERATION__.moduleInfo;\n\nexport const getTargetSnapshotInfoByModuleInfo = (\n moduleInfo: Optional<Remote, 'alias'>,\n snapshot: GlobalModuleInfo,\n): GlobalModuleInfo[string] | undefined => {\n // Check if the remote is included in the hostSnapshot\n const moduleKey = getFMId(moduleInfo);\n const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;\n\n // The remoteSnapshot might not include a version\n if (\n getModuleInfo &&\n !getModuleInfo.version &&\n 'version' in moduleInfo &&\n moduleInfo['version']\n ) {\n getModuleInfo.version = moduleInfo['version'];\n }\n\n if (getModuleInfo) {\n return getModuleInfo;\n }\n\n // If the remote is not included in the hostSnapshot, deploy a micro app snapshot\n if ('version' in moduleInfo && moduleInfo['version']) {\n const { version, ...resModuleInfo } = moduleInfo;\n const moduleKeyWithoutVersion = getFMId(resModuleInfo);\n const getModuleInfoWithoutVersion = getInfoWithoutType(\n nativeGlobal.__FEDERATION__.moduleInfo,\n moduleKeyWithoutVersion,\n ).value;\n\n if (getModuleInfoWithoutVersion?.version === version) {\n return getModuleInfoWithoutVersion;\n }\n }\n\n return;\n};\n\nexport const getGlobalSnapshotInfoByModuleInfo = (\n moduleInfo: Optional<Remote, 'alias'>,\n): GlobalModuleInfo[string] | undefined =>\n getTargetSnapshotInfoByModuleInfo(\n moduleInfo,\n nativeGlobal.__FEDERATION__.moduleInfo,\n );\n\nexport const setGlobalSnapshotInfoByModuleInfo = (\n remoteInfo: Remote,\n moduleDetailInfo: GlobalModuleInfo[string],\n): GlobalModuleInfo => {\n const moduleKey = getFMId(remoteInfo);\n nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;\n return nativeGlobal.__FEDERATION__.moduleInfo;\n};\n\nexport const addGlobalSnapshot = (\n moduleInfos: GlobalModuleInfo,\n): (() => void) => {\n nativeGlobal.__FEDERATION__.moduleInfo = {\n ...nativeGlobal.__FEDERATION__.moduleInfo,\n ...moduleInfos,\n };\n return () => {\n const keys = Object.keys(moduleInfos);\n for (const key of keys) {\n delete nativeGlobal.__FEDERATION__.moduleInfo[key];\n }\n };\n};\n\nexport const getRemoteEntryExports = (\n name: string,\n globalName: string | undefined,\n): {\n remoteEntryKey: string;\n entryExports: RemoteEntryExports | undefined;\n} => {\n const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;\n const entryExports = (CurrentGlobal as any)[remoteEntryKey];\n return {\n remoteEntryKey,\n entryExports,\n };\n};\n\n// This function is used to register global plugins.\n// It iterates over the provided plugins and checks if they are already registered.\n// If a plugin is not registered, it is added to the global plugins.\n// If a plugin is already registered, a warning message is logged.\nexport const registerGlobalPlugins = (\n plugins: Array<ModuleFederationRuntimePlugin>,\n): void => {\n const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;\n\n plugins.forEach((plugin) => {\n if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {\n __GLOBAL_PLUGIN__.push(plugin);\n } else {\n warn(`The plugin ${plugin.name} has been registered.`);\n }\n });\n};\n\nexport const getGlobalHostPlugins = (): Array<ModuleFederationRuntimePlugin> =>\n nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;\n\nexport const getPreloaded = (id: string) =>\n CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);\n\nexport const setPreloaded = (id: string) =>\n CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);\n"],"mappings":";;;;;AA0BA,MAAa,gBACX,OAAO,eAAe,WAAW,aAAa;AAChD,MAAa,sBAAqC;AAChD,KAAI;AAEF,SAAO,SAAS;SACV;AAEN,SAAO;;IAEP;AAEJ,MAAa,SAAS;AAatB,SAAS,wBACP,QACA,KACA,KACA;AACA,QAAO,eAAe,QAAQ,KAAK;EACjC,OAAO;EACP,cAAc;EACd,UAAU;EACX,CAAC;;AAGJ,SAAS,mBAAmB,QAA8B,KAAa;AACrE,QAAO,OAAO,eAAe,KAAK,QAAQ,IAAI;;AAMhD,IAAI,CAAC,mBAAmB,eAAe,kCAAkC,CACvE,yBAAwB,eAAe,mCAAmC,EAAE,CAAC;AAG/E,MAAa,gBAAgB,cAAc;AAE3C,SAAS,oBAAoB,QAA8B;AACzD,KACE,mBAAmB,QAAQ,WAAW,IACtC,CAAC,mBAAmB,QAAQ,iBAAiB,CAE7C,yBAAwB,QAAQ,k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,WAAW,MAAM,EAAE,SAAS,OAAO,KAAK,KAAK,GACjE,mBAAkB,KAAK,OAAO;MAE9B,qBAAK,cAAc,OAAO,KAAK,uBAAuB;GAExD;;AAGJ,MAAa,6BACX,aAAa,eAAe;AAE9B,MAAa,gBAAgB,OAC3B,cAAc,eAAe,kBAAkB,IAAI,GAAG;AAExD,MAAa,gBAAgB,OAC3B,cAAc,eAAe,kBAAkB,IAAI,IAAI,KAAK"}
@@ -0,0 +1,45 @@
1
+ import { ModuleFederation } from "./core.js";
2
+ import { ModuleFederationRuntimePlugin } from "./type/plugin.js";
3
+ import { GlobalShareScopeMap, Optional, Remote, RemoteEntryExports } from "./type/config.js";
4
+ import { GlobalModuleInfo, ModuleInfo } from "@module-federation/sdk";
5
+
6
+ //#region src/global.d.ts
7
+ interface Federation {
8
+ __GLOBAL_PLUGIN__: Array<ModuleFederationRuntimePlugin>;
9
+ __DEBUG_CONSTRUCTOR_VERSION__?: string;
10
+ moduleInfo: GlobalModuleInfo;
11
+ __DEBUG_CONSTRUCTOR__?: typeof ModuleFederation;
12
+ __INSTANCES__: Array<ModuleFederation>;
13
+ __SHARE__: GlobalShareScopeMap;
14
+ __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;
15
+ __PRELOADED_MAP__: Map<string, boolean>;
16
+ }
17
+ declare const CurrentGlobal: typeof globalThis;
18
+ declare const Global: typeof globalThis;
19
+ declare global {
20
+ var __FEDERATION__: Federation, __VMOK__: Federation, __GLOBAL_LOADING_REMOTE_ENTRY__: Record<string, undefined | Promise<RemoteEntryExports | void>>;
21
+ }
22
+ declare function resetFederationGlobalInfo(): void;
23
+ declare function setGlobalFederationInstance(FederationInstance: ModuleFederation): void;
24
+ declare function getGlobalFederationConstructor(): typeof ModuleFederation | undefined;
25
+ declare function setGlobalFederationConstructor(FederationConstructor: typeof ModuleFederation | undefined, isDebug?: boolean): void;
26
+ declare function getInfoWithoutType<T extends object>(target: T, key: keyof T): {
27
+ value: T[keyof T] | undefined;
28
+ key: string;
29
+ };
30
+ declare const getGlobalSnapshot: () => GlobalModuleInfo;
31
+ declare const getTargetSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, "alias">, snapshot: GlobalModuleInfo) => GlobalModuleInfo[string] | undefined;
32
+ declare const getGlobalSnapshotInfoByModuleInfo: (moduleInfo: Optional<Remote, "alias">) => GlobalModuleInfo[string] | undefined;
33
+ declare const setGlobalSnapshotInfoByModuleInfo: (remoteInfo: Remote, moduleDetailInfo: GlobalModuleInfo[string]) => GlobalModuleInfo;
34
+ declare const addGlobalSnapshot: (moduleInfos: GlobalModuleInfo) => (() => void);
35
+ declare const getRemoteEntryExports: (name: string, globalName: string | undefined) => {
36
+ remoteEntryKey: string;
37
+ entryExports: RemoteEntryExports | undefined;
38
+ };
39
+ declare const registerGlobalPlugins: (plugins: Array<ModuleFederationRuntimePlugin>) => void;
40
+ declare const getGlobalHostPlugins: () => Array<ModuleFederationRuntimePlugin>;
41
+ declare const getPreloaded: (id: string) => boolean | undefined;
42
+ declare const setPreloaded: (id: string) => Map<string, boolean>;
43
+ //#endregion
44
+ export { CurrentGlobal, Federation, Global, addGlobalSnapshot, getGlobalFederationConstructor, getGlobalHostPlugins, getGlobalSnapshot, getGlobalSnapshotInfoByModuleInfo, getInfoWithoutType, getPreloaded, getRemoteEntryExports, getTargetSnapshotInfoByModuleInfo, registerGlobalPlugins, resetFederationGlobalInfo, setGlobalFederationConstructor, setGlobalFederationInstance, setGlobalSnapshotInfoByModuleInfo, setPreloaded };
45
+ //# sourceMappingURL=global.d.ts.map
package/dist/global.js ADDED
@@ -0,0 +1,142 @@
1
+ import { error, warn as warn$1 } from "./utils/logger.js";
2
+ import { getFMId } from "./utils/tool.js";
3
+ import { isDebugMode } from "@module-federation/sdk";
4
+
5
+ //#region src/global.ts
6
+ const CurrentGlobal = typeof globalThis === "object" ? globalThis : window;
7
+ const nativeGlobal = (() => {
8
+ try {
9
+ return document.defaultView;
10
+ } catch {
11
+ return CurrentGlobal;
12
+ }
13
+ })();
14
+ const Global = nativeGlobal;
15
+ function definePropertyGlobalVal(target, key, val) {
16
+ Object.defineProperty(target, key, {
17
+ value: val,
18
+ configurable: false,
19
+ writable: true
20
+ });
21
+ }
22
+ function includeOwnProperty(target, key) {
23
+ return Object.hasOwnProperty.call(target, key);
24
+ }
25
+ if (!includeOwnProperty(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__")) definePropertyGlobalVal(CurrentGlobal, "__GLOBAL_LOADING_REMOTE_ENTRY__", {});
26
+ const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;
27
+ function setGlobalDefaultVal(target) {
28
+ if (includeOwnProperty(target, "__VMOK__") && !includeOwnProperty(target, "__FEDERATION__")) definePropertyGlobalVal(target, "__FEDERATION__", target.__VMOK__);
29
+ if (!includeOwnProperty(target, "__FEDERATION__")) {
30
+ definePropertyGlobalVal(target, "__FEDERATION__", {
31
+ __GLOBAL_PLUGIN__: [],
32
+ __INSTANCES__: [],
33
+ moduleInfo: {},
34
+ __SHARE__: {},
35
+ __MANIFEST_LOADING__: {},
36
+ __PRELOADED_MAP__: /* @__PURE__ */ new Map()
37
+ });
38
+ definePropertyGlobalVal(target, "__VMOK__", target.__FEDERATION__);
39
+ }
40
+ target.__FEDERATION__.__GLOBAL_PLUGIN__ ??= [];
41
+ target.__FEDERATION__.__INSTANCES__ ??= [];
42
+ target.__FEDERATION__.moduleInfo ??= {};
43
+ target.__FEDERATION__.__SHARE__ ??= {};
44
+ target.__FEDERATION__.__MANIFEST_LOADING__ ??= {};
45
+ target.__FEDERATION__.__PRELOADED_MAP__ ??= /* @__PURE__ */ new Map();
46
+ }
47
+ setGlobalDefaultVal(CurrentGlobal);
48
+ setGlobalDefaultVal(nativeGlobal);
49
+ function resetFederationGlobalInfo() {
50
+ CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];
51
+ CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];
52
+ CurrentGlobal.__FEDERATION__.moduleInfo = {};
53
+ CurrentGlobal.__FEDERATION__.__SHARE__ = {};
54
+ CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};
55
+ Object.keys(globalLoading).forEach((key) => {
56
+ delete globalLoading[key];
57
+ });
58
+ }
59
+ function setGlobalFederationInstance(FederationInstance) {
60
+ CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);
61
+ }
62
+ function getGlobalFederationConstructor() {
63
+ return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;
64
+ }
65
+ function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
66
+ if (isDebug) {
67
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
68
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.2.0";
69
+ }
70
+ }
71
+ function getInfoWithoutType(target, key) {
72
+ if (typeof key === "string") if (target[key]) return {
73
+ value: target[key],
74
+ key
75
+ };
76
+ else {
77
+ const targetKeys = Object.keys(target);
78
+ for (const targetKey of targetKeys) {
79
+ const [targetTypeOrName, _] = targetKey.split(":");
80
+ const nKey = `${targetTypeOrName}:${key}`;
81
+ const typeWithKeyRes = target[nKey];
82
+ if (typeWithKeyRes) return {
83
+ value: typeWithKeyRes,
84
+ key: nKey
85
+ };
86
+ }
87
+ return {
88
+ value: void 0,
89
+ key
90
+ };
91
+ }
92
+ else error(`getInfoWithoutType: "key" must be a string, got ${typeof key} (${JSON.stringify(key)}).`);
93
+ }
94
+ const getGlobalSnapshot = () => nativeGlobal.__FEDERATION__.moduleInfo;
95
+ const getTargetSnapshotInfoByModuleInfo = (moduleInfo, snapshot) => {
96
+ const getModuleInfo = getInfoWithoutType(snapshot, getFMId(moduleInfo)).value;
97
+ if (getModuleInfo && !getModuleInfo.version && "version" in moduleInfo && moduleInfo["version"]) getModuleInfo.version = moduleInfo["version"];
98
+ if (getModuleInfo) return getModuleInfo;
99
+ if ("version" in moduleInfo && moduleInfo["version"]) {
100
+ const { version, ...resModuleInfo } = moduleInfo;
101
+ const moduleKeyWithoutVersion = getFMId(resModuleInfo);
102
+ const getModuleInfoWithoutVersion = getInfoWithoutType(nativeGlobal.__FEDERATION__.moduleInfo, moduleKeyWithoutVersion).value;
103
+ if (getModuleInfoWithoutVersion?.version === version) return getModuleInfoWithoutVersion;
104
+ }
105
+ };
106
+ const getGlobalSnapshotInfoByModuleInfo = (moduleInfo) => getTargetSnapshotInfoByModuleInfo(moduleInfo, nativeGlobal.__FEDERATION__.moduleInfo);
107
+ const setGlobalSnapshotInfoByModuleInfo = (remoteInfo, moduleDetailInfo) => {
108
+ const moduleKey = getFMId(remoteInfo);
109
+ nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;
110
+ return nativeGlobal.__FEDERATION__.moduleInfo;
111
+ };
112
+ const addGlobalSnapshot = (moduleInfos) => {
113
+ nativeGlobal.__FEDERATION__.moduleInfo = {
114
+ ...nativeGlobal.__FEDERATION__.moduleInfo,
115
+ ...moduleInfos
116
+ };
117
+ return () => {
118
+ const keys = Object.keys(moduleInfos);
119
+ for (const key of keys) delete nativeGlobal.__FEDERATION__.moduleInfo[key];
120
+ };
121
+ };
122
+ const getRemoteEntryExports = (name, globalName) => {
123
+ const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;
124
+ return {
125
+ remoteEntryKey,
126
+ entryExports: CurrentGlobal[remoteEntryKey]
127
+ };
128
+ };
129
+ const registerGlobalPlugins = (plugins) => {
130
+ const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;
131
+ plugins.forEach((plugin) => {
132
+ if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) __GLOBAL_PLUGIN__.push(plugin);
133
+ else warn$1(`The plugin ${plugin.name} has been registered.`);
134
+ });
135
+ };
136
+ const getGlobalHostPlugins = () => nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;
137
+ const getPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);
138
+ const setPreloaded = (id) => CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);
139
+
140
+ //#endregion
141
+ export { CurrentGlobal, Global, addGlobalSnapshot, getGlobalFederationConstructor, getGlobalHostPlugins, getGlobalSnapshot, getGlobalSnapshotInfoByModuleInfo, getInfoWithoutType, getPreloaded, getRemoteEntryExports, getTargetSnapshotInfoByModuleInfo, globalLoading, nativeGlobal, registerGlobalPlugins, resetFederationGlobalInfo, setGlobalFederationConstructor, setGlobalFederationInstance, setGlobalSnapshotInfoByModuleInfo, setPreloaded };
142
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global.js","names":[],"sources":["../src/global.ts"],"sourcesContent":["import { ModuleFederation } from './core';\nimport {\n RemoteEntryExports,\n GlobalShareScopeMap,\n Remote,\n Optional,\n} from './type';\nimport { getFMId } from './utils/tool';\nimport {\n GlobalModuleInfo,\n ModuleInfo,\n isDebugMode,\n} from '@module-federation/sdk';\nimport { warn, error } from './utils/logger';\nimport { ModuleFederationRuntimePlugin } from './type/plugin';\n\nexport interface Federation {\n __GLOBAL_PLUGIN__: Array<ModuleFederationRuntimePlugin>;\n __DEBUG_CONSTRUCTOR_VERSION__?: string;\n moduleInfo: GlobalModuleInfo;\n __DEBUG_CONSTRUCTOR__?: typeof ModuleFederation;\n __INSTANCES__: Array<ModuleFederation>;\n __SHARE__: GlobalShareScopeMap;\n __MANIFEST_LOADING__: Record<string, Promise<ModuleInfo>>;\n __PRELOADED_MAP__: Map<string, boolean>;\n}\nexport const CurrentGlobal =\n typeof globalThis === 'object' ? globalThis : window;\nexport const nativeGlobal: typeof global = (() => {\n try {\n // get real window (incase of sandbox)\n return document.defaultView;\n } catch {\n // node env\n return CurrentGlobal;\n }\n})() as typeof global;\n\nexport const Global = nativeGlobal;\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __FEDERATION__: Federation,\n __VMOK__: Federation,\n // eslint-disable-next-line no-var\n __GLOBAL_LOADING_REMOTE_ENTRY__: Record<\n string,\n undefined | Promise<RemoteEntryExports | void>\n >;\n}\n\nfunction definePropertyGlobalVal(\n target: typeof CurrentGlobal,\n key: string,\n val: any,\n) {\n Object.defineProperty(target, key, {\n value: val,\n configurable: false,\n writable: true,\n });\n}\n\nfunction includeOwnProperty(target: typeof CurrentGlobal, key: string) {\n return Object.hasOwnProperty.call(target, key);\n}\n\n// This section is to prevent encapsulation by certain microfrontend frameworks. Due to reuse policies, sandbox escapes.\n// The sandbox in the microfrontend does not replicate the value of 'configurable'.\n// If there is no loading content on the global object, this section defines the loading object.\nif (!includeOwnProperty(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__')) {\n definePropertyGlobalVal(CurrentGlobal, '__GLOBAL_LOADING_REMOTE_ENTRY__', {});\n}\n\nexport const globalLoading = CurrentGlobal.__GLOBAL_LOADING_REMOTE_ENTRY__;\n\nfunction setGlobalDefaultVal(target: typeof CurrentGlobal) {\n if (\n includeOwnProperty(target, '__VMOK__') &&\n !includeOwnProperty(target, '__FEDERATION__')\n ) {\n definePropertyGlobalVal(target, '__FEDERATION__', target.__VMOK__);\n }\n\n if (!includeOwnProperty(target, '__FEDERATION__')) {\n definePropertyGlobalVal(target, '__FEDERATION__', {\n __GLOBAL_PLUGIN__: [],\n __INSTANCES__: [],\n moduleInfo: {},\n __SHARE__: {},\n __MANIFEST_LOADING__: {},\n __PRELOADED_MAP__: new Map(),\n });\n\n definePropertyGlobalVal(target, '__VMOK__', target.__FEDERATION__);\n }\n\n target.__FEDERATION__.__GLOBAL_PLUGIN__ ??= [];\n target.__FEDERATION__.__INSTANCES__ ??= [];\n target.__FEDERATION__.moduleInfo ??= {};\n target.__FEDERATION__.__SHARE__ ??= {};\n target.__FEDERATION__.__MANIFEST_LOADING__ ??= {};\n target.__FEDERATION__.__PRELOADED_MAP__ ??= new Map();\n}\n\nsetGlobalDefaultVal(CurrentGlobal);\nsetGlobalDefaultVal(nativeGlobal);\n\nexport function resetFederationGlobalInfo(): void {\n CurrentGlobal.__FEDERATION__.__GLOBAL_PLUGIN__ = [];\n CurrentGlobal.__FEDERATION__.__INSTANCES__ = [];\n CurrentGlobal.__FEDERATION__.moduleInfo = {};\n CurrentGlobal.__FEDERATION__.__SHARE__ = {};\n CurrentGlobal.__FEDERATION__.__MANIFEST_LOADING__ = {};\n\n Object.keys(globalLoading).forEach((key) => {\n delete globalLoading[key];\n });\n}\n\nexport function setGlobalFederationInstance(\n FederationInstance: ModuleFederation,\n): void {\n CurrentGlobal.__FEDERATION__.__INSTANCES__.push(FederationInstance);\n}\n\nexport function getGlobalFederationConstructor():\n | typeof ModuleFederation\n | undefined {\n return CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__;\n}\n\nexport function setGlobalFederationConstructor(\n FederationConstructor: typeof ModuleFederation | undefined,\n isDebug = isDebugMode(),\n): void {\n if (isDebug) {\n CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;\n CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = __VERSION__;\n }\n}\n\nexport function getInfoWithoutType<T extends object>(\n target: T,\n key: keyof T,\n): { value: T[keyof T] | undefined; key: string } {\n if (typeof key === 'string') {\n const keyRes = target[key];\n if (keyRes) {\n return {\n value: target[key],\n key: key as string,\n };\n } else {\n const targetKeys = Object.keys(target);\n for (const targetKey of targetKeys) {\n const [targetTypeOrName, _] = targetKey.split(':');\n const nKey = `${targetTypeOrName}:${key}` as unknown as keyof T;\n const typeWithKeyRes = target[nKey];\n if (typeWithKeyRes) {\n return {\n value: typeWithKeyRes,\n key: nKey as string,\n };\n }\n }\n return {\n value: undefined,\n key: key as string,\n };\n }\n } else {\n error(\n `getInfoWithoutType: \"key\" must be a string, got ${typeof key} (${JSON.stringify(key)}).`,\n );\n }\n}\n\nexport const getGlobalSnapshot = (): GlobalModuleInfo =>\n nativeGlobal.__FEDERATION__.moduleInfo;\n\nexport const getTargetSnapshotInfoByModuleInfo = (\n moduleInfo: Optional<Remote, 'alias'>,\n snapshot: GlobalModuleInfo,\n): GlobalModuleInfo[string] | undefined => {\n // Check if the remote is included in the hostSnapshot\n const moduleKey = getFMId(moduleInfo);\n const getModuleInfo = getInfoWithoutType(snapshot, moduleKey).value;\n\n // The remoteSnapshot might not include a version\n if (\n getModuleInfo &&\n !getModuleInfo.version &&\n 'version' in moduleInfo &&\n moduleInfo['version']\n ) {\n getModuleInfo.version = moduleInfo['version'];\n }\n\n if (getModuleInfo) {\n return getModuleInfo;\n }\n\n // If the remote is not included in the hostSnapshot, deploy a micro app snapshot\n if ('version' in moduleInfo && moduleInfo['version']) {\n const { version, ...resModuleInfo } = moduleInfo;\n const moduleKeyWithoutVersion = getFMId(resModuleInfo);\n const getModuleInfoWithoutVersion = getInfoWithoutType(\n nativeGlobal.__FEDERATION__.moduleInfo,\n moduleKeyWithoutVersion,\n ).value;\n\n if (getModuleInfoWithoutVersion?.version === version) {\n return getModuleInfoWithoutVersion;\n }\n }\n\n return;\n};\n\nexport const getGlobalSnapshotInfoByModuleInfo = (\n moduleInfo: Optional<Remote, 'alias'>,\n): GlobalModuleInfo[string] | undefined =>\n getTargetSnapshotInfoByModuleInfo(\n moduleInfo,\n nativeGlobal.__FEDERATION__.moduleInfo,\n );\n\nexport const setGlobalSnapshotInfoByModuleInfo = (\n remoteInfo: Remote,\n moduleDetailInfo: GlobalModuleInfo[string],\n): GlobalModuleInfo => {\n const moduleKey = getFMId(remoteInfo);\n nativeGlobal.__FEDERATION__.moduleInfo[moduleKey] = moduleDetailInfo;\n return nativeGlobal.__FEDERATION__.moduleInfo;\n};\n\nexport const addGlobalSnapshot = (\n moduleInfos: GlobalModuleInfo,\n): (() => void) => {\n nativeGlobal.__FEDERATION__.moduleInfo = {\n ...nativeGlobal.__FEDERATION__.moduleInfo,\n ...moduleInfos,\n };\n return () => {\n const keys = Object.keys(moduleInfos);\n for (const key of keys) {\n delete nativeGlobal.__FEDERATION__.moduleInfo[key];\n }\n };\n};\n\nexport const getRemoteEntryExports = (\n name: string,\n globalName: string | undefined,\n): {\n remoteEntryKey: string;\n entryExports: RemoteEntryExports | undefined;\n} => {\n const remoteEntryKey = globalName || `__FEDERATION_${name}:custom__`;\n const entryExports = (CurrentGlobal as any)[remoteEntryKey];\n return {\n remoteEntryKey,\n entryExports,\n };\n};\n\n// This function is used to register global plugins.\n// It iterates over the provided plugins and checks if they are already registered.\n// If a plugin is not registered, it is added to the global plugins.\n// If a plugin is already registered, a warning message is logged.\nexport const registerGlobalPlugins = (\n plugins: Array<ModuleFederationRuntimePlugin>,\n): void => {\n const { __GLOBAL_PLUGIN__ } = nativeGlobal.__FEDERATION__;\n\n plugins.forEach((plugin) => {\n if (__GLOBAL_PLUGIN__.findIndex((p) => p.name === plugin.name) === -1) {\n __GLOBAL_PLUGIN__.push(plugin);\n } else {\n warn(`The plugin ${plugin.name} has been registered.`);\n }\n });\n};\n\nexport const getGlobalHostPlugins = (): Array<ModuleFederationRuntimePlugin> =>\n nativeGlobal.__FEDERATION__.__GLOBAL_PLUGIN__;\n\nexport const getPreloaded = (id: string) =>\n CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.get(id);\n\nexport const setPreloaded = (id: string) =>\n CurrentGlobal.__FEDERATION__.__PRELOADED_MAP__.set(id, true);\n"],"mappings":";;;;;AA0BA,MAAa,gBACX,OAAO,eAAe,WAAW,aAAa;AAChD,MAAa,sBAAqC;AAChD,KAAI;AAEF,SAAO,SAAS;SACV;AAEN,SAAO;;IAEP;AAEJ,MAAa,SAAS;AAatB,SAAS,wBACP,QACA,KACA,KACA;AACA,QAAO,eAAe,QAAQ,KAAK;EACjC,OAAO;EACP,cAAc;EACd,UAAU;EACX,CAAC;;AAGJ,SAAS,mBAAmB,QAA8B,KAAa;AACrE,QAAO,OAAO,eAAe,KAAK,QAAQ,IAAI;;AAMhD,IAAI,CAAC,mBAAmB,eAAe,kCAA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G;CACH,MAAM,iBAAiB,cAAc,gBAAgB,KAAK;AAE1D,QAAO;EACL;EACA,cAHoB,cAAsB;EAI3C;;AAOH,MAAa,yBACX,YACS;CACT,MAAM,EAAE,sBAAsB,aAAa;AAE3C,SAAQ,SAAS,WAAW;AAC1B,MAAI,kBAAkB,WAAW,MAAM,EAAE,SAAS,OAAO,KAAK,KAAK,GACjE,mBAAkB,KAAK,OAAO;MAE9B,QAAK,cAAc,OAAO,KAAK,uBAAuB;GAExD;;AAGJ,MAAa,6BACX,aAAa,eAAe;AAE9B,MAAa,gBAAgB,OAC3B,cAAc,eAAe,kBAAkB,IAAI,GAAG;AAExD,MAAa,gBAAgB,OAC3B,cAAc,eAAe,kBAAkB,IAAI,IAAI,KAAK"}
@@ -0,0 +1,44 @@
1
+ const require_global = require('./global.cjs');
2
+ const require_share = require('./utils/share.cjs');
3
+ const require_manifest = require('./utils/manifest.cjs');
4
+ const require_load = require('./utils/load.cjs');
5
+ require('./utils/index.cjs');
6
+ const require_preload = require('./utils/preload.cjs');
7
+
8
+ //#region src/helpers.ts
9
+ const ShareUtils = {
10
+ getRegisteredShare: require_share.getRegisteredShare,
11
+ getGlobalShareScope: require_share.getGlobalShareScope
12
+ };
13
+ const GlobalUtils = {
14
+ Global: require_global.Global,
15
+ nativeGlobal: require_global.nativeGlobal,
16
+ resetFederationGlobalInfo: require_global.resetFederationGlobalInfo,
17
+ setGlobalFederationInstance: require_global.setGlobalFederationInstance,
18
+ getGlobalFederationConstructor: require_global.getGlobalFederationConstructor,
19
+ setGlobalFederationConstructor: require_global.setGlobalFederationConstructor,
20
+ getInfoWithoutType: require_global.getInfoWithoutType,
21
+ getGlobalSnapshot: require_global.getGlobalSnapshot,
22
+ getTargetSnapshotInfoByModuleInfo: require_global.getTargetSnapshotInfoByModuleInfo,
23
+ getGlobalSnapshotInfoByModuleInfo: require_global.getGlobalSnapshotInfoByModuleInfo,
24
+ setGlobalSnapshotInfoByModuleInfo: require_global.setGlobalSnapshotInfoByModuleInfo,
25
+ addGlobalSnapshot: require_global.addGlobalSnapshot,
26
+ getRemoteEntryExports: require_global.getRemoteEntryExports,
27
+ registerGlobalPlugins: require_global.registerGlobalPlugins,
28
+ getGlobalHostPlugins: require_global.getGlobalHostPlugins,
29
+ getPreloaded: require_global.getPreloaded,
30
+ setPreloaded: require_global.setPreloaded
31
+ };
32
+ var helpers_default = {
33
+ global: GlobalUtils,
34
+ share: ShareUtils,
35
+ utils: {
36
+ matchRemoteWithNameAndExpose: require_manifest.matchRemoteWithNameAndExpose,
37
+ preloadAssets: require_preload.preloadAssets,
38
+ getRemoteInfo: require_load.getRemoteInfo
39
+ }
40
+ };
41
+
42
+ //#endregion
43
+ exports.default = helpers_default;
44
+ //# sourceMappingURL=helpers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.cjs","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import {\n nativeGlobal,\n resetFederationGlobalInfo,\n setGlobalFederationInstance,\n getGlobalFederationConstructor,\n setGlobalFederationConstructor,\n getInfoWithoutType,\n getGlobalSnapshot,\n getTargetSnapshotInfoByModuleInfo,\n getGlobalSnapshotInfoByModuleInfo,\n setGlobalSnapshotInfoByModuleInfo,\n addGlobalSnapshot,\n getRemoteEntryExports,\n registerGlobalPlugins,\n getGlobalHostPlugins,\n getPreloaded,\n setPreloaded,\n Global,\n} from './global';\nimport { getRegisteredShare, getGlobalShareScope } from './utils/share';\nimport { getRemoteInfo, matchRemoteWithNameAndExpose } from './utils';\nimport { preloadAssets } from './utils/preload';\ninterface IShareUtils {\n getRegisteredShare: typeof getRegisteredShare;\n getGlobalShareScope: typeof getGlobalShareScope;\n}\nconst ShareUtils: IShareUtils = {\n getRegisteredShare,\n getGlobalShareScope,\n};\n\ninterface IGlobalUtils {\n Global: typeof Global;\n nativeGlobal: typeof global;\n resetFederationGlobalInfo: typeof resetFederationGlobalInfo;\n setGlobalFederationInstance: typeof setGlobalFederationInstance;\n getGlobalFederationConstructor: typeof getGlobalFederationConstructor;\n setGlobalFederationConstructor: typeof setGlobalFederationConstructor;\n getInfoWithoutType: typeof getInfoWithoutType;\n getGlobalSnapshot: typeof getGlobalSnapshot;\n getTargetSnapshotInfoByModuleInfo: typeof getTargetSnapshotInfoByModuleInfo;\n getGlobalSnapshotInfoByModuleInfo: typeof getGlobalSnapshotInfoByModuleInfo;\n setGlobalSnapshotInfoByModuleInfo: typeof setGlobalSnapshotInfoByModuleInfo;\n addGlobalSnapshot: typeof addGlobalSnapshot;\n getRemoteEntryExports: typeof getRemoteEntryExports;\n registerGlobalPlugins: typeof registerGlobalPlugins;\n getGlobalHostPlugins: typeof getGlobalHostPlugins;\n getPreloaded: typeof getPreloaded;\n setPreloaded: typeof setPreloaded;\n}\n\nconst GlobalUtils: IGlobalUtils = {\n Global,\n nativeGlobal,\n resetFederationGlobalInfo,\n setGlobalFederationInstance,\n getGlobalFederationConstructor,\n setGlobalFederationConstructor,\n getInfoWithoutType,\n getGlobalSnapshot,\n getTargetSnapshotInfoByModuleInfo,\n getGlobalSnapshotInfoByModuleInfo,\n setGlobalSnapshotInfoByModuleInfo,\n addGlobalSnapshot,\n getRemoteEntryExports,\n registerGlobalPlugins,\n getGlobalHostPlugins,\n getPreloaded,\n setPreloaded,\n};\n\nexport default {\n global: GlobalUtils,\n share: ShareUtils,\n utils: {\n matchRemoteWithNameAndExpose,\n preloadAssets,\n getRemoteInfo,\n },\n};\n\nexport type { IGlobalUtils, IShareUtils };\n"],"mappings":";;;;;;;;AA0BA,MAAM,aAA0B;CAC9B;CACA;CACD;AAsBD,MAAM,cAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,sBAAe;CACb,QAAQ;CACR,OAAO;CACP,OAAO;EACL;EACA;EACA;EACD;CACF"}
@@ -0,0 +1,30 @@
1
+ import { Global, addGlobalSnapshot, getGlobalFederationConstructor, getGlobalHostPlugins, getGlobalSnapshot, getGlobalSnapshotInfoByModuleInfo, getInfoWithoutType, getPreloaded, getRemoteEntryExports, getTargetSnapshotInfoByModuleInfo, registerGlobalPlugins, resetFederationGlobalInfo, setGlobalFederationConstructor, setGlobalFederationInstance, setGlobalSnapshotInfoByModuleInfo, setPreloaded } from "./global.js";
2
+ import { getGlobalShareScope, getRegisteredShare } from "./utils/share.js";
3
+
4
+ //#region src/helpers.d.ts
5
+ interface IShareUtils {
6
+ getRegisteredShare: typeof getRegisteredShare;
7
+ getGlobalShareScope: typeof getGlobalShareScope;
8
+ }
9
+ interface IGlobalUtils {
10
+ Global: typeof Global;
11
+ nativeGlobal: typeof global;
12
+ resetFederationGlobalInfo: typeof resetFederationGlobalInfo;
13
+ setGlobalFederationInstance: typeof setGlobalFederationInstance;
14
+ getGlobalFederationConstructor: typeof getGlobalFederationConstructor;
15
+ setGlobalFederationConstructor: typeof setGlobalFederationConstructor;
16
+ getInfoWithoutType: typeof getInfoWithoutType;
17
+ getGlobalSnapshot: typeof getGlobalSnapshot;
18
+ getTargetSnapshotInfoByModuleInfo: typeof getTargetSnapshotInfoByModuleInfo;
19
+ getGlobalSnapshotInfoByModuleInfo: typeof getGlobalSnapshotInfoByModuleInfo;
20
+ setGlobalSnapshotInfoByModuleInfo: typeof setGlobalSnapshotInfoByModuleInfo;
21
+ addGlobalSnapshot: typeof addGlobalSnapshot;
22
+ getRemoteEntryExports: typeof getRemoteEntryExports;
23
+ registerGlobalPlugins: typeof registerGlobalPlugins;
24
+ getGlobalHostPlugins: typeof getGlobalHostPlugins;
25
+ getPreloaded: typeof getPreloaded;
26
+ setPreloaded: typeof setPreloaded;
27
+ }
28
+ //#endregion
29
+ export { type IGlobalUtils, type IShareUtils };
30
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1,44 @@
1
+ import { Global, addGlobalSnapshot, getGlobalFederationConstructor, getGlobalHostPlugins, getGlobalSnapshot, getGlobalSnapshotInfoByModuleInfo, getInfoWithoutType, getPreloaded, getRemoteEntryExports, getTargetSnapshotInfoByModuleInfo, nativeGlobal, registerGlobalPlugins, resetFederationGlobalInfo, setGlobalFederationConstructor, setGlobalFederationInstance, setGlobalSnapshotInfoByModuleInfo, setPreloaded } from "./global.js";
2
+ import { getGlobalShareScope, getRegisteredShare } from "./utils/share.js";
3
+ import { matchRemoteWithNameAndExpose } from "./utils/manifest.js";
4
+ import { getRemoteInfo } from "./utils/load.js";
5
+ import "./utils/index.js";
6
+ import { preloadAssets } from "./utils/preload.js";
7
+
8
+ //#region src/helpers.ts
9
+ const ShareUtils = {
10
+ getRegisteredShare,
11
+ getGlobalShareScope
12
+ };
13
+ const GlobalUtils = {
14
+ Global,
15
+ nativeGlobal,
16
+ resetFederationGlobalInfo,
17
+ setGlobalFederationInstance,
18
+ getGlobalFederationConstructor,
19
+ setGlobalFederationConstructor,
20
+ getInfoWithoutType,
21
+ getGlobalSnapshot,
22
+ getTargetSnapshotInfoByModuleInfo,
23
+ getGlobalSnapshotInfoByModuleInfo,
24
+ setGlobalSnapshotInfoByModuleInfo,
25
+ addGlobalSnapshot,
26
+ getRemoteEntryExports,
27
+ registerGlobalPlugins,
28
+ getGlobalHostPlugins,
29
+ getPreloaded,
30
+ setPreloaded
31
+ };
32
+ var helpers_default = {
33
+ global: GlobalUtils,
34
+ share: ShareUtils,
35
+ utils: {
36
+ matchRemoteWithNameAndExpose,
37
+ preloadAssets,
38
+ getRemoteInfo
39
+ }
40
+ };
41
+
42
+ //#endregion
43
+ export { helpers_default as default };
44
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","names":[],"sources":["../src/helpers.ts"],"sourcesContent":["import {\n nativeGlobal,\n resetFederationGlobalInfo,\n setGlobalFederationInstance,\n getGlobalFederationConstructor,\n setGlobalFederationConstructor,\n getInfoWithoutType,\n getGlobalSnapshot,\n getTargetSnapshotInfoByModuleInfo,\n getGlobalSnapshotInfoByModuleInfo,\n setGlobalSnapshotInfoByModuleInfo,\n addGlobalSnapshot,\n getRemoteEntryExports,\n registerGlobalPlugins,\n getGlobalHostPlugins,\n getPreloaded,\n setPreloaded,\n Global,\n} from './global';\nimport { getRegisteredShare, getGlobalShareScope } from './utils/share';\nimport { getRemoteInfo, matchRemoteWithNameAndExpose } from './utils';\nimport { preloadAssets } from './utils/preload';\ninterface IShareUtils {\n getRegisteredShare: typeof getRegisteredShare;\n getGlobalShareScope: typeof getGlobalShareScope;\n}\nconst ShareUtils: IShareUtils = {\n getRegisteredShare,\n getGlobalShareScope,\n};\n\ninterface IGlobalUtils {\n Global: typeof Global;\n nativeGlobal: typeof global;\n resetFederationGlobalInfo: typeof resetFederationGlobalInfo;\n setGlobalFederationInstance: typeof setGlobalFederationInstance;\n getGlobalFederationConstructor: typeof getGlobalFederationConstructor;\n setGlobalFederationConstructor: typeof setGlobalFederationConstructor;\n getInfoWithoutType: typeof getInfoWithoutType;\n getGlobalSnapshot: typeof getGlobalSnapshot;\n getTargetSnapshotInfoByModuleInfo: typeof getTargetSnapshotInfoByModuleInfo;\n getGlobalSnapshotInfoByModuleInfo: typeof getGlobalSnapshotInfoByModuleInfo;\n setGlobalSnapshotInfoByModuleInfo: typeof setGlobalSnapshotInfoByModuleInfo;\n addGlobalSnapshot: typeof addGlobalSnapshot;\n getRemoteEntryExports: typeof getRemoteEntryExports;\n registerGlobalPlugins: typeof registerGlobalPlugins;\n getGlobalHostPlugins: typeof getGlobalHostPlugins;\n getPreloaded: typeof getPreloaded;\n setPreloaded: typeof setPreloaded;\n}\n\nconst GlobalUtils: IGlobalUtils = {\n Global,\n nativeGlobal,\n resetFederationGlobalInfo,\n setGlobalFederationInstance,\n getGlobalFederationConstructor,\n setGlobalFederationConstructor,\n getInfoWithoutType,\n getGlobalSnapshot,\n getTargetSnapshotInfoByModuleInfo,\n getGlobalSnapshotInfoByModuleInfo,\n setGlobalSnapshotInfoByModuleInfo,\n addGlobalSnapshot,\n getRemoteEntryExports,\n registerGlobalPlugins,\n getGlobalHostPlugins,\n getPreloaded,\n setPreloaded,\n};\n\nexport default {\n global: GlobalUtils,\n share: ShareUtils,\n utils: {\n matchRemoteWithNameAndExpose,\n preloadAssets,\n getRemoteInfo,\n },\n};\n\nexport type { IGlobalUtils, IShareUtils };\n"],"mappings":";;;;;;;;AA0BA,MAAM,aAA0B;CAC9B;CACA;CACD;AAsBD,MAAM,cAA4B;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,sBAAe;CACb,QAAQ;CACR,OAAO;CACP,OAAO;EACL;EACA;EACA;EACD;CACF"}
package/dist/index.cjs ADDED
@@ -0,0 +1,60 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_logger = require('./utils/logger.cjs');
3
+ const require_tool = require('./utils/tool.cjs');
4
+ const require_global = require('./global.cjs');
5
+ const require_index = require('./utils/semver/index.cjs');
6
+ const require_share = require('./utils/share.cjs');
7
+ const require_manifest = require('./utils/manifest.cjs');
8
+ const require_load = require('./utils/load.cjs');
9
+ require('./utils/index.cjs');
10
+ const require_helpers = require('./helpers.cjs');
11
+ const require_index$2 = require('./module/index.cjs');
12
+ const require_core = require('./core.cjs');
13
+ const require_index$3 = require('./type/index.cjs');
14
+ let _module_federation_sdk = require("@module-federation/sdk");
15
+
16
+ //#region src/index.ts
17
+ const helpers = require_helpers.default;
18
+
19
+ //#endregion
20
+ exports.CurrentGlobal = require_global.CurrentGlobal;
21
+ exports.Global = require_global.Global;
22
+ exports.Module = require_index$2.Module;
23
+ exports.ModuleFederation = require_core.ModuleFederation;
24
+ exports.addGlobalSnapshot = require_global.addGlobalSnapshot;
25
+ exports.assert = require_logger.assert;
26
+ exports.error = require_logger.error;
27
+ exports.getGlobalFederationConstructor = require_global.getGlobalFederationConstructor;
28
+ exports.getGlobalSnapshot = require_global.getGlobalSnapshot;
29
+ exports.getInfoWithoutType = require_global.getInfoWithoutType;
30
+ exports.getRegisteredShare = require_share.getRegisteredShare;
31
+ exports.getRemoteEntry = require_load.getRemoteEntry;
32
+ exports.getRemoteInfo = require_load.getRemoteInfo;
33
+ exports.helpers = helpers;
34
+ exports.isStaticResourcesEqual = require_tool.isStaticResourcesEqual;
35
+ Object.defineProperty(exports, 'loadScript', {
36
+ enumerable: true,
37
+ get: function () {
38
+ return _module_federation_sdk.loadScript;
39
+ }
40
+ });
41
+ Object.defineProperty(exports, 'loadScriptNode', {
42
+ enumerable: true,
43
+ get: function () {
44
+ return _module_federation_sdk.loadScriptNode;
45
+ }
46
+ });
47
+ exports.matchRemoteWithNameAndExpose = require_manifest.matchRemoteWithNameAndExpose;
48
+ exports.registerGlobalPlugins = require_global.registerGlobalPlugins;
49
+ exports.resetFederationGlobalInfo = require_global.resetFederationGlobalInfo;
50
+ exports.safeWrapper = require_tool.safeWrapper;
51
+ exports.satisfy = require_index.satisfy;
52
+ exports.setGlobalFederationConstructor = require_global.setGlobalFederationConstructor;
53
+ exports.setGlobalFederationInstance = require_global.setGlobalFederationInstance;
54
+ Object.defineProperty(exports, 'types', {
55
+ enumerable: true,
56
+ get: function () {
57
+ return require_index$3.type_exports;
58
+ }
59
+ });
60
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["helpersDefault"],"sources":["../src/index.ts"],"sourcesContent":["import helpersDefault, { type IGlobalUtils, type IShareUtils } from './helpers';\n\nconst helpers = helpersDefault;\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 { UserOptions, ModuleFederationRuntimePlugin } 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 } from './module';\nexport * as types from './type';\nexport { helpers };\nexport { satisfy } from '../src/utils/semver';\nexport type { IGlobalUtils, IShareUtils };\n"],"mappings":";;;;;;;;;;;;;;;;AAEA,MAAM,UAAUA"}
package/dist/index.d.ts CHANGED
@@ -1 +1,29 @@
1
- export * from "./src/index";
1
+ import { Module } 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 } 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
+ //#endregion
28
+ export { CurrentGlobal, type Federation, Global, type IGlobalUtils, type IShareUtils, Module, ModuleFederation, type ModuleFederationRuntimePlugin, 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 };
29
+ //# sourceMappingURL=index.d.ts.map