@module-federation/runtime-core 2.4.0 → 2.5.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 (69) hide show
  1. package/dist/core.cjs +8 -1
  2. package/dist/core.cjs.map +1 -1
  3. package/dist/core.d.ts +62 -6
  4. package/dist/core.js +8 -1
  5. package/dist/core.js.map +1 -1
  6. package/dist/global.cjs +1 -1
  7. package/dist/global.js +1 -1
  8. package/dist/module/index.cjs +158 -21
  9. package/dist/module/index.cjs.map +1 -1
  10. package/dist/module/index.d.ts +5 -4
  11. package/dist/module/index.js +160 -23
  12. package/dist/module/index.js.map +1 -1
  13. package/dist/plugins/snapshot/SnapshotHandler.cjs +40 -16
  14. package/dist/plugins/snapshot/SnapshotHandler.cjs.map +1 -1
  15. package/dist/plugins/snapshot/SnapshotHandler.d.ts +5 -2
  16. package/dist/plugins/snapshot/SnapshotHandler.js +42 -18
  17. package/dist/plugins/snapshot/SnapshotHandler.js.map +1 -1
  18. package/dist/plugins/snapshot/index.cjs +6 -2
  19. package/dist/plugins/snapshot/index.cjs.map +1 -1
  20. package/dist/plugins/snapshot/index.js +6 -2
  21. package/dist/plugins/snapshot/index.js.map +1 -1
  22. package/dist/remote/index.cjs +163 -25
  23. package/dist/remote/index.cjs.map +1 -1
  24. package/dist/remote/index.d.ts +30 -4
  25. package/dist/remote/index.js +164 -26
  26. package/dist/remote/index.js.map +1 -1
  27. package/dist/shared/index.cjs +210 -95
  28. package/dist/shared/index.cjs.map +1 -1
  29. package/dist/shared/index.d.ts +22 -0
  30. package/dist/shared/index.js +211 -96
  31. package/dist/shared/index.js.map +1 -1
  32. package/dist/type/index.d.ts +2 -2
  33. package/dist/type/preload.d.ts +25 -1
  34. package/dist/types.d.ts +2 -2
  35. package/dist/utils/hooks/asyncHook.cjs +4 -1
  36. package/dist/utils/hooks/asyncHook.cjs.map +1 -1
  37. package/dist/utils/hooks/asyncHook.js +4 -1
  38. package/dist/utils/hooks/asyncHook.js.map +1 -1
  39. package/dist/utils/hooks/asyncWaterfallHooks.cjs +10 -8
  40. package/dist/utils/hooks/asyncWaterfallHooks.cjs.map +1 -1
  41. package/dist/utils/hooks/asyncWaterfallHooks.d.ts +2 -2
  42. package/dist/utils/hooks/asyncWaterfallHooks.js +10 -8
  43. package/dist/utils/hooks/asyncWaterfallHooks.js.map +1 -1
  44. package/dist/utils/hooks/pluginSystem.d.ts +1 -1
  45. package/dist/utils/hooks/syncHook.cjs +2 -1
  46. package/dist/utils/hooks/syncHook.cjs.map +1 -1
  47. package/dist/utils/hooks/syncHook.js +2 -1
  48. package/dist/utils/hooks/syncHook.js.map +1 -1
  49. package/dist/utils/hooks/syncWaterfallHook.cjs +1 -0
  50. package/dist/utils/hooks/syncWaterfallHook.cjs.map +1 -1
  51. package/dist/utils/hooks/syncWaterfallHook.d.ts +1 -1
  52. package/dist/utils/hooks/syncWaterfallHook.js +1 -0
  53. package/dist/utils/hooks/syncWaterfallHook.js.map +1 -1
  54. package/dist/utils/index.js +1 -1
  55. package/dist/utils/load.cjs +42 -10
  56. package/dist/utils/load.cjs.map +1 -1
  57. package/dist/utils/load.d.ts +2 -0
  58. package/dist/utils/load.js +42 -10
  59. package/dist/utils/load.js.map +1 -1
  60. package/dist/utils/manifest.cjs +5 -0
  61. package/dist/utils/manifest.cjs.map +1 -1
  62. package/dist/utils/manifest.js +5 -1
  63. package/dist/utils/manifest.js.map +1 -1
  64. package/dist/utils/preload.cjs +126 -63
  65. package/dist/utils/preload.cjs.map +1 -1
  66. package/dist/utils/preload.d.ts +2 -2
  67. package/dist/utils/preload.js +126 -63
  68. package/dist/utils/preload.js.map +1 -1
  69. package/package.json +3 -3
@@ -4,6 +4,7 @@ import { ModuleInfo } from "@module-federation/sdk";
4
4
 
5
5
  //#region src/module/index.d.ts
6
6
  type ModuleOptions = ConstructorParameters<typeof Module$1>[0];
7
+ type RemoteModuleFactory = () => unknown | Promise<unknown>;
7
8
  declare class Module$1 {
8
9
  remoteInfo: RemoteInfo;
9
10
  inited: boolean;
@@ -19,13 +20,13 @@ declare class Module$1 {
19
20
  remoteInfo: RemoteInfo;
20
21
  host: ModuleFederation;
21
22
  });
22
- getEntry(): Promise<RemoteEntryExports>;
23
- init(id?: string, remoteSnapshot?: ModuleInfo, rawInitScope?: InitScope): Promise<RemoteEntryExports>;
23
+ getEntry(expose?: string): Promise<RemoteEntryExports>;
24
+ init(id?: string, remoteSnapshot?: ModuleInfo, rawInitScope?: InitScope, expose?: string): Promise<RemoteEntryExports>;
24
25
  get(id: string, expose: string, options?: {
25
26
  loadFactory?: boolean;
26
- }, remoteSnapshot?: ModuleInfo): Promise<any>;
27
+ }, remoteSnapshot?: ModuleInfo): Promise<unknown>;
27
28
  private wraperFactory;
28
29
  }
29
30
  //#endregion
30
- export { Module$1 as Module, ModuleOptions };
31
+ export { Module$1 as Module, ModuleOptions, RemoteModuleFactory };
31
32
  //# sourceMappingURL=index.d.ts.map
@@ -1,12 +1,18 @@
1
1
  import { assert, error } from "../utils/logger.js";
2
- import { getFMId, processModuleAlias } from "../utils/tool.js";
2
+ import { processModuleAlias } from "../utils/tool.js";
3
+ import { composeRemoteRequestId } from "../utils/manifest.js";
3
4
  import { getRemoteEntry } from "../utils/load.js";
4
5
  import { optionsToMFContext } from "../utils/context.js";
5
6
  import "../utils/index.js";
6
7
  import { safeToString } from "@module-federation/sdk";
7
- import { RUNTIME_002, runtimeDescMap } from "@module-federation/error-codes";
8
+ import { RUNTIME_002, RUNTIME_014, RUNTIME_015, runtimeDescMap } from "@module-federation/error-codes";
8
9
 
9
10
  //#region src/module/index.ts
11
+ function getAvailableExposeNames(remoteSnapshot) {
12
+ if (!remoteSnapshot || !("modules" in remoteSnapshot) || !Array.isArray(remoteSnapshot.modules)) return;
13
+ const exposes = remoteSnapshot.modules.map((module) => module.moduleName).filter(Boolean);
14
+ return exposes.length ? exposes.join(",") : void 0;
15
+ }
10
16
  function createRemoteEntryInitOptions(remoteInfo, hostShareScopeMap, rawInitScope) {
11
17
  const localShareScopeMap = hostShareScopeMap;
12
18
  const shareScopeKeys = Array.isArray(remoteInfo.shareScope) ? remoteInfo.shareScope : [remoteInfo.shareScope];
@@ -36,26 +42,68 @@ var Module$1 = class {
36
42
  this.remoteInfo = remoteInfo;
37
43
  this.host = host;
38
44
  }
39
- async getEntry() {
45
+ async getEntry(expose) {
40
46
  if (this.remoteEntryExports) return this.remoteEntryExports;
41
47
  const remoteEntryExports = await getRemoteEntry({
42
48
  origin: this.host,
43
49
  remoteInfo: this.remoteInfo,
44
- remoteEntryExports: this.remoteEntryExports
50
+ remoteEntryExports: this.remoteEntryExports,
51
+ resourceContext: {
52
+ initiator: "loadRemote",
53
+ id: composeRemoteRequestId(this.remoteInfo.name, expose),
54
+ resourceType: "remoteEntry"
55
+ }
45
56
  });
46
57
  assert(remoteEntryExports, `remoteEntryExports is undefined \n ${safeToString(this.remoteInfo)}`);
47
58
  this.remoteEntryExports = remoteEntryExports;
48
59
  return this.remoteEntryExports;
49
60
  }
50
- async init(id, remoteSnapshot, rawInitScope) {
51
- const remoteEntryExports = await this.getEntry();
52
- if (this.inited) return remoteEntryExports;
61
+ async init(id, remoteSnapshot, rawInitScope, expose) {
62
+ const remoteEntryExports = await this.getEntry(expose);
63
+ if (this.inited) {
64
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
65
+ id,
66
+ remoteInfo: this.remoteInfo,
67
+ remoteSnapshot,
68
+ remoteEntryExports,
69
+ cached: true,
70
+ origin: this.host
71
+ });
72
+ return remoteEntryExports;
73
+ }
53
74
  if (this.initPromise) {
54
- await this.initPromise;
75
+ try {
76
+ await this.initPromise;
77
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
78
+ id,
79
+ remoteInfo: this.remoteInfo,
80
+ remoteSnapshot,
81
+ remoteEntryExports,
82
+ cached: true,
83
+ origin: this.host
84
+ });
85
+ } catch (initError) {
86
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
87
+ id,
88
+ remoteInfo: this.remoteInfo,
89
+ remoteSnapshot,
90
+ remoteEntryExports,
91
+ error: initError,
92
+ cached: true,
93
+ origin: this.host
94
+ });
95
+ throw initError;
96
+ }
55
97
  return remoteEntryExports;
56
98
  }
57
99
  this.initing = true;
58
100
  this.initPromise = (async () => {
101
+ await this.host.loaderHook.lifecycle.beforeInitRemote.emit({
102
+ id,
103
+ remoteInfo: this.remoteInfo,
104
+ remoteSnapshot,
105
+ origin: this.host
106
+ });
59
107
  const { remoteEntryInitOptions, shareScope, initScope } = createRemoteEntryInitOptions(this.remoteInfo, this.host.shareScopeMap, rawInitScope);
60
108
  const initContainerOptions = await this.host.hooks.lifecycle.beforeInitContainer.emit({
61
109
  shareScope,
@@ -70,7 +118,17 @@ var Module$1 = class {
70
118
  remoteEntryUrl: this.remoteInfo.entry,
71
119
  remoteEntryKey: this.remoteInfo.entryGlobalName
72
120
  }, void 0, optionsToMFContext(this.host.options));
73
- await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
121
+ try {
122
+ await remoteEntryExports.init(initContainerOptions.shareScope, initContainerOptions.initScope, initContainerOptions.remoteEntryInitOptions);
123
+ } catch (initError) {
124
+ error(RUNTIME_015, runtimeDescMap, {
125
+ hostName: this.host.name,
126
+ remoteName: this.remoteInfo.name,
127
+ remoteEntryUrl: this.remoteInfo.entry,
128
+ remoteEntryKey: this.remoteInfo.entryGlobalName,
129
+ shareScope: this.remoteInfo.shareScope
130
+ }, `${initError}`, optionsToMFContext(this.host.options));
131
+ }
74
132
  await this.host.hooks.lifecycle.initContainer.emit({
75
133
  ...initContainerOptions,
76
134
  id,
@@ -81,6 +139,23 @@ var Module$1 = class {
81
139
  })();
82
140
  try {
83
141
  await this.initPromise;
142
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
143
+ id,
144
+ remoteInfo: this.remoteInfo,
145
+ remoteSnapshot,
146
+ remoteEntryExports,
147
+ origin: this.host
148
+ });
149
+ } catch (initError) {
150
+ await this.host.loaderHook.lifecycle.afterInitRemote.emit({
151
+ id,
152
+ remoteInfo: this.remoteInfo,
153
+ remoteSnapshot,
154
+ remoteEntryExports,
155
+ error: initError,
156
+ origin: this.host
157
+ });
158
+ throw initError;
84
159
  } finally {
85
160
  this.initing = false;
86
161
  this.initPromise = void 0;
@@ -89,20 +164,83 @@ var Module$1 = class {
89
164
  }
90
165
  async get(id, expose, options, remoteSnapshot) {
91
166
  const { loadFactory = true } = options || { loadFactory: true };
92
- const remoteEntryExports = await this.init(id, remoteSnapshot);
167
+ const remoteEntryExports = await this.init(id, remoteSnapshot, void 0, expose);
93
168
  this.lib = remoteEntryExports;
94
- let moduleFactory;
95
- moduleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
96
- remoteEntryExports,
169
+ await this.host.loaderHook.lifecycle.beforeGetExpose.emit({
170
+ id,
97
171
  expose,
98
- moduleInfo: this.remoteInfo
172
+ moduleInfo: this.remoteInfo,
173
+ remoteEntryExports,
174
+ origin: this.host
99
175
  });
100
- if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
101
- assert(moduleFactory, `${getFMId(this.remoteInfo)} remote don't export ${expose}.`);
176
+ let moduleFactory;
177
+ try {
178
+ const hookModuleFactory = await this.host.loaderHook.lifecycle.getModuleFactory.emit({
179
+ remoteEntryExports,
180
+ expose,
181
+ moduleInfo: this.remoteInfo
182
+ });
183
+ moduleFactory = typeof hookModuleFactory === "function" ? hookModuleFactory : void 0;
184
+ if (!moduleFactory) moduleFactory = await remoteEntryExports.get(expose);
185
+ if (!moduleFactory) error(RUNTIME_014, runtimeDescMap, {
186
+ hostName: this.host.name,
187
+ remoteName: this.remoteInfo.name,
188
+ remoteEntryUrl: this.remoteInfo.entry,
189
+ expose,
190
+ requestId: id,
191
+ availableExposes: getAvailableExposeNames(remoteSnapshot)
192
+ }, void 0, optionsToMFContext(this.host.options));
193
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
194
+ id,
195
+ expose,
196
+ moduleInfo: this.remoteInfo,
197
+ remoteEntryExports,
198
+ moduleFactory,
199
+ origin: this.host
200
+ });
201
+ } catch (getExposeError) {
202
+ await this.host.loaderHook.lifecycle.afterGetExpose.emit({
203
+ id,
204
+ expose,
205
+ moduleInfo: this.remoteInfo,
206
+ remoteEntryExports,
207
+ error: getExposeError,
208
+ origin: this.host
209
+ });
210
+ throw getExposeError;
211
+ }
102
212
  const symbolName = processModuleAlias(this.remoteInfo.name, expose);
103
213
  const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);
104
214
  if (!loadFactory) return wrapModuleFactory;
105
- return await wrapModuleFactory();
215
+ await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({
216
+ id,
217
+ expose,
218
+ moduleInfo: this.remoteInfo,
219
+ loadFactory,
220
+ origin: this.host
221
+ });
222
+ try {
223
+ const exposeContent = await wrapModuleFactory();
224
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
225
+ id,
226
+ expose,
227
+ moduleInfo: this.remoteInfo,
228
+ loadFactory,
229
+ exposeModule: exposeContent,
230
+ origin: this.host
231
+ });
232
+ return exposeContent;
233
+ } catch (executeFactoryError) {
234
+ await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({
235
+ id,
236
+ expose,
237
+ moduleInfo: this.remoteInfo,
238
+ loadFactory,
239
+ error: executeFactoryError,
240
+ origin: this.host
241
+ });
242
+ throw executeFactoryError;
243
+ }
106
244
  }
107
245
  wraperFactory(moduleFactory, id) {
108
246
  function defineModuleId(res, id) {
@@ -111,13 +249,12 @@ var Module$1 = class {
111
249
  enumerable: false
112
250
  });
113
251
  }
114
- if (moduleFactory instanceof Promise) return async () => {
115
- const res = await moduleFactory();
116
- defineModuleId(res, id);
117
- return res;
118
- };
119
- else return () => {
252
+ return () => {
120
253
  const res = moduleFactory();
254
+ if (res instanceof Promise) return res.then((asyncRes) => {
255
+ defineModuleId(asyncRes, id);
256
+ return asyncRes;
257
+ });
121
258
  defineModuleId(res, id);
122
259
  return res;
123
260
  };
@@ -1 +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,SAAg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K,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"}
1
+ {"version":3,"file":"index.js","names":["Module"],"sources":["../../src/module/index.ts"],"sourcesContent":["import {\n assert,\n error,\n processModuleAlias,\n optionsToMFContext,\n composeRemoteRequestId,\n} from '../utils';\nimport { safeToString, ModuleInfo } from '@module-federation/sdk';\nimport {\n RUNTIME_002,\n RUNTIME_014,\n RUNTIME_015,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { getRemoteEntry } from '../utils/load';\nimport { ModuleFederation } from '../core';\nimport {\n RemoteEntryExports,\n RemoteInfo,\n InitScope,\n ShareScopeMap,\n} from '../type';\n\nexport type ModuleOptions = ConstructorParameters<typeof Module>[0];\nexport type RemoteModuleFactory = () => unknown | Promise<unknown>;\n\nfunction getAvailableExposeNames(\n remoteSnapshot?: ModuleInfo,\n): string | undefined {\n if (\n !remoteSnapshot ||\n !('modules' in remoteSnapshot) ||\n !Array.isArray(remoteSnapshot.modules)\n ) {\n return undefined;\n }\n\n const exposes = remoteSnapshot.modules\n .map((module) => module.moduleName)\n .filter(Boolean);\n\n return exposes.length ? exposes.join(',') : undefined;\n}\n\nexport function createRemoteEntryInitOptions(\n remoteInfo: RemoteInfo,\n hostShareScopeMap: ShareScopeMap,\n rawInitScope?: InitScope,\n): Record<string, any> {\n const localShareScopeMap = hostShareScopeMap;\n\n const shareScopeKeys = Array.isArray(remoteInfo.shareScope)\n ? remoteInfo.shareScope\n : [remoteInfo.shareScope];\n\n if (!shareScopeKeys.length) {\n shareScopeKeys.push('default');\n }\n shareScopeKeys.forEach((shareScopeKey) => {\n if (!localShareScopeMap[shareScopeKey]) {\n localShareScopeMap[shareScopeKey] = {};\n }\n });\n\n const remoteEntryInitOptions = {\n version: remoteInfo.version || '',\n shareScopeKeys: Array.isArray(remoteInfo.shareScope)\n ? shareScopeKeys\n : remoteInfo.shareScope || 'default',\n };\n\n // Help to find host instance\n Object.defineProperty(remoteEntryInitOptions, 'shareScopeMap', {\n value: localShareScopeMap,\n // remoteEntryInitOptions will be traversed and assigned during container init, ,so this attribute is not allowed to be traversed\n enumerable: false,\n });\n\n // TODO: compate legacy init params, should use shareScopeMap if exist\n const shareScope = localShareScopeMap[shareScopeKeys[0]];\n const initScope: InitScope = rawInitScope ?? [];\n\n return {\n remoteEntryInitOptions,\n shareScope,\n initScope,\n };\n}\n\nclass Module {\n remoteInfo: RemoteInfo;\n inited = false;\n initing = false;\n initPromise?: Promise<void>;\n remoteEntryExports?: RemoteEntryExports;\n lib: RemoteEntryExports | undefined = undefined;\n host: ModuleFederation;\n\n constructor({\n remoteInfo,\n host,\n }: {\n remoteInfo: RemoteInfo;\n host: ModuleFederation;\n }) {\n this.remoteInfo = remoteInfo;\n this.host = host;\n }\n\n async getEntry(expose?: string): 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 resourceContext: {\n initiator: 'loadRemote',\n id: composeRemoteRequestId(this.remoteInfo.name, expose),\n resourceType: 'remoteEntry',\n },\n });\n\n assert(\n remoteEntryExports,\n `remoteEntryExports is undefined \\n ${safeToString(this.remoteInfo)}`,\n );\n\n this.remoteEntryExports = remoteEntryExports;\n return this.remoteEntryExports;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n\n async init(\n id?: string,\n remoteSnapshot?: ModuleInfo,\n rawInitScope?: InitScope,\n expose?: string,\n ) {\n // Get remoteEntry.js\n const remoteEntryExports = await this.getEntry(expose);\n\n if (this.inited) {\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n cached: true,\n origin: this.host,\n });\n return remoteEntryExports;\n }\n\n if (this.initPromise) {\n try {\n await this.initPromise;\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n cached: true,\n origin: this.host,\n });\n } catch (initError) {\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n error: initError,\n cached: true,\n origin: this.host,\n });\n throw initError;\n }\n return remoteEntryExports;\n }\n\n this.initing = true;\n this.initPromise = (async () => {\n await this.host.loaderHook.lifecycle.beforeInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n origin: this.host,\n });\n\n const { remoteEntryInitOptions, shareScope, initScope } =\n createRemoteEntryInitOptions(\n this.remoteInfo,\n this.host.shareScopeMap,\n rawInitScope,\n );\n\n const initContainerOptions =\n await this.host.hooks.lifecycle.beforeInitContainer.emit({\n shareScope,\n // @ts-ignore shareScopeMap will be set by Object.defineProperty\n remoteEntryInitOptions,\n initScope,\n remoteInfo: this.remoteInfo,\n origin: this.host,\n });\n\n if (typeof remoteEntryExports?.init === 'undefined') {\n error(\n RUNTIME_002,\n runtimeDescMap,\n {\n hostName: this.host.name,\n remoteName: this.remoteInfo.name,\n remoteEntryUrl: this.remoteInfo.entry,\n remoteEntryKey: this.remoteInfo.entryGlobalName,\n },\n undefined,\n optionsToMFContext(this.host.options),\n );\n }\n\n try {\n await remoteEntryExports.init(\n initContainerOptions.shareScope,\n initContainerOptions.initScope,\n initContainerOptions.remoteEntryInitOptions,\n );\n } catch (initError) {\n error(\n RUNTIME_015,\n runtimeDescMap,\n {\n hostName: this.host.name,\n remoteName: this.remoteInfo.name,\n remoteEntryUrl: this.remoteInfo.entry,\n remoteEntryKey: this.remoteInfo.entryGlobalName,\n shareScope: this.remoteInfo.shareScope,\n },\n `${initError}`,\n optionsToMFContext(this.host.options),\n );\n }\n\n await this.host.hooks.lifecycle.initContainer.emit({\n ...initContainerOptions,\n id,\n remoteSnapshot,\n remoteEntryExports,\n });\n this.inited = true;\n })();\n\n try {\n await this.initPromise;\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n origin: this.host,\n });\n } catch (initError) {\n await this.host.loaderHook.lifecycle.afterInitRemote.emit({\n id,\n remoteInfo: this.remoteInfo,\n remoteSnapshot,\n remoteEntryExports,\n error: initError,\n origin: this.host,\n });\n throw initError;\n } finally {\n this.initing = false;\n this.initPromise = undefined;\n }\n\n return remoteEntryExports;\n }\n\n // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types\n async get(\n id: string,\n expose: string,\n options?: { loadFactory?: boolean },\n remoteSnapshot?: ModuleInfo,\n ) {\n const { loadFactory = true } = options || { loadFactory: true };\n\n const remoteEntryExports = await this.init(\n id,\n remoteSnapshot,\n undefined,\n expose,\n );\n this.lib = remoteEntryExports;\n\n await this.host.loaderHook.lifecycle.beforeGetExpose.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n remoteEntryExports,\n origin: this.host,\n });\n\n let moduleFactory: RemoteModuleFactory | undefined;\n try {\n const hookModuleFactory =\n await this.host.loaderHook.lifecycle.getModuleFactory.emit({\n remoteEntryExports,\n expose,\n moduleInfo: this.remoteInfo,\n });\n moduleFactory =\n typeof hookModuleFactory === 'function' ? hookModuleFactory : undefined;\n\n // get exposeGetter\n if (!moduleFactory) {\n moduleFactory = await remoteEntryExports.get(expose);\n }\n\n if (!moduleFactory) {\n error(\n RUNTIME_014,\n runtimeDescMap,\n {\n hostName: this.host.name,\n remoteName: this.remoteInfo.name,\n remoteEntryUrl: this.remoteInfo.entry,\n expose,\n requestId: id,\n availableExposes: getAvailableExposeNames(remoteSnapshot),\n },\n undefined,\n optionsToMFContext(this.host.options),\n );\n }\n\n await this.host.loaderHook.lifecycle.afterGetExpose.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n remoteEntryExports,\n moduleFactory,\n origin: this.host,\n });\n } catch (getExposeError) {\n await this.host.loaderHook.lifecycle.afterGetExpose.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n remoteEntryExports,\n error: getExposeError,\n origin: this.host,\n });\n throw getExposeError;\n }\n\n // keep symbol for module name always one format\n const symbolName = processModuleAlias(this.remoteInfo.name, expose);\n const wrapModuleFactory = this.wraperFactory(moduleFactory, symbolName);\n\n if (!loadFactory) {\n return wrapModuleFactory;\n }\n\n await this.host.loaderHook.lifecycle.beforeExecuteFactory.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n loadFactory,\n origin: this.host,\n });\n\n try {\n const exposeContent = await wrapModuleFactory();\n\n await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n loadFactory,\n exposeModule: exposeContent,\n origin: this.host,\n });\n\n return exposeContent;\n } catch (executeFactoryError) {\n await this.host.loaderHook.lifecycle.afterExecuteFactory.emit({\n id,\n expose,\n moduleInfo: this.remoteInfo,\n loadFactory,\n error: executeFactoryError,\n origin: this.host,\n });\n throw executeFactoryError;\n }\n }\n\n private wraperFactory(moduleFactory: RemoteModuleFactory, id: string) {\n function defineModuleId(res: unknown, id: string) {\n if (\n res &&\n typeof res === 'object' &&\n Object.isExtensible(res) &&\n !Object.getOwnPropertyDescriptor(res, Symbol.for('mf_module_id'))\n ) {\n Object.defineProperty(res, Symbol.for('mf_module_id'), {\n value: id,\n enumerable: false,\n });\n }\n }\n\n return () => {\n const res = moduleFactory();\n\n if (res instanceof Promise) {\n return res.then((asyncRes) => {\n // This parameter is used for bridge debugging\n defineModuleId(asyncRes, id);\n return asyncRes;\n });\n }\n\n // This parameter is used for bridge debugging\n defineModuleId(res, id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Ae,KAAK,OAAO,IAAI,eAAe,EAAE;IACrD,OAAO;IACP,YAAY;IACb,CAAC;;AAIN,eAAa;GACX,MAAM,MAAM,eAAe;AAE3B,OAAI,eAAe,QACjB,QAAO,IAAI,MAAM,aAAa;AAE5B,mBAAe,UAAU,GAAG;AAC5B,WAAO;KACP;AAIJ,kBAAe,KAAK,GAAG;AACvB,UAAO"}
@@ -49,11 +49,12 @@ var SnapshotHandler = class {
49
49
  this.HostInstance = HostInstance;
50
50
  this.loaderHook = HostInstance.loaderHook;
51
51
  }
52
- async loadRemoteSnapshotInfo({ moduleInfo, id, expose }) {
52
+ async loadRemoteSnapshotInfo({ moduleInfo, id, initiator = "loadRemote" }) {
53
53
  const { options } = this.HostInstance;
54
54
  await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({
55
55
  options,
56
- moduleInfo
56
+ moduleInfo,
57
+ origin: this.HostInstance
57
58
  });
58
59
  let hostSnapshot = require_global.getGlobalSnapshotInfoByModuleInfo({
59
60
  name: this.HostInstance.options.name,
@@ -85,7 +86,10 @@ var SnapshotHandler = class {
85
86
  let gSnapshot;
86
87
  if (globalRemoteSnapshot) if ((0, _module_federation_sdk.isManifestProvider)(globalRemoteSnapshot)) {
87
88
  const remoteEntry = _module_federation_sdk.isBrowserEnvValue ? globalRemoteSnapshot.remoteEntry : globalRemoteSnapshot.ssrRemoteEntry || globalRemoteSnapshot.remoteEntry || "";
88
- const moduleSnapshot = await this.getManifestJson(remoteEntry, moduleInfo, {});
89
+ const moduleSnapshot = await this.loadManifestSnapshot(remoteEntry, moduleInfo, {}, {
90
+ initiator,
91
+ id: id || moduleInfo.name
92
+ });
89
93
  const globalSnapshotRes = require_global.setGlobalSnapshotInfoByModuleInfo({
90
94
  ...moduleInfo,
91
95
  entry: remoteEntry
@@ -103,15 +107,12 @@ var SnapshotHandler = class {
103
107
  gSnapshot = globalSnapshotRes;
104
108
  }
105
109
  else if (require_tool.isRemoteInfoWithEntry(moduleInfo)) {
106
- const moduleSnapshot = await this.getManifestJson(moduleInfo.entry, moduleInfo, {});
107
- const globalSnapshotRes = require_global.setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
108
- const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
109
- options: this.HostInstance.options,
110
- moduleInfo,
111
- remoteSnapshot: moduleSnapshot,
112
- from: "global"
110
+ const moduleSnapshot = await this.loadManifestSnapshot(moduleInfo.entry, moduleInfo, {}, {
111
+ initiator,
112
+ id: id || moduleInfo.name
113
113
  });
114
- mSnapshot = remoteSnapshotRes;
114
+ const globalSnapshotRes = require_global.setGlobalSnapshotInfoByModuleInfo(moduleInfo, moduleSnapshot);
115
+ mSnapshot = moduleSnapshot;
115
116
  gSnapshot = globalSnapshotRes;
116
117
  } else require_logger.error(_module_federation_error_codes.RUNTIME_007, _module_federation_error_codes.runtimeDescMap, {
117
118
  remoteName: moduleInfo.name,
@@ -134,12 +135,17 @@ var SnapshotHandler = class {
134
135
  getGlobalRemoteInfo(moduleInfo) {
135
136
  return getGlobalRemoteInfo(moduleInfo, this.HostInstance);
136
137
  }
137
- async getManifestJson(manifestUrl, moduleInfo, extraOptions) {
138
+ async getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
138
139
  const getManifest = async () => {
140
+ const remoteInfo = require_load.getRemoteInfo(moduleInfo);
139
141
  let manifestJson = this.manifestCache.get(manifestUrl);
140
142
  if (manifestJson) return manifestJson;
141
143
  try {
142
- let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {}, require_load.getRemoteInfo(moduleInfo));
144
+ let res = await this.loaderHook.lifecycle.fetch.emit(manifestUrl, {}, remoteInfo, resourceOptions ? {
145
+ ...resourceOptions,
146
+ url: manifestUrl,
147
+ resourceType: "manifest"
148
+ } : void 0);
143
149
  if (!res || !(res instanceof Response)) res = await fetch(manifestUrl, {});
144
150
  manifestJson = await res.json();
145
151
  } catch (err) {
@@ -148,6 +154,7 @@ var SnapshotHandler = class {
148
154
  error: err,
149
155
  from: "runtime",
150
156
  lifecycle: "afterResolve",
157
+ remote: remoteInfo,
151
158
  origin: this.HostInstance
152
159
  });
153
160
  if (!manifestJson) {
@@ -159,16 +166,33 @@ var SnapshotHandler = class {
159
166
  }, `${err}`, require_context.optionsToMFContext(this.HostInstance.options));
160
167
  }
161
168
  }
162
- require_logger.assert(manifestJson.metaData && manifestJson.exposes && manifestJson.shared, `"${manifestUrl}" is not a valid federation manifest for remote "${moduleInfo.name}". Missing required fields: ${[
169
+ const missingRequiredFields = [
163
170
  !manifestJson.metaData && "metaData",
164
171
  !manifestJson.exposes && "exposes",
165
172
  !manifestJson.shared && "shared"
166
- ].filter(Boolean).join(", ")}.`);
173
+ ].filter(Boolean);
174
+ if (missingRequiredFields.length > 0) await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit({
175
+ id: manifestUrl,
176
+ error: /* @__PURE__ */ new Error(`"${manifestUrl}" is not a valid federation manifest for remote "${moduleInfo.name}". Missing required fields: ${missingRequiredFields.join(", ")}.`),
177
+ from: "runtime",
178
+ lifecycle: "afterResolve",
179
+ remote: remoteInfo,
180
+ origin: this.HostInstance
181
+ });
182
+ if (missingRequiredFields.length > 0) require_logger.error(_module_federation_error_codes.RUNTIME_013, _module_federation_error_codes.runtimeDescMap, {
183
+ manifestUrl,
184
+ moduleName: moduleInfo.name,
185
+ hostName: this.HostInstance.options.name,
186
+ missingFields: missingRequiredFields.join(",")
187
+ }, void 0, require_context.optionsToMFContext(this.HostInstance.options));
167
188
  this.manifestCache.set(manifestUrl, manifestJson);
168
189
  return manifestJson;
169
190
  };
191
+ return getManifest();
192
+ }
193
+ async loadManifestSnapshot(manifestUrl, moduleInfo, extraOptions, resourceOptions) {
170
194
  const asyncLoadProcess = async () => {
171
- const manifestJson = await getManifest();
195
+ const manifestJson = await this.getManifestJson(manifestUrl, moduleInfo, extraOptions, resourceOptions);
172
196
  const remoteSnapshot = (0, _module_federation_sdk.generateSnapshotFromManifest)(manifestJson, { version: manifestUrl });
173
197
  const { remoteSnapshot: remoteSnapshotRes } = await this.hooks.lifecycle.loadRemoteSnapshot.emit({
174
198
  options: this.HostInstance.options,
@@ -1 +1 @@
1
- {"version":3,"file":"SnapshotHandler.cjs","names":["getGlobalSnapshotInfoByModuleInfo","getInfoWithoutType","getGlobalSnapshot","PluginSystem","AsyncHook","AsyncWaterfallHook","Global","isBrowserEnvValue","setGlobalSnapshotInfoByModuleInfo","isRemoteInfoWithEntry","RUNTIME_007","runtimeDescMap","optionsToMFContext","getRemoteInfo","RUNTIME_003"],"sources":["../../../src/plugins/snapshot/SnapshotHandler.ts"],"sourcesContent":["import {\n GlobalModuleInfo,\n Manifest,\n ModuleInfo,\n generateSnapshotFromManifest,\n isManifestProvider,\n isBrowserEnvValue,\n} from '@module-federation/sdk';\nimport {\n RUNTIME_003,\n RUNTIME_007,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Options, Remote } from '../../type';\nimport {\n isRemoteInfoWithEntry,\n error,\n optionsToMFContext,\n getRemoteInfo,\n} from '../../utils';\nimport {\n getGlobalSnapshot,\n setGlobalSnapshotInfoByModuleInfo,\n Global,\n addGlobalSnapshot,\n getGlobalSnapshotInfoByModuleInfo,\n getInfoWithoutType,\n} from '../../global';\nimport { PluginSystem, AsyncHook, AsyncWaterfallHook } from '../../utils/hooks';\nimport { ModuleFederation } from '../../core';\nimport { assert } from '../../utils/logger';\n\nexport function getGlobalRemoteInfo(\n moduleInfo: Remote,\n origin: ModuleFederation,\n): {\n hostGlobalSnapshot: ModuleInfo | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot: GlobalModuleInfo[string] | undefined;\n} {\n const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({\n name: origin.name,\n version: origin.options.version,\n });\n\n // get remote detail info from global\n const globalRemoteInfo =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;\n\n if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {\n return {\n hostGlobalSnapshot,\n globalSnapshot: getGlobalSnapshot(),\n remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({\n name: moduleInfo.name,\n version: globalRemoteInfo.matchedVersion,\n }),\n };\n }\n\n return {\n hostGlobalSnapshot: undefined,\n globalSnapshot: getGlobalSnapshot(),\n remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({\n name: moduleInfo.name,\n version: 'version' in moduleInfo ? moduleInfo.version : undefined,\n }),\n };\n}\n\nexport class SnapshotHandler {\n loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null = null;\n HostInstance: ModuleFederation;\n manifestCache: Map<string, Manifest> = new Map();\n hooks = new PluginSystem({\n beforeLoadRemoteSnapshot: new AsyncHook<\n [\n {\n options: Options;\n moduleInfo: Remote;\n },\n ],\n void\n >('beforeLoadRemoteSnapshot'),\n loadSnapshot: new AsyncWaterfallHook<{\n options: Options;\n moduleInfo: Remote;\n hostGlobalSnapshot: GlobalModuleInfo[string] | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot?: GlobalModuleInfo[string] | undefined;\n }>('loadGlobalSnapshot'),\n loadRemoteSnapshot: new AsyncWaterfallHook<{\n options: Options;\n moduleInfo: Remote;\n manifestJson?: Manifest;\n manifestUrl?: string;\n remoteSnapshot: ModuleInfo;\n from: 'global' | 'manifest';\n }>('loadRemoteSnapshot'),\n afterLoadSnapshot: new AsyncWaterfallHook<{\n id?: string;\n host: ModuleFederation;\n options: Options;\n moduleInfo: Remote;\n remoteSnapshot: ModuleInfo;\n }>('afterLoadSnapshot'),\n });\n loaderHook: ModuleFederation['loaderHook'];\n manifestLoading: Record<string, Promise<ModuleInfo>> =\n Global.__FEDERATION__.__MANIFEST_LOADING__;\n\n constructor(HostInstance: ModuleFederation) {\n this.HostInstance = HostInstance;\n this.loaderHook = HostInstance.loaderHook;\n }\n\n // eslint-disable-next-line max-lines-per-function\n async loadRemoteSnapshotInfo({\n moduleInfo,\n id,\n expose,\n }: {\n moduleInfo: Remote;\n id?: string;\n expose?: string;\n }):\n | Promise<{\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n }>\n | never {\n const { options } = this.HostInstance;\n\n await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({\n options,\n moduleInfo,\n });\n\n let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({\n name: this.HostInstance.options.name,\n version: this.HostInstance.options.version,\n });\n\n if (!hostSnapshot) {\n hostSnapshot = {\n version: this.HostInstance.options.version || '',\n remoteEntry: '',\n remotesInfo: {},\n };\n addGlobalSnapshot({\n [this.HostInstance.options.name]: hostSnapshot,\n });\n }\n\n // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.\n // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.\n if (\n hostSnapshot &&\n 'remotesInfo' in hostSnapshot &&\n !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value\n ) {\n if ('version' in moduleInfo || 'entry' in moduleInfo) {\n hostSnapshot.remotesInfo = {\n ...hostSnapshot?.remotesInfo,\n [moduleInfo.name]: {\n matchedVersion:\n 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,\n },\n };\n }\n }\n\n const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } =\n this.getGlobalRemoteInfo(moduleInfo);\n const {\n remoteSnapshot: globalRemoteSnapshot,\n globalSnapshot: globalSnapshotRes,\n } = await this.hooks.lifecycle.loadSnapshot.emit({\n options,\n moduleInfo,\n hostGlobalSnapshot,\n remoteSnapshot,\n globalSnapshot,\n });\n\n let mSnapshot;\n let gSnapshot;\n // global snapshot includes manifest or module info includes manifest\n if (globalRemoteSnapshot) {\n if (isManifestProvider(globalRemoteSnapshot)) {\n const remoteEntry = isBrowserEnvValue\n ? globalRemoteSnapshot.remoteEntry\n : globalRemoteSnapshot.ssrRemoteEntry ||\n globalRemoteSnapshot.remoteEntry ||\n '';\n const moduleSnapshot = await this.getManifestJson(\n remoteEntry,\n moduleInfo,\n {},\n );\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(\n {\n ...moduleInfo,\n // The global remote may be overridden\n // Therefore, set the snapshot key to the global address of the actual request\n entry: remoteEntry,\n },\n moduleSnapshot,\n );\n mSnapshot = moduleSnapshot;\n gSnapshot = globalSnapshotRes;\n } else {\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n remoteSnapshot: globalRemoteSnapshot,\n from: 'global',\n });\n mSnapshot = remoteSnapshotRes;\n gSnapshot = globalSnapshotRes;\n }\n } else {\n if (isRemoteInfoWithEntry(moduleInfo)) {\n // get from manifest.json and merge remote info from remote server\n const moduleSnapshot = await this.getManifestJson(\n moduleInfo.entry,\n moduleInfo,\n {},\n );\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(\n moduleInfo,\n moduleSnapshot,\n );\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n remoteSnapshot: moduleSnapshot,\n from: 'global',\n });\n\n mSnapshot = remoteSnapshotRes;\n gSnapshot = globalSnapshotRes;\n } else {\n error(\n RUNTIME_007,\n runtimeDescMap,\n {\n remoteName: moduleInfo.name,\n remoteVersion: moduleInfo.version,\n hostName: this.HostInstance.options.name,\n globalSnapshot: JSON.stringify(globalSnapshotRes),\n },\n undefined,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n }\n\n await this.hooks.lifecycle.afterLoadSnapshot.emit({\n id,\n host: this.HostInstance,\n options,\n moduleInfo,\n remoteSnapshot: mSnapshot,\n });\n\n return {\n remoteSnapshot: mSnapshot,\n globalSnapshot: gSnapshot,\n };\n }\n\n getGlobalRemoteInfo(moduleInfo: Remote): {\n hostGlobalSnapshot: ModuleInfo | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot: GlobalModuleInfo[string] | undefined;\n } {\n return getGlobalRemoteInfo(moduleInfo, this.HostInstance);\n }\n\n private async getManifestJson(\n manifestUrl: string,\n moduleInfo: Remote,\n extraOptions: Record<string, any>,\n ): Promise<ModuleInfo> {\n const getManifest = async (): Promise<Manifest> => {\n let manifestJson: Manifest | undefined =\n this.manifestCache.get(manifestUrl);\n if (manifestJson) {\n return manifestJson;\n }\n try {\n let res = await this.loaderHook.lifecycle.fetch.emit(\n manifestUrl,\n {},\n getRemoteInfo(moduleInfo),\n );\n if (!res || !(res instanceof Response)) {\n res = await fetch(manifestUrl, {});\n }\n manifestJson = (await res.json()) as Manifest;\n } catch (err) {\n manifestJson =\n (await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit(\n {\n id: manifestUrl,\n error: err,\n from: 'runtime',\n lifecycle: 'afterResolve',\n origin: this.HostInstance,\n },\n )) as Manifest | undefined;\n\n if (!manifestJson) {\n delete this.manifestLoading[manifestUrl];\n error(\n RUNTIME_003,\n runtimeDescMap,\n {\n manifestUrl,\n moduleName: moduleInfo.name,\n hostName: this.HostInstance.options.name,\n },\n `${err}`,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n }\n\n assert(\n manifestJson.metaData && manifestJson.exposes && manifestJson.shared,\n `\"${manifestUrl}\" is not a valid federation manifest for remote \"${moduleInfo.name}\". Missing required fields: ${[!manifestJson.metaData && 'metaData', !manifestJson.exposes && 'exposes', !manifestJson.shared && 'shared'].filter(Boolean).join(', ')}.`,\n );\n this.manifestCache.set(manifestUrl, manifestJson);\n return manifestJson;\n };\n\n const asyncLoadProcess = async () => {\n const manifestJson = await getManifest();\n const remoteSnapshot = generateSnapshotFromManifest(manifestJson, {\n version: manifestUrl,\n });\n\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n manifestJson,\n remoteSnapshot,\n manifestUrl,\n from: 'manifest',\n });\n return remoteSnapshotRes;\n };\n\n if (!this.manifestLoading[manifestUrl]) {\n this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);\n }\n return this.manifestLoading[manifestUrl];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,oBACd,YACA,QAKA;CACA,MAAM,qBAAqBA,iDAAkC;EAC3D,MAAM,OAAO;EACb,SAAS,OAAO,QAAQ;EACzB,CAAC;CAGF,MAAM,mBACJ,sBACA,iBAAiB,sBACjB,mBAAmB,eACnBC,kCAAmB,mBAAmB,aAAa,WAAW,KAAK,CAAC;AAEtE,KAAI,oBAAoB,iBAAiB,eACvC,QAAO;EACL;EACA,gBAAgBC,kCAAmB;EACnC,gBAAgBF,iDAAkC;GAChD,MAAM,WAAW;GACjB,SAAS,iBAAiB;GAC3B,CAAC;EACH;AAGH,QAAO;EACL,oBAAoB;EACpB,gBAAgBE,kCAAmB;EACnC,gBAAgBF,iDAAkC;GAChD,MAAM,WAAW;GACjB,SAAS,aAAa,aAAa,WAAW,UAAU;GACzD,CAAC;EACH;;AAGH,IAAa,kBAAb,MAA6B;CAyC3B,YAAY,cAAgC;6BAxCmB;uCAExB,IAAI,KAAK;eACxC,IAAIG,kCAAa;GACvB,0BAA0B,IAAIC,4BAQ5B,2BAA2B;GAC7B,cAAc,IAAIC,+CAMf,qBAAqB;GACxB,oBAAoB,IAAIA,+CAOrB,qBAAqB;GACxB,mBAAmB,IAAIA,+CAMpB,oBAAoB;GACxB,CAAC;yBAGAC,sBAAO,eAAe;AAGtB,OAAK,eAAe;AACpB,OAAK,aAAa,aAAa;;CAIjC,MAAM,uBAAuB,EAC3B,YACA,IACA,UA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,4CACAH,+CACA;MACE;MACA,YAAY,WAAW;MACvB,UAAU,KAAK,aAAa,QAAQ;MACrC,EACD,GAAG,OACHC,mCAAmB,KAAK,aAAa,QAAQ,CAC9C;;;AAIL,yBACE,aAAa,YAAY,aAAa,WAAW,aAAa,QAC9D,IAAI,YAAY,mDAAmD,WAAW,KAAK,8BAA8B;IAAC,CAAC,aAAa,YAAY;IAAY,CAAC,aAAa,WAAW;IAAW,CAAC,aAAa,UAAU;IAAS,CAAC,OAAO,QAAQ,CAAC,KAAK,KAAK,CAAC,GAC1P;AACD,QAAK,cAAc,IAAI,aAAa,aAAa;AACjD,UAAO;;EAGT,MAAM,mBAAmB,YAAY;GACnC,MAAM,eAAe,MAAM,aAAa;GACxC,MAAM,0EAA8C,cAAc,EAChE,SAAS,aACV,CAAC;GAEF,MAAM,EAAE,gBAAgB,sBACtB,MAAM,KAAK,MAAM,UAAU,mBAAmB,KAAK;IACjD,SAAS,KAAK,aAAa;IAC3B;IACA;IACA;IACA;IACA,MAAM;IACP,CAAC;AACJ,UAAO;;AAGT,MAAI,CAAC,KAAK,gBAAgB,aACxB,MAAK,gBAAgB,eAAe,kBAAkB,CAAC,MAAM,QAAQ,IAAI;AAE3E,SAAO,KAAK,gBAAgB"}
1
+ {"version":3,"file":"SnapshotHandler.cjs","names":["getGlobalSnapshotInfoByModuleInfo","getInfoWithoutType","getGlobalSnapshot","PluginSystem","AsyncHook","AsyncWaterfallHook","Global","isBrowserEnvValue","setGlobalSnapshotInfoByModuleInfo","isRemoteInfoWithEntry","RUNTIME_007","runtimeDescMap","optionsToMFContext","getRemoteInfo","RUNTIME_003","RUNTIME_013"],"sources":["../../../src/plugins/snapshot/SnapshotHandler.ts"],"sourcesContent":["import {\n GlobalModuleInfo,\n Manifest,\n ModuleInfo,\n generateSnapshotFromManifest,\n isManifestProvider,\n isBrowserEnvValue,\n} from '@module-federation/sdk';\nimport {\n RUNTIME_003,\n RUNTIME_007,\n RUNTIME_013,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Options, Remote, ResourceLoadInitiator } from '../../type';\nimport {\n isRemoteInfoWithEntry,\n error,\n optionsToMFContext,\n getRemoteInfo,\n} from '../../utils';\nimport {\n getGlobalSnapshot,\n setGlobalSnapshotInfoByModuleInfo,\n Global,\n addGlobalSnapshot,\n getGlobalSnapshotInfoByModuleInfo,\n getInfoWithoutType,\n} from '../../global';\nimport { PluginSystem, AsyncHook, AsyncWaterfallHook } from '../../utils/hooks';\nimport { ModuleFederation } from '../../core';\n\nexport function getGlobalRemoteInfo(\n moduleInfo: Remote,\n origin: ModuleFederation,\n): {\n hostGlobalSnapshot: ModuleInfo | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot: GlobalModuleInfo[string] | undefined;\n} {\n const hostGlobalSnapshot = getGlobalSnapshotInfoByModuleInfo({\n name: origin.name,\n version: origin.options.version,\n });\n\n // get remote detail info from global\n const globalRemoteInfo =\n hostGlobalSnapshot &&\n 'remotesInfo' in hostGlobalSnapshot &&\n hostGlobalSnapshot.remotesInfo &&\n getInfoWithoutType(hostGlobalSnapshot.remotesInfo, moduleInfo.name).value;\n\n if (globalRemoteInfo && globalRemoteInfo.matchedVersion) {\n return {\n hostGlobalSnapshot,\n globalSnapshot: getGlobalSnapshot(),\n remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({\n name: moduleInfo.name,\n version: globalRemoteInfo.matchedVersion,\n }),\n };\n }\n\n return {\n hostGlobalSnapshot: undefined,\n globalSnapshot: getGlobalSnapshot(),\n remoteSnapshot: getGlobalSnapshotInfoByModuleInfo({\n name: moduleInfo.name,\n version: 'version' in moduleInfo ? moduleInfo.version : undefined,\n }),\n };\n}\n\nexport class SnapshotHandler {\n loadingHostSnapshot: Promise<GlobalModuleInfo | void> | null = null;\n HostInstance: ModuleFederation;\n manifestCache: Map<string, Manifest> = new Map();\n hooks = new PluginSystem({\n beforeLoadRemoteSnapshot: new AsyncHook<\n [\n {\n options: Options;\n moduleInfo: Remote;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeLoadRemoteSnapshot'),\n loadSnapshot: new AsyncWaterfallHook<{\n options: Options;\n moduleInfo: Remote;\n hostGlobalSnapshot: GlobalModuleInfo[string] | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot?: GlobalModuleInfo[string] | undefined;\n }>('loadGlobalSnapshot'),\n loadRemoteSnapshot: new AsyncWaterfallHook<{\n options: Options;\n moduleInfo: Remote;\n manifestJson?: Manifest;\n manifestUrl?: string;\n remoteSnapshot: ModuleInfo;\n from: 'global' | 'manifest';\n }>('loadRemoteSnapshot'),\n afterLoadSnapshot: new AsyncWaterfallHook<{\n id?: string;\n host: ModuleFederation;\n options: Options;\n moduleInfo: Remote;\n remoteSnapshot: ModuleInfo;\n }>('afterLoadSnapshot'),\n });\n loaderHook: ModuleFederation['loaderHook'];\n manifestLoading: Record<string, Promise<ModuleInfo>> =\n Global.__FEDERATION__.__MANIFEST_LOADING__;\n\n constructor(HostInstance: ModuleFederation) {\n this.HostInstance = HostInstance;\n this.loaderHook = HostInstance.loaderHook;\n }\n\n // eslint-disable-next-line max-lines-per-function\n async loadRemoteSnapshotInfo({\n moduleInfo,\n id,\n initiator = 'loadRemote',\n }: {\n moduleInfo: Remote;\n id?: string;\n initiator?: ResourceLoadInitiator;\n }):\n | Promise<{\n remoteSnapshot: ModuleInfo;\n globalSnapshot: GlobalModuleInfo;\n }>\n | never {\n const { options } = this.HostInstance;\n\n await this.hooks.lifecycle.beforeLoadRemoteSnapshot.emit({\n options,\n moduleInfo,\n origin: this.HostInstance,\n });\n\n let hostSnapshot = getGlobalSnapshotInfoByModuleInfo({\n name: this.HostInstance.options.name,\n version: this.HostInstance.options.version,\n });\n\n if (!hostSnapshot) {\n hostSnapshot = {\n version: this.HostInstance.options.version || '',\n remoteEntry: '',\n remotesInfo: {},\n };\n addGlobalSnapshot({\n [this.HostInstance.options.name]: hostSnapshot,\n });\n }\n\n // In dynamic loadRemote scenarios, incomplete remotesInfo delivery may occur. In such cases, the remotesInfo in the host needs to be completed in the snapshot at runtime.\n // This ensures the snapshot's integrity and helps the chrome plugin correctly identify all producer modules, ensuring that proxyable producer modules will not be missing.\n if (\n hostSnapshot &&\n 'remotesInfo' in hostSnapshot &&\n !getInfoWithoutType(hostSnapshot.remotesInfo, moduleInfo.name).value\n ) {\n if ('version' in moduleInfo || 'entry' in moduleInfo) {\n hostSnapshot.remotesInfo = {\n ...hostSnapshot?.remotesInfo,\n [moduleInfo.name]: {\n matchedVersion:\n 'version' in moduleInfo ? moduleInfo.version : moduleInfo.entry,\n },\n };\n }\n }\n\n const { hostGlobalSnapshot, remoteSnapshot, globalSnapshot } =\n this.getGlobalRemoteInfo(moduleInfo);\n const {\n remoteSnapshot: globalRemoteSnapshot,\n globalSnapshot: globalSnapshotRes,\n } = await this.hooks.lifecycle.loadSnapshot.emit({\n options,\n moduleInfo,\n hostGlobalSnapshot,\n remoteSnapshot,\n globalSnapshot,\n });\n\n let mSnapshot;\n let gSnapshot;\n // global snapshot includes manifest or module info includes manifest\n if (globalRemoteSnapshot) {\n if (isManifestProvider(globalRemoteSnapshot)) {\n const remoteEntry = isBrowserEnvValue\n ? globalRemoteSnapshot.remoteEntry\n : globalRemoteSnapshot.ssrRemoteEntry ||\n globalRemoteSnapshot.remoteEntry ||\n '';\n const moduleSnapshot = await this.loadManifestSnapshot(\n remoteEntry,\n moduleInfo,\n {},\n {\n initiator,\n id: id || moduleInfo.name,\n },\n );\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(\n {\n ...moduleInfo,\n // The global remote may be overridden\n // Therefore, set the snapshot key to the global address of the actual request\n entry: remoteEntry,\n },\n moduleSnapshot,\n );\n mSnapshot = moduleSnapshot;\n gSnapshot = globalSnapshotRes;\n } else {\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n remoteSnapshot: globalRemoteSnapshot,\n from: 'global',\n });\n mSnapshot = remoteSnapshotRes;\n gSnapshot = globalSnapshotRes;\n }\n } else {\n if (isRemoteInfoWithEntry(moduleInfo)) {\n // get from manifest.json and merge remote info from remote server\n const moduleSnapshot = await this.loadManifestSnapshot(\n moduleInfo.entry,\n moduleInfo,\n {},\n {\n initiator,\n id: id || moduleInfo.name,\n },\n );\n // eslint-disable-next-line @typescript-eslint/no-shadow\n const globalSnapshotRes = setGlobalSnapshotInfoByModuleInfo(\n moduleInfo,\n moduleSnapshot,\n );\n mSnapshot = moduleSnapshot;\n gSnapshot = globalSnapshotRes;\n } else {\n error(\n RUNTIME_007,\n runtimeDescMap,\n {\n remoteName: moduleInfo.name,\n remoteVersion: moduleInfo.version,\n hostName: this.HostInstance.options.name,\n globalSnapshot: JSON.stringify(globalSnapshotRes),\n },\n undefined,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n }\n\n await this.hooks.lifecycle.afterLoadSnapshot.emit({\n id,\n host: this.HostInstance,\n options,\n moduleInfo,\n remoteSnapshot: mSnapshot,\n });\n\n return {\n remoteSnapshot: mSnapshot,\n globalSnapshot: gSnapshot,\n };\n }\n\n getGlobalRemoteInfo(moduleInfo: Remote): {\n hostGlobalSnapshot: ModuleInfo | undefined;\n globalSnapshot: ReturnType<typeof getGlobalSnapshot>;\n remoteSnapshot: GlobalModuleInfo[string] | undefined;\n } {\n return getGlobalRemoteInfo(moduleInfo, this.HostInstance);\n }\n\n private async getManifestJson(\n manifestUrl: string,\n moduleInfo: Remote,\n extraOptions: Record<string, any>,\n resourceOptions?: {\n initiator: ResourceLoadInitiator;\n id: string;\n },\n ): Promise<Manifest> {\n const getManifest = async (): Promise<Manifest> => {\n const remoteInfo = getRemoteInfo(moduleInfo);\n let manifestJson: Manifest | undefined =\n this.manifestCache.get(manifestUrl);\n if (manifestJson) {\n return manifestJson;\n }\n try {\n let res = await this.loaderHook.lifecycle.fetch.emit(\n manifestUrl,\n {},\n remoteInfo,\n resourceOptions\n ? {\n ...resourceOptions,\n url: manifestUrl,\n resourceType: 'manifest',\n }\n : undefined,\n );\n if (!res || !(res instanceof Response)) {\n res = await fetch(manifestUrl, {});\n }\n manifestJson = (await res.json()) as Manifest;\n } catch (err) {\n manifestJson =\n (await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit(\n {\n id: manifestUrl,\n error: err,\n from: 'runtime',\n lifecycle: 'afterResolve',\n remote: remoteInfo,\n origin: this.HostInstance,\n },\n )) as Manifest | undefined;\n\n if (!manifestJson) {\n delete this.manifestLoading[manifestUrl];\n error(\n RUNTIME_003,\n runtimeDescMap,\n {\n manifestUrl,\n moduleName: moduleInfo.name,\n hostName: this.HostInstance.options.name,\n },\n `${err}`,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n }\n\n const missingRequiredFields = [\n !manifestJson.metaData && 'metaData',\n !manifestJson.exposes && 'exposes',\n !manifestJson.shared && 'shared',\n ].filter(Boolean);\n if (missingRequiredFields.length > 0) {\n await this.HostInstance.remoteHandler.hooks.lifecycle.errorLoadRemote.emit(\n {\n id: manifestUrl,\n error: new Error(\n `\"${manifestUrl}\" is not a valid federation manifest for remote \"${moduleInfo.name}\". Missing required fields: ${missingRequiredFields.join(', ')}.`,\n ),\n from: 'runtime',\n lifecycle: 'afterResolve',\n remote: remoteInfo,\n origin: this.HostInstance,\n },\n );\n }\n\n if (missingRequiredFields.length > 0) {\n error(\n RUNTIME_013,\n runtimeDescMap,\n {\n manifestUrl,\n moduleName: moduleInfo.name,\n hostName: this.HostInstance.options.name,\n missingFields: missingRequiredFields.join(','),\n },\n undefined,\n optionsToMFContext(this.HostInstance.options),\n );\n }\n this.manifestCache.set(manifestUrl, manifestJson);\n return manifestJson;\n };\n\n return getManifest();\n }\n\n private async loadManifestSnapshot(\n manifestUrl: string,\n moduleInfo: Remote,\n extraOptions: Record<string, any>,\n resourceOptions?: {\n initiator: ResourceLoadInitiator;\n id: string;\n },\n ): Promise<ModuleInfo> {\n const asyncLoadProcess = async () => {\n const manifestJson = await this.getManifestJson(\n manifestUrl,\n moduleInfo,\n extraOptions,\n resourceOptions,\n );\n const remoteSnapshot = generateSnapshotFromManifest(manifestJson, {\n version: manifestUrl,\n });\n\n const { remoteSnapshot: remoteSnapshotRes } =\n await this.hooks.lifecycle.loadRemoteSnapshot.emit({\n options: this.HostInstance.options,\n moduleInfo,\n manifestJson,\n remoteSnapshot,\n manifestUrl,\n from: 'manifest',\n });\n return remoteSnapshotRes;\n };\n\n if (!this.manifestLoading[manifestUrl]) {\n this.manifestLoading[manifestUrl] = asyncLoadProcess().then((res) => res);\n }\n return this.manifestLoading[manifestUrl];\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AAgCA,SAAgB,oBACd,YACA,QAKA;CACA,MAAM,qBAAqBA,iDAAkC;EAC3D,MAAM,OAAO;EACb,SAAS,OAAO,QAAQ;EACzB,CAAC;CAGF,MAAM,mBACJ,sBACA,iBAAiB,sBACjB,mBAAmB,eACnBC,kCAAmB,mBAAmB,aAAa,WAAW,KAAK,CAAC;AAEtE,KAAI,oBAAoB,iBAAiB,eACvC,QAAO;EACL;EACA,gBAAgBC,kCAAmB;EACnC,gBAAgBF,iDAAkC;GAChD,MAAM,WAAW;GACjB,SAAS,iBAAiB;GAC3B,CAAC;EACH;AAGH,QAAO;EACL,oBAAoB;EACpB,gBAAgBE,kCAAmB;EACnC,gBAAgBF,iDAAkC;GAChD,MAAM,WAAW;GACjB,SAAS,aAAa,aAAa,WAAW,UAAU;GACzD,CAAC;EACH;;AAGH,IAAa,kBAAb,MAA6B;CA0C3B,YAAY,cAAgC;6BAzCmB;uCAExB,IAAI,KAAK;eACxC,IAAIG,kCAAa;GACvB,0BAA0B,IAAIC,4BAS5B,2BAA2B;GAC7B,cAAc,IAAIC,+CAMf,qBAAqB;GACxB,oBAAoB,IAAIA,+CAOrB,qBAAqB;GACxB,mBAAmB,IAAIA,+CAMpB,oBAAoB;GACxB,CAA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CAAC;AACJ,UAAO;;AAGT,MAAI,CAAC,KAAK,gBAAgB,aACxB,MAAK,gBAAgB,eAAe,kBAAkB,CAAC,MAAM,QAAQ,IAAI;AAE3E,SAAO,KAAK,gBAAgB"}
@@ -4,6 +4,7 @@ import { PluginSystem } from "../../utils/hooks/pluginSystem.js";
4
4
  import { getGlobalSnapshot } from "../../global.js";
5
5
  import { ModuleFederation } from "../../core.js";
6
6
  import { Options, Remote } from "../../type/config.js";
7
+ import { ResourceLoadInitiator } from "../../type/preload.js";
7
8
  import { GlobalModuleInfo, Manifest, ModuleInfo } from "@module-federation/sdk";
8
9
 
9
10
  //#region src/plugins/snapshot/SnapshotHandler.d.ts
@@ -15,6 +16,7 @@ declare class SnapshotHandler {
15
16
  beforeLoadRemoteSnapshot: AsyncHook<[{
16
17
  options: Options;
17
18
  moduleInfo: Remote;
19
+ origin: ModuleFederation;
18
20
  }], void>;
19
21
  loadSnapshot: AsyncWaterfallHook<{
20
22
  options: Options;
@@ -45,11 +47,11 @@ declare class SnapshotHandler {
45
47
  loadRemoteSnapshotInfo({
46
48
  moduleInfo,
47
49
  id,
48
- expose
50
+ initiator
49
51
  }: {
50
52
  moduleInfo: Remote;
51
53
  id?: string;
52
- expose?: string;
54
+ initiator?: ResourceLoadInitiator;
53
55
  }): Promise<{
54
56
  remoteSnapshot: ModuleInfo;
55
57
  globalSnapshot: GlobalModuleInfo;
@@ -60,6 +62,7 @@ declare class SnapshotHandler {
60
62
  remoteSnapshot: GlobalModuleInfo[string] | undefined;
61
63
  };
62
64
  private getManifestJson;
65
+ private loadManifestSnapshot;
63
66
  }
64
67
  //#endregion
65
68
  export { SnapshotHandler };