@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
package/dist/index.js ADDED
@@ -0,0 +1,20 @@
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 } from "./module/index.js";
11
+ import { ModuleFederation } from "./core.js";
12
+ import { type_exports } from "./type/index.js";
13
+ import { loadScript, loadScriptNode } from "@module-federation/sdk";
14
+
15
+ //#region src/index.ts
16
+ const helpers = helpers_default;
17
+
18
+ //#endregion
19
+ 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 };
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","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"}
@@ -0,0 +1,129 @@
1
+ const require_logger = require('../utils/logger.cjs');
2
+ const require_tool = require('../utils/tool.cjs');
3
+ const require_load = require('../utils/load.cjs');
4
+ const require_context = require('../utils/context.cjs');
5
+ require('../utils/index.cjs');
6
+ let _module_federation_sdk = require("@module-federation/sdk");
7
+ let _module_federation_error_codes = require("@module-federation/error-codes");
8
+
9
+ //#region src/module/index.ts
10
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
11
+ const localShareScopeMap = hostShareScopeMap;
12
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
13
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
14
+ shareScopeKeys.forEach((shareScopeKey) => {
15
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
16
+ });
17
+ const remoteEntryInitOptions = {
18
+ version: remoteInfo.version || "",
19
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
20
+ };
21
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
22
+ value: localShareScopeMap,
23
+ enumerable: false
24
+ });
25
+ return {
26
+ remoteEntryInitOptions,
27
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
28
+ initScope: rawInitScope ?? []
29
+ };
30
+ }
31
+ var Module = class {
32
+ constructor({ remoteInfo, host }) {
33
+ this.inited = false;
34
+ this.initing = false;
35
+ this.lib = void 0;
36
+ this.remoteInfo = remoteInfo;
37
+ this.host = host;
38
+ }
39
+ async getEntry() {
40
+ if (this.remoteEntryExports) return this.remoteEntryExports;
41
+ const remoteEntryExports = await require_load.getRemoteEntry({
42
+ origin: this.host,
43
+ remoteInfo: this.remoteInfo,
44
+ remoteEntryExports: this.remoteEntryExports
45
+ });
46
+ require_logger.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${(0, _module_federation_sdk.safeToString)(this.remoteInfo)}`);
47
+ this.remoteEntryExports = remoteEntryExports;
48
+ return this.remoteEntryExports;
49
+ }
50
+ async init(id, remoteSnapshot, rawInitScope) {
51
+ const remoteEntryExports = await this.getEntry();
52
+ if (this.inited) return remoteEntryExports;
53
+ if (this.initPromise) {
54
+ await this.initPromise;
55
+ return remoteEntryExports;
56
+ }
57
+ this.initing = true;
58
+ this.initPromise = (async () => {
59
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
60
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
61
+ shareScope,
62
+ remoteEntryInitOptions,
63
+ initScope,
64
+ remoteInfo: this.remoteInfo,
65
+ origin: this.host
66
+ });
67
+ if (typeof remoteEntryExports?.init === "undefined") require_logger.error(_module_federation_error_codes.RUNTIME_002, _module_federation_error_codes.runtimeDescMap, {
68
+ hostName: this.host.name,
69
+ remoteName: this.remoteInfo.name,
70
+ remoteEntryUrl: this.remoteInfo.entry,
71
+ remoteEntryKey: this.remoteInfo.entryGlobalName
72
+ }, void 0, require_context.optionsToMFContext(this.host.options));
73
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
74
+ await this.host.hooks.lifecycle.initContainer.emit({
75
+ ...initContainerOptions,
76
+ id,
77
+ remoteSnapshot,
78
+ remoteEntryExports
79
+ });
80
+ this.inited = true;
81
+ })();
82
+ try {
83
+ await this.initPromise;
84
+ } finally {
85
+ this.initing = false;
86
+ this.initPromise = void 0;
87
+ }
88
+ return remoteEntryExports;
89
+ }
90
+ async get(id, expose, options, remoteSnapshot) {
91
+ const { loadFactory = true } = options || { loadFactory: true };
92
+ const remoteEntryExports = await this.init(id, remoteSnapshot);
93
+ this.lib = remoteEntryExports;
94
+ let moduleFactory;
95
+ moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
96
+ remoteEntryExports,
97
+ expose,
98
+ moduleInfo: this.remoteInfo
99
+ });
100
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
101
+ require_logger.assert(moduleFactory, `${require_tool.getFMId(this.remoteInfo)} remote don't export ${expose}.`);
102
+ const symbolName = require_tool.processModuleAlias(this.remoteInfo.name, expose);
103
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
104
+ if (!loadFactory) return wrapModuleFactory;
105
+ return await wrapModuleFactory();
106
+ }
107
+ wraperFactory(moduleFactory, id) {
108
+ function defineModuleId(res, id) {
109
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
110
+ value: id,
111
+ enumerable: false
112
+ });
113
+ }
114
+ if (moduleFactory instanceof Promise) return async () => {
115
+ const res = await moduleFactory();
116
+ defineModuleId(res, id);
117
+ return res;
118
+ };
119
+ else return () => {
120
+ const res = moduleFactory();
121
+ defineModuleId(res, id);
122
+ return res;
123
+ };
124
+ }
125
+ };
126
+
127
+ //#endregion
128
+ exports.Module = Module;
129
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["getRemoteEntry","RUNTIME_002","runtimeDescMap","optionsToMFContext","getFMId","processModuleAlias"],"sources":["../../src/module/index.ts"],"sourcesContent":["import {\n getFMId,\n assert,\n error,\n processModuleAlias,\n optionsToMFContext,\n} from '../utils';\nimport { safeToString, ModuleInfo } from '@module-federation/sdk';\nimport {\n RUNTIME_002,\n RUNTIME_008,\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} from '../type';\n\nexport type ModuleOptions = ConstructorParameters<typeof Module>[0];\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(): Promise<RemoteEntryExports> {\n if (this.remoteEntryExports) {\n return this.remoteEntryExports;\n }\n\n const remoteEntryExports = await getRemoteEntry({\n origin: this.host,\n remoteInfo: this.remoteInfo,\n remoteEntryExports: this.remoteEntryExports,\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 ) {\n // Get remoteEntry.js\n const remoteEntryExports = await this.getEntry();\n\n if (this.inited) {\n return remoteEntryExports;\n }\n\n if (this.initPromise) {\n await this.initPromise;\n return remoteEntryExports;\n }\n\n this.initing = true;\n this.initPromise = (async () => {\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 await remoteEntryExports.init(\n initContainerOptions.shareScope,\n initContainerOptions.initScope,\n initContainerOptions.remoteEntryInitOptions,\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 } 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(id, remoteSnapshot);\n this.lib = remoteEntryExports;\n\n let moduleFactory;\n moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({\n remoteEntryExports,\n expose,\n moduleInfo: this.remoteInfo,\n });\n\n // get exposeGetter\n if (!moduleFactory) {\n moduleFactory = await remoteEntryExports.get(expose);\n }\n\n assert(\n moduleFactory,\n `${getFMId(this.remoteInfo)} remote don't export ${expose}.`,\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 const exposeContent = await wrapModuleFactory();\n\n return exposeContent;\n }\n\n private wraperFactory(\n moduleFactory: () => any | (() => Promise<any>),\n id: string,\n ) {\n function defineModuleId(res: any, 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 if (moduleFactory instanceof Promise) {\n return async () => {\n const res = await moduleFactory();\n // This parameter is used for bridge debugging\n defineModuleId(res, id);\n return res;\n };\n } else {\n return () => {\n const res = moduleFactory();\n // This parameter is used for bridge debugging\n defineModuleId(res, id);\n return res;\n };\n }\n }\n}\n\nexport { Module };\n"],"mappings":";;;;;;;;;AAwBA,SAAgB,6BACd,YACA,mBACA,cACqB;CACrB,MAAM,qBAAqB;CAE3B,MAAM,iBAAiB,MAAM,QAAQ,WAAW,WAAW,GACvD,WAAW,aACX,CAAC,WAAW,WAAW;AAE3B,KAAI,CAAC,eAAe,OAClB,gBAAe,KAAK,UAAU;AAEhC,gBAAe,SAAS,kBAAkB;AACxC,MAAI,CAAC,mBAAmB,eACtB,oBAAmB,iBAAiB,EAAE;GAExC;CAEF,MAAM,yBAAyB;EAC7B,SAAS,WAAW,WAAW;EAC/B,gBAAgB,MAAM,QAAQ,WAAW,WAAW,GAChD,iBACA,WAAW,cAAc;EAC9B;AAGD,QAAO,eAAe,wBAAwB,iBAAiB;EAC7D,OAAO;EAEP,YAAY;EACb,CAAC;AAMF,QAAO;EACL;EACA,YALiB,mBAAmB,eAAe;EAMnD,WAL2B,gBAAgB,EAAE;EAM9C;;AAGH,IAAM,SAAN,MAAa;CASX,YAAY,EACV,YACA,QAIC;gBAbM;iBACC;aAG4B;AAUpC,OAAK,aAAa;AAClB,OAAK,OAAO;;CAGd,MAAM,WAAwC;AAC5C,MAAI,KAAK,mBACP,QAAO,KAAK;EAGd,MAAM,qBAAqB,MAAMA,4BAAe;GAC9C,QAAQ,KAAK;GACb,YAAY,KAAK;GACjB,oBAAoB,KAAK;GAC1B,CAAC;AAEF,wBACE,oBACA,+EAAmD,KAAK,WAAW,GACpE;AAED,OAAK,qBAAqB;AAC1B,SAAO,KAAK;;CAKd,MAAM,KACJ,IACA,gBACA,cACA;EAEA,MAAM,qBAAqB,MAAM,KAAK,UAAU;AAEhD,MAAI,KAAK,OACP,QAAO;AAGT,MAAI,KAAK,aAAa;AACpB,SAAM,KAAK;AACX,UAAO;;AAGT,OAAK,UAAU;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O;AAIT,SAFsB,MAAM,mBAAmB;;CAKjD,AAAQ,cACN,eACA,IACA;EACA,SAAS,eAAe,KAAU,IAAY;AAC5C,OACE,OACA,OAAO,QAAQ,YACf,OAAO,aAAa,IAAI,IACxB,CAAC,OAAO,yBAAyB,KAAK,OAAO,IAAI,eAAe,CAAC,CAEjE,QAAO,eAAe,KAAK,OAAO,IAAI,eAAe,EAAE;IACrD,OAAO;IACP,YAAY;IACb,CAAC;;AAIN,MAAI,yBAAyB,QAC3B,QAAO,YAAY;GACjB,MAAM,MAAM,MAAM,eAAe;AAEjC,kBAAe,KAAK,GAAG;AACvB,UAAO;;MAGT,cAAa;GACX,MAAM,MAAM,eAAe;AAE3B,kBAAe,KAAK,GAAG;AACvB,UAAO"}
@@ -0,0 +1,31 @@
1
+ import { ModuleFederation } from "../core.js";
2
+ import { InitScope, RemoteEntryExports, RemoteInfo } from "../type/config.js";
3
+ import { ModuleInfo } from "@module-federation/sdk";
4
+
5
+ //#region src/module/index.d.ts
6
+ type ModuleOptions = ConstructorParameters<typeof Module$1>[0];
7
+ declare class Module$1 {
8
+ remoteInfo: RemoteInfo;
9
+ inited: boolean;
10
+ initing: boolean;
11
+ initPromise?: Promise<void>;
12
+ remoteEntryExports?: RemoteEntryExports;
13
+ lib: RemoteEntryExports | undefined;
14
+ host: ModuleFederation;
15
+ constructor({
16
+ remoteInfo,
17
+ host
18
+ }: {
19
+ remoteInfo: RemoteInfo;
20
+ host: ModuleFederation;
21
+ });
22
+ getEntry(): Promise<RemoteEntryExports>;
23
+ init(id?: string, remoteSnapshot?: ModuleInfo, rawInitScope?: InitScope): Promise<RemoteEntryExports>;
24
+ get(id: string, expose: string, options?: {
25
+ loadFactory?: boolean;
26
+ }, remoteSnapshot?: ModuleInfo): Promise<any>;
27
+ private wraperFactory;
28
+ }
29
+ //#endregion
30
+ export { Module$1 as Module, ModuleOptions };
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,129 @@
1
+ import { assert, error } from "../utils/logger.js";
2
+ import { getFMId, processModuleAlias } from "../utils/tool.js";
3
+ import { getRemoteEntry } from "../utils/load.js";
4
+ import { optionsToMFContext } from "../utils/context.js";
5
+ import "../utils/index.js";
6
+ import { safeToString } from "@module-federation/sdk";
7
+ import { RUNTIME_002, runtimeDescMap } from "@module-federation/error-codes";
8
+
9
+ //#region src/module/index.ts
10
+ function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
11
+ const localShareScopeMap = hostShareScopeMap;
12
+ const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
13
+ if (!shareScopeKeys.length) shareScopeKeys.push("default");
14
+ shareScopeKeys.forEach((shareScopeKey) => {
15
+ if (!localShareScopeMap[shareScopeKey]) localShareScopeMap[shareScopeKey] = {};
16
+ });
17
+ const remoteEntryInitOptions = {
18
+ version: remoteInfo.version || "",
19
+ shareScopeKeys: Array.isArray(remoteInfo.shareScope) ? shareScopeKeys : remoteInfo.shareScope || "default"
20
+ };
21
+ Object.defineProperty(remoteEntryInitOptions, "shareScopeMap", {
22
+ value: localShareScopeMap,
23
+ enumerable: false
24
+ });
25
+ return {
26
+ remoteEntryInitOptions,
27
+ shareScope: localShareScopeMap[shareScopeKeys[0]],
28
+ initScope: rawInitScope ?? []
29
+ };
30
+ }
31
+ var Module$1 = class {
32
+ constructor({ remoteInfo, host }) {
33
+ this.inited = false;
34
+ this.initing = false;
35
+ this.lib = void 0;
36
+ this.remoteInfo = remoteInfo;
37
+ this.host = host;
38
+ }
39
+ async getEntry() {
40
+ if (this.remoteEntryExports) return this.remoteEntryExports;
41
+ const remoteEntryExports = await getRemoteEntry({
42
+ origin: this.host,
43
+ remoteInfo: this.remoteInfo,
44
+ remoteEntryExports: this.remoteEntryExports
45
+ });
46
+ assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
47
+ this.remoteEntryExports = remoteEntryExports;
48
+ return this.remoteEntryExports;
49
+ }
50
+ async init(id, remoteSnapshot, rawInitScope) {
51
+ const remoteEntryExports = await this.getEntry();
52
+ if (this.inited) return remoteEntryExports;
53
+ if (this.initPromise) {
54
+ await this.initPromise;
55
+ return remoteEntryExports;
56
+ }
57
+ this.initing = true;
58
+ this.initPromise = (async () => {
59
+ const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
60
+ const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
61
+ shareScope,
62
+ remoteEntryInitOptions,
63
+ initScope,
64
+ remoteInfo: this.remoteInfo,
65
+ origin: this.host
66
+ });
67
+ if (typeof remoteEntryExports?.init === "undefined") error(RUNTIME_002, runtimeDescMap, {
68
+ hostName: this.host.name,
69
+ remoteName: this.remoteInfo.name,
70
+ remoteEntryUrl: this.remoteInfo.entry,
71
+ remoteEntryKey: this.remoteInfo.entryGlobalName
72
+ }, void 0, optionsToMFContext(this.host.options));
73
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
74
+ await this.host.hooks.lifecycle.initContainer.emit({
75
+ ...initContainerOptions,
76
+ id,
77
+ remoteSnapshot,
78
+ remoteEntryExports
79
+ });
80
+ this.inited = true;
81
+ })();
82
+ try {
83
+ await this.initPromise;
84
+ } finally {
85
+ this.initing = false;
86
+ this.initPromise = void 0;
87
+ }
88
+ return remoteEntryExports;
89
+ }
90
+ async get(id, expose, options, remoteSnapshot) {
91
+ const { loadFactory = true } = options || { loadFactory: true };
92
+ const remoteEntryExports = await this.init(id, remoteSnapshot);
93
+ this.lib = remoteEntryExports;
94
+ let moduleFactory;
95
+ moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
96
+ remoteEntryExports,
97
+ expose,
98
+ moduleInfo: this.remoteInfo
99
+ });
100
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
101
+ assert(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
102
+ const symbolName = processModuleAlias(this.remoteInfo.name, expose);
103
+ const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
104
+ if (!loadFactory) return wrapModuleFactory;
105
+ return await wrapModuleFactory();
106
+ }
107
+ wraperFactory(moduleFactory, id) {
108
+ function defineModuleId(res, id) {
109
+ if (res && typeof res === "object" && Object.isExtensible(res) && !Object.getOwnPropertyDescriptor(res, Symbol.for("mf_module_id"))) Object.defineProperty(res, Symbol.for("mf_module_id"), {
110
+ value: id,
111
+ enumerable: false
112
+ });
113
+ }
114
+ if (moduleFactory instanceof Promise) return async () => {
115
+ const res = await moduleFactory();
116
+ defineModuleId(res, id);
117
+ return res;
118
+ };
119
+ else return () => {
120
+ const res = moduleFactory();
121
+ defineModuleId(res, id);
122
+ return res;
123
+ };
124
+ }
125
+ };
126
+
127
+ //#endregion
128
+ export { Module$1 as Module };
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["Module"],"sources":["../../src/module/index.ts"],"sourcesContent":["import {\n getFMId,\n assert,\n error,\n processModuleAlias,\n optionsToMFContext,\n} from '../utils';\nimport { safeToString, ModuleInfo } from '@module-federation/sdk';\nimport {\n RUNTIME_002,\n RUNTIME_008,\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} from '../type';\n\nexport type ModuleOptions = ConstructorParameters<typeof Module>[0];\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(): Promise<RemoteEntryExports> {\n if (this.remoteEntryExports) {\n return this.remoteEntryExports;\n }\n\n const remoteEntryExports = await getRemoteEntry({\n origin: this.host,\n remoteInfo: this.remoteInfo,\n remoteEntryExports: this.remoteEntryExports,\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 ) {\n // Get remoteEntry.js\n const remoteEntryExports = await this.getEntry();\n\n if (this.inited) {\n return remoteEntryExports;\n }\n\n if (this.initPromise) {\n await this.initPromise;\n return remoteEntryExports;\n }\n\n this.initing = true;\n this.initPromise = (async () => {\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 await remoteEntryExports.init(\n initContainerOptions.shareScope,\n initContainerOptions.initScope,\n initContainerOptions.remoteEntryInitOptions,\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 } 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(id, remoteSnapshot);\n this.lib = remoteEntryExports;\n\n let moduleFactory;\n moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({\n remoteEntryExports,\n expose,\n moduleInfo: this.remoteInfo,\n });\n\n // get exposeGetter\n if (!moduleFactory) {\n moduleFactory = await remoteEntryExports.get(expose);\n }\n\n assert(\n moduleFactory,\n `${getFMId(this.remoteInfo)} remote don't export ${expose}.`,\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 const exposeContent = await wrapModuleFactory();\n\n return exposeContent;\n }\n\n private wraperFactory(\n moduleFactory: () => any | (() => Promise<any>),\n id: string,\n ) {\n function defineModuleId(res: any, 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 if (moduleFactory instanceof Promise) {\n return async () => {\n const res = await moduleFactory();\n // This parameter is used for bridge debugging\n defineModuleId(res, id);\n return res;\n };\n } else {\n return () => {\n const res = moduleFactory();\n // This parameter is used for bridge debugging\n defineModuleId(res, id);\n return res;\n };\n }\n }\n}\n\nexport { Module };\n"],"mappings":";;;;;;;;;AAwBA,SAAgB,6BACd,YACA,mBACA,cACqB;CACrB,MAAM,qBAAqB;CAE3B,MAAM,iBAAiB,MAAM,QAAQ,WAAW,WAAW,GACvD,WAAW,aACX,CAAC,WAAW,WAAW;AAE3B,KAAI,CAAC,eAAe,OAClB,gBAAe,KAAK,UAAU;AAEhC,gBAAe,SAAS,kBAAkB;AACxC,MAAI,CAAC,mBAAmB,eACtB,oBAAmB,iBAAiB,EAAE;GAExC;CAEF,MAAM,yBAAyB;EAC7B,SAAS,WAAW,WAAW;EAC/B,gBAAgB,MAAM,QAAQ,WAAW,WAAW,GAChD,iBACA,WAAW,cAAc;EAC9B;AAGD,QAAO,eAAe,wBAAwB,iBAAiB;EAC7D,OAAO;EAEP,YAAY;EACb,CAAC;AAMF,QAAO;EACL;EACA,YALiB,mBAAmB,eAAe;EAMnD,WAL2B,gBAAgB,EAAE;EAM9C;;AAGH,IAAMA,WAAN,MAAa;CASX,YAAY,EACV,YACA,QAIC;gBAbM;iBACC;aAG4B;AAUpC,OAAK,aAAa;AAClB,OAAK,OAAO;;CAGd,MAAM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AK,KAAK,IAAI,eAAe;AAC9D,OAAK,MAAM;EAEX,IAAI;AACJ,kBAAgB,MAAM,KAAK,KAAK,WAAW,UAAU,iBAAiB,KAAK;GACzE;GACA;GACA,YAAY,KAAK;GAClB,CAAC;AAGF,MAAI,CAAC,cACH,iBAAgB,MAAM,mBAAmB,IAAI,OAAO;AAGtD,SACE,eACA,GAAG,QAAQ,KAAK,WAAW,CAAC,uBAAuB,OAAO,GAC3D;EAGD,MAAM,aAAa,mBAAmB,KAAK,WAAW,MAAM,OAAO;EACnE,MAAM,oBAAoB,KAAK,cAAc,eAAe,WAAW;AAEvE,MAAI,CAAC,YACH,QAAO;AAIT,SAFsB,MAAM,mBAAmB;;CAKjD,AAAQ,cACN,eACA,IACA;EACA,SAAS,eAAe,KAAU,IAAY;AAC5C,OACE,OACA,OAAO,QAAQ,YACf,OAAO,aAAa,IAAI,IACxB,CAAC,OAAO,yBAAyB,KAAK,OAAO,IAAI,eAAe,CAAC,CAEjE,QAAO,eAAe,KAAK,OAAO,IAAI,eAAe,EAAE;IACrD,OAAO;IACP,YAAY;IACb,CAAC;;AAIN,MAAI,yBAAyB,QAC3B,QAAO,YAAY;GACjB,MAAM,MAAM,MAAM,eAAe;AAEjC,kBAAe,KAAK,GAAG;AACvB,UAAO;;MAGT,cAAa;GACX,MAAM,MAAM,eAAe;AAE3B,kBAAe,KAAK,GAAG;AACvB,UAAO"}
@@ -0,0 +1,182 @@
1
+ const require_tool = require('../utils/tool.cjs');
2
+ const require_global = require('../global.cjs');
3
+ const require_share = require('../utils/share.cjs');
4
+ require('../utils/index.cjs');
5
+ const require_preload = require('../utils/preload.cjs');
6
+ const require_index$1 = require('./snapshot/index.cjs');
7
+ let _module_federation_sdk = require("@module-federation/sdk");
8
+
9
+ //#region src/plugins/generate-preload-assets.ts
10
+ function splitId(id) {
11
+ const splitInfo = id.split(":");
12
+ if (splitInfo.length === 1) return {
13
+ name: splitInfo[0],
14
+ version: void 0
15
+ };
16
+ else if (splitInfo.length === 2) return {
17
+ name: splitInfo[0],
18
+ version: splitInfo[1]
19
+ };
20
+ else return {
21
+ name: splitInfo[1],
22
+ version: splitInfo[2]
23
+ };
24
+ }
25
+ function traverseModuleInfo(globalSnapshot, remoteInfo, traverse, isRoot, memo = {}, remoteSnapshot) {
26
+ const { value: snapshotValue } = require_global.getInfoWithoutType(globalSnapshot, require_tool.getFMId(remoteInfo));
27
+ const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;
28
+ if (effectiveRemoteSnapshot && !(0, _module_federation_sdk.isManifestProvider)(effectiveRemoteSnapshot)) {
29
+ traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);
30
+ if (effectiveRemoteSnapshot.remotesInfo) {
31
+ const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);
32
+ for (const key of remoteKeys) {
33
+ if (memo[key]) continue;
34
+ memo[key] = true;
35
+ const subRemoteInfo = splitId(key);
36
+ const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];
37
+ traverseModuleInfo(globalSnapshot, {
38
+ name: subRemoteInfo.name,
39
+ version: remoteValue.matchedVersion
40
+ }, traverse, false, memo, void 0);
41
+ }
42
+ }
43
+ }
44
+ }
45
+ const isExisted = (type, url) => {
46
+ return document.querySelector(`${type}[${type === "link" ? "href" : "src"}="${url}"]`);
47
+ };
48
+ function generatePreloadAssets(origin, preloadOptions, remote, globalSnapshot, remoteSnapshot) {
49
+ const cssAssets = [];
50
+ const jsAssets = [];
51
+ const entryAssets = [];
52
+ const loadedSharedJsAssets = /* @__PURE__ */ new Set();
53
+ const loadedSharedCssAssets = /* @__PURE__ */ new Set();
54
+ const { options } = origin;
55
+ const { preloadConfig: rootPreloadConfig } = preloadOptions;
56
+ const { depsRemote } = rootPreloadConfig;
57
+ traverseModuleInfo(globalSnapshot, remote, (moduleInfoSnapshot, remoteInfo, isRoot) => {
58
+ let preloadConfig;
59
+ if (isRoot) preloadConfig = rootPreloadConfig;
60
+ else if (Array.isArray(depsRemote)) {
61
+ const findPreloadConfig = depsRemote.find((remoteConfig) => {
62
+ if (remoteConfig.nameOrAlias === remoteInfo.name || remoteConfig.nameOrAlias === remoteInfo.alias) return true;
63
+ return false;
64
+ });
65
+ if (!findPreloadConfig) return;
66
+ preloadConfig = require_preload.defaultPreloadArgs(findPreloadConfig);
67
+ } else if (depsRemote === true) preloadConfig = rootPreloadConfig;
68
+ else return;
69
+ const remoteEntryUrl = (0, _module_federation_sdk.getResourceUrl)(moduleInfoSnapshot, require_tool.getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url);
70
+ if (remoteEntryUrl) entryAssets.push({
71
+ name: remoteInfo.name,
72
+ moduleInfo: {
73
+ name: remoteInfo.name,
74
+ entry: remoteEntryUrl,
75
+ type: "remoteEntryType" in moduleInfoSnapshot ? moduleInfoSnapshot.remoteEntryType : "global",
76
+ entryGlobalName: "globalName" in moduleInfoSnapshot ? moduleInfoSnapshot.globalName : remoteInfo.name,
77
+ shareScope: "",
78
+ version: "version" in moduleInfoSnapshot ? moduleInfoSnapshot.version : void 0
79
+ },
80
+ url: remoteEntryUrl
81
+ });
82
+ let moduleAssetsInfo = "modules" in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];
83
+ const normalizedPreloadExposes = require_preload.normalizePreloadExposes(preloadConfig.exposes);
84
+ if (normalizedPreloadExposes.length && "modules" in moduleInfoSnapshot) moduleAssetsInfo = moduleInfoSnapshot?.modules?.reduce((assets, moduleAssetInfo) => {
85
+ if (normalizedPreloadExposes?.indexOf(moduleAssetInfo.moduleName) !== -1) assets.push(moduleAssetInfo);
86
+ return assets;
87
+ }, []);
88
+ function handleAssets(assets) {
89
+ const assetsRes = assets.map((asset) => (0, _module_federation_sdk.getResourceUrl)(moduleInfoSnapshot, asset));
90
+ if (preloadConfig.filter) return assetsRes.filter(preloadConfig.filter);
91
+ return assetsRes;
92
+ }
93
+ if (moduleAssetsInfo) {
94
+ const assetsLength = moduleAssetsInfo.length;
95
+ for (let index = 0; index < assetsLength; index++) {
96
+ const assetsInfo = moduleAssetsInfo[index];
97
+ const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;
98
+ origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({
99
+ id: assetsInfo.moduleName === "." ? remoteInfo.name : exposeFullPath,
100
+ name: remoteInfo.name,
101
+ remoteSnapshot: moduleInfoSnapshot,
102
+ preloadConfig,
103
+ remote: remoteInfo,
104
+ origin
105
+ });
106
+ if (require_global.getPreloaded(exposeFullPath)) continue;
107
+ if (preloadConfig.resourceCategory === "all") {
108
+ cssAssets.push(...handleAssets(assetsInfo.assets.css.async));
109
+ cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
110
+ jsAssets.push(...handleAssets(assetsInfo.assets.js.async));
111
+ jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
112
+ } else if (preloadConfig.resourceCategory === "sync") {
113
+ cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));
114
+ jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));
115
+ }
116
+ require_global.setPreloaded(exposeFullPath);
117
+ }
118
+ }
119
+ }, true, {}, remoteSnapshot);
120
+ if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {
121
+ const collectSharedAssets = (shareInfo, snapshotShared) => {
122
+ const { shared: registeredShared } = require_share.getRegisteredShare(origin.shareScopeMap, snapshotShared.sharedName, shareInfo, origin.sharedHandler.hooks.lifecycle.resolveShare) || {};
123
+ if (registeredShared && typeof registeredShared.lib === "function") {
124
+ snapshotShared.assets.js.sync.forEach((asset) => {
125
+ loadedSharedJsAssets.add(asset);
126
+ });
127
+ snapshotShared.assets.css.sync.forEach((asset) => {
128
+ loadedSharedCssAssets.add(asset);
129
+ });
130
+ }
131
+ };
132
+ remoteSnapshot.shared.forEach((shared) => {
133
+ const shareInfos = options.shared?.[shared.sharedName];
134
+ if (!shareInfos) return;
135
+ const sharedOptions = shared.version ? shareInfos.find((s) => s.version === shared.version) : shareInfos;
136
+ if (!sharedOptions) return;
137
+ require_tool.arrayOptions(sharedOptions).forEach((s) => {
138
+ collectSharedAssets(s, shared);
139
+ });
140
+ });
141
+ }
142
+ const needPreloadJsAssets = jsAssets.filter((asset) => !loadedSharedJsAssets.has(asset) && !isExisted("script", asset));
143
+ return {
144
+ cssAssets: cssAssets.filter((asset) => !loadedSharedCssAssets.has(asset) && !isExisted("link", asset)),
145
+ jsAssetsWithoutEntry: needPreloadJsAssets,
146
+ entryAssets: entryAssets.filter((entry) => !isExisted("script", entry.url))
147
+ };
148
+ }
149
+ const generatePreloadAssetsPlugin = function() {
150
+ return {
151
+ name: "generate-preload-assets-plugin",
152
+ async generatePreloadAssets(args) {
153
+ const { origin, preloadOptions, remoteInfo, remote, globalSnapshot, remoteSnapshot } = args;
154
+ if (!_module_federation_sdk.isBrowserEnvValue) return {
155
+ cssAssets: [],
156
+ jsAssetsWithoutEntry: [],
157
+ entryAssets: []
158
+ };
159
+ if (require_tool.isRemoteInfoWithEntry(remote) && require_tool.isPureRemoteEntry(remote)) return {
160
+ cssAssets: [],
161
+ jsAssetsWithoutEntry: [],
162
+ entryAssets: [{
163
+ name: remote.name,
164
+ url: remote.entry,
165
+ moduleInfo: {
166
+ name: remoteInfo.name,
167
+ entry: remote.entry,
168
+ type: remoteInfo.type || "global",
169
+ entryGlobalName: "",
170
+ shareScope: ""
171
+ }
172
+ }]
173
+ };
174
+ require_index$1.assignRemoteInfo(remoteInfo, remoteSnapshot);
175
+ return generatePreloadAssets(origin, preloadOptions, remoteInfo, globalSnapshot, remoteSnapshot);
176
+ }
177
+ };
178
+ };
179
+
180
+ //#endregion
181
+ exports.generatePreloadAssetsPlugin = generatePreloadAssetsPlugin;
182
+ //# sourceMappingURL=generate-preload-assets.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-preload-assets.cjs","names":["getInfoWithoutType","getFMId","defaultPreloadArgs","getRemoteEntryInfoFromSnapshot","normalizePreloadExposes","getPreloaded","getRegisteredShare","arrayOptions","isBrowserEnvValue","isRemoteInfoWithEntry","isPureRemoteEntry"],"sources":["../../src/plugins/generate-preload-assets.ts"],"sourcesContent":["import {\n GlobalModuleInfo,\n ModuleInfo,\n ProviderModuleInfo,\n isManifestProvider,\n getResourceUrl,\n isBrowserEnvValue,\n} from '@module-federation/sdk';\nimport {\n EntryAssets,\n ModuleFederationRuntimePlugin,\n PreloadAssets,\n PreloadConfig,\n PreloadOptions,\n RemoteInfoOptionalVersion,\n Shared,\n Remote,\n} from '../type';\nimport { assignRemoteInfo } from './snapshot';\nimport { getInfoWithoutType, getPreloaded, setPreloaded } from '../global';\nimport { ModuleFederation } from '../core';\nimport { defaultPreloadArgs, normalizePreloadExposes } from '../utils/preload';\nimport { getRegisteredShare } from '../utils/share';\nimport {\n arrayOptions,\n getFMId,\n getRemoteEntryInfoFromSnapshot,\n isPureRemoteEntry,\n isRemoteInfoWithEntry,\n} from '../utils';\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __INIT_VMOK_DEPLOY_GLOBAL_DATA__: boolean | undefined;\n}\n\n// name\n// name:version\nfunction splitId(id: string): {\n name: string;\n version: string | undefined;\n} {\n const splitInfo = id.split(':');\n if (splitInfo.length === 1) {\n return {\n name: splitInfo[0],\n version: undefined,\n };\n } else if (splitInfo.length === 2) {\n return {\n name: splitInfo[0],\n version: splitInfo[1],\n };\n } else {\n return {\n name: splitInfo[1],\n version: splitInfo[2],\n };\n }\n}\n\n// Traverse all nodes in moduleInfo and traverse the entire snapshot\nfunction traverseModuleInfo(\n globalSnapshot: GlobalModuleInfo,\n remoteInfo: RemoteInfoOptionalVersion,\n traverse: (\n snapshotInfo: ModuleInfo,\n remoteInfo: RemoteInfoOptionalVersion,\n isRoot: boolean,\n ) => void,\n isRoot: boolean,\n memo: Record<string, boolean> = {},\n remoteSnapshot?: ModuleInfo,\n): void {\n const id = getFMId(remoteInfo);\n const { value: snapshotValue } = getInfoWithoutType(globalSnapshot, id);\n const effectiveRemoteSnapshot = remoteSnapshot || snapshotValue;\n if (effectiveRemoteSnapshot && !isManifestProvider(effectiveRemoteSnapshot)) {\n traverse(effectiveRemoteSnapshot, remoteInfo, isRoot);\n if (effectiveRemoteSnapshot.remotesInfo) {\n const remoteKeys = Object.keys(effectiveRemoteSnapshot.remotesInfo);\n for (const key of remoteKeys) {\n if (memo[key]) {\n continue;\n }\n memo[key] = true;\n const subRemoteInfo = splitId(key);\n const remoteValue = effectiveRemoteSnapshot.remotesInfo[key];\n traverseModuleInfo(\n globalSnapshot,\n {\n name: subRemoteInfo.name,\n version: remoteValue.matchedVersion,\n },\n traverse,\n false,\n memo,\n undefined,\n );\n }\n }\n }\n}\n\nconst isExisted = (type: 'link' | 'script', url: string) => {\n return document.querySelector(\n `${type}[${type === 'link' ? 'href' : 'src'}=\"${url}\"]`,\n );\n};\n\n// eslint-disable-next-line max-lines-per-function\nexport function generatePreloadAssets(\n origin: ModuleFederation,\n preloadOptions: PreloadOptions[number],\n remote: RemoteInfoOptionalVersion,\n globalSnapshot: GlobalModuleInfo,\n remoteSnapshot: ModuleInfo,\n): PreloadAssets {\n const cssAssets: Array<string> = [];\n const jsAssets: Array<string> = [];\n const entryAssets: Array<EntryAssets> = [];\n const loadedSharedJsAssets = new Set();\n const loadedSharedCssAssets = new Set();\n const { options } = origin;\n\n const { preloadConfig: rootPreloadConfig } = preloadOptions;\n const { depsRemote } = rootPreloadConfig;\n const memo = {};\n traverseModuleInfo(\n globalSnapshot,\n remote,\n (moduleInfoSnapshot: ModuleInfo, remoteInfo, isRoot) => {\n let preloadConfig: PreloadConfig;\n if (isRoot) {\n preloadConfig = rootPreloadConfig;\n } else {\n if (Array.isArray(depsRemote)) {\n // eslint-disable-next-line array-callback-return\n const findPreloadConfig = depsRemote.find((remoteConfig) => {\n if (\n remoteConfig.nameOrAlias === remoteInfo.name ||\n remoteConfig.nameOrAlias === remoteInfo.alias\n ) {\n return true;\n }\n return false;\n });\n if (!findPreloadConfig) {\n return;\n }\n preloadConfig = defaultPreloadArgs(findPreloadConfig);\n } else if (depsRemote === true) {\n preloadConfig = rootPreloadConfig;\n } else {\n return;\n }\n }\n\n const remoteEntryUrl = getResourceUrl(\n moduleInfoSnapshot,\n getRemoteEntryInfoFromSnapshot(moduleInfoSnapshot).url,\n );\n\n if (remoteEntryUrl) {\n entryAssets.push({\n name: remoteInfo.name,\n moduleInfo: {\n name: remoteInfo.name,\n entry: remoteEntryUrl,\n type:\n 'remoteEntryType' in moduleInfoSnapshot\n ? moduleInfoSnapshot.remoteEntryType\n : 'global',\n entryGlobalName:\n 'globalName' in moduleInfoSnapshot\n ? moduleInfoSnapshot.globalName\n : remoteInfo.name,\n shareScope: '',\n version:\n 'version' in moduleInfoSnapshot\n ? moduleInfoSnapshot.version\n : undefined,\n },\n url: remoteEntryUrl,\n });\n }\n\n let moduleAssetsInfo: NonNullable<ProviderModuleInfo['modules']> =\n 'modules' in moduleInfoSnapshot ? moduleInfoSnapshot.modules : [];\n const normalizedPreloadExposes = normalizePreloadExposes(\n preloadConfig.exposes,\n );\n if (normalizedPreloadExposes.length && 'modules' in moduleInfoSnapshot) {\n moduleAssetsInfo = moduleInfoSnapshot?.modules?.reduce(\n (assets, moduleAssetInfo) => {\n if (\n normalizedPreloadExposes?.indexOf(moduleAssetInfo.moduleName) !==\n -1\n ) {\n assets.push(moduleAssetInfo);\n }\n return assets;\n },\n [] as NonNullable<(typeof moduleInfoSnapshot)['modules']>,\n );\n }\n\n function handleAssets(assets: string[]): string[] {\n const assetsRes = assets.map((asset) =>\n getResourceUrl(moduleInfoSnapshot, asset),\n );\n if (preloadConfig.filter) {\n return assetsRes.filter(preloadConfig.filter);\n }\n return assetsRes;\n }\n\n if (moduleAssetsInfo) {\n const assetsLength = moduleAssetsInfo.length;\n for (let index = 0; index < assetsLength; index++) {\n const assetsInfo = moduleAssetsInfo[index];\n const exposeFullPath = `${remoteInfo.name}/${assetsInfo.moduleName}`;\n origin.remoteHandler.hooks.lifecycle.handlePreloadModule.emit({\n id:\n assetsInfo.moduleName === '.' ? remoteInfo.name : exposeFullPath,\n name: remoteInfo.name,\n remoteSnapshot: moduleInfoSnapshot,\n preloadConfig,\n remote: remoteInfo as Remote,\n origin,\n });\n const preloaded = getPreloaded(exposeFullPath);\n if (preloaded) {\n continue;\n }\n\n if (preloadConfig.resourceCategory === 'all') {\n cssAssets.push(...handleAssets(assetsInfo.assets.css.async));\n cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));\n jsAssets.push(...handleAssets(assetsInfo.assets.js.async));\n jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));\n } else if (preloadConfig.resourceCategory === 'sync') {\n cssAssets.push(...handleAssets(assetsInfo.assets.css.sync));\n jsAssets.push(...handleAssets(assetsInfo.assets.js.sync));\n }\n\n setPreloaded(exposeFullPath);\n }\n }\n },\n true,\n memo,\n remoteSnapshot,\n );\n\n if (remoteSnapshot.shared && remoteSnapshot.shared.length > 0) {\n const collectSharedAssets = (\n shareInfo: Shared,\n snapshotShared: ModuleInfo['shared'][0],\n ) => {\n const { shared: registeredShared } =\n getRegisteredShare(\n origin.shareScopeMap,\n snapshotShared.sharedName,\n shareInfo,\n origin.sharedHandler.hooks.lifecycle.resolveShare,\n ) || {};\n // If the global share does not exist, or the lib function does not exist, it means that the shared has not been loaded yet and can be preloaded.\n\n if (registeredShared && typeof registeredShared.lib === 'function') {\n snapshotShared.assets.js.sync.forEach((asset) => {\n loadedSharedJsAssets.add(asset);\n });\n snapshotShared.assets.css.sync.forEach((asset) => {\n loadedSharedCssAssets.add(asset);\n });\n }\n };\n remoteSnapshot.shared.forEach((shared) => {\n const shareInfos = options.shared?.[shared.sharedName];\n if (!shareInfos) {\n return;\n }\n // if no version, preload all shared\n const sharedOptions = shared.version\n ? shareInfos.find((s) => s.version === shared.version)\n : shareInfos;\n\n if (!sharedOptions) {\n return;\n }\n const arrayShareInfo = arrayOptions(sharedOptions);\n arrayShareInfo.forEach((s) => {\n collectSharedAssets(s, shared);\n });\n });\n }\n\n const needPreloadJsAssets = jsAssets.filter(\n (asset) => !loadedSharedJsAssets.has(asset) && !isExisted('script', asset),\n );\n const needPreloadCssAssets = cssAssets.filter(\n (asset) => !loadedSharedCssAssets.has(asset) && !isExisted('link', asset),\n );\n\n return {\n cssAssets: needPreloadCssAssets,\n jsAssetsWithoutEntry: needPreloadJsAssets,\n entryAssets: entryAssets.filter((entry) => !isExisted('script', entry.url)),\n };\n}\n\nexport const generatePreloadAssetsPlugin: () => ModuleFederationRuntimePlugin =\n function () {\n return {\n name: 'generate-preload-assets-plugin',\n async generatePreloadAssets(args) {\n const {\n origin,\n preloadOptions,\n remoteInfo,\n remote,\n globalSnapshot,\n remoteSnapshot,\n } = args;\n if (!isBrowserEnvValue) {\n return {\n cssAssets: [],\n jsAssetsWithoutEntry: [],\n entryAssets: [],\n };\n }\n\n if (isRemoteInfoWithEntry(remote) && isPureRemoteEntry(remote)) {\n return {\n cssAssets: [],\n jsAssetsWithoutEntry: [],\n entryAssets: [\n {\n name: remote.name,\n url: remote.entry,\n moduleInfo: {\n name: remoteInfo.name,\n entry: remote.entry,\n type: remoteInfo.type || 'global',\n entryGlobalName: '',\n shareScope: '',\n },\n },\n ],\n };\n }\n\n assignRemoteInfo(remoteInfo, remoteSnapshot);\n\n const assets = generatePreloadAssets(\n origin,\n preloadOptions,\n remoteInfo,\n globalSnapshot,\n remoteSnapshot,\n );\n\n return assets;\n },\n };\n };\n"],"mappings":";;;;;;;;;AAsCA,SAAS,QAAQ,IAGf;CACA,MAAM,YAAY,GAAG,MAAM,IAAI;AAC/B,KAAI,UAAU,WAAW,EACvB,QAAO;EACL,MAAM,UAAU;EAChB,SAAS;EACV;UACQ,UAAU,WAAW,EAC9B,QAAO;EACL,MAAM,UAAU;EAChB,SAAS,UAAU;EACpB;KAED,QAAO;EACL,MAAM,UAAU;EAChB,SAAS,UAAU;EACpB;;AAKL,SAAS,mBACP,gBACA,YACA,UAKA,QACA,OAAgC,EAAE,EAClC,gBACM;CAEN,MAAM,EAAE,OAAO,kBAAkBA,kCAAm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