@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
package/dist/core.cjs CHANGED
@@ -30,7 +30,7 @@ var ModuleFederation = class {
30
30
  beforeInitContainer: new require_asyncWaterfallHooks.AsyncWaterfallHook("beforeInitContainer"),
31
31
  initContainer: new require_asyncWaterfallHooks.AsyncWaterfallHook("initContainer")
32
32
  });
33
- this.version = "2.4.0";
33
+ this.version = "2.5.0";
34
34
  this.moduleCache = /* @__PURE__ */ new Map();
35
35
  this.loaderHook = new require_pluginSystem.PluginSystem({
36
36
  getModuleInfo: new require_syncHook.SyncHook(),
@@ -38,6 +38,13 @@ var ModuleFederation = class {
38
38
  createLink: new require_syncHook.SyncHook(),
39
39
  fetch: new require_asyncHook.AsyncHook(),
40
40
  loadEntryError: new require_asyncHook.AsyncHook(),
41
+ afterLoadEntry: new require_asyncHook.AsyncHook("afterLoadEntry"),
42
+ beforeInitRemote: new require_asyncHook.AsyncHook("beforeInitRemote"),
43
+ afterInitRemote: new require_asyncHook.AsyncHook("afterInitRemote"),
44
+ beforeGetExpose: new require_asyncHook.AsyncHook("beforeGetExpose"),
45
+ afterGetExpose: new require_asyncHook.AsyncHook("afterGetExpose"),
46
+ beforeExecuteFactory: new require_asyncHook.AsyncHook("beforeExecuteFactory"),
47
+ afterExecuteFactory: new require_asyncHook.AsyncHook("afterExecuteFactory"),
41
48
  getModuleFactory: new require_asyncHook.AsyncHook()
42
49
  });
43
50
  this.bridgeHook = new require_pluginSystem.PluginSystem({
package/dist/core.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs","names":["PluginSystem","SyncWaterfallHook","SyncHook","AsyncWaterfallHook","AsyncHook","snapshotPlugin","generatePreloadAssetsPlugin","getBuilderId","isBrowserEnvValue","SnapshotHandler","SharedHandler","RemoteHandler","RUNTIME_010","runtimeDescMap","DEFAULT_SCOPE","getRemoteInfo","Module","formatShareConfigs","registerPlugins"],"sources":["../src/core.ts"],"sourcesContent":["import { isBrowserEnvValue } from '@module-federation/sdk';\nimport type {\n CreateScriptHookReturn,\n GlobalModuleInfo,\n ModuleInfo,\n} from '@module-federation/sdk';\nimport {\n Options,\n PreloadRemoteArgs,\n RemoteEntryExports,\n Remote,\n Shared,\n ShareInfos,\n UserOptions,\n RemoteInfo,\n ShareScopeMap,\n InitScope,\n RemoteEntryInitOptions,\n CallFrom,\n} from './type';\nimport { getBuilderId, registerPlugins, getRemoteEntry, error } from './utils';\nimport {\n getShortErrorMsg,\n RUNTIME_010,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Module } from './module';\nimport {\n AsyncHook,\n AsyncWaterfallHook,\n PluginSystem,\n SyncHook,\n SyncWaterfallHook,\n} from './utils/hooks';\nimport { generatePreloadAssetsPlugin } from './plugins/generate-preload-assets';\nimport { snapshotPlugin } from './plugins/snapshot';\nimport { getRemoteInfo } from './utils/load';\nimport { DEFAULT_SCOPE } from './constant';\nimport { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';\nimport { SharedHandler } from './shared';\nimport { RemoteHandler } from './remote';\nimport { formatShareConfigs } from './utils/share';\n\n// Declare the global constant that will be defined by DefinePlugin\n// Default to true if not defined (e.g., when runtime-core is used outside of webpack)\n// so that snapshot functionality is included by default.\ndeclare const FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN: boolean;\nconst USE_SNAPSHOT =\n typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN\n : true; // Default to true (use snapshot) when not explicitly defined\n\nexport class ModuleFederation {\n options: Options;\n hooks = new PluginSystem({\n beforeInit: new SyncWaterfallHook<{\n userOptions: UserOptions;\n options: Options;\n origin: ModuleFederation;\n /**\n * @deprecated shareInfo will be removed soon, please use userOptions directly!\n */\n shareInfo: ShareInfos;\n }>('beforeInit'),\n init: new SyncHook<\n [\n {\n options: Options;\n origin: ModuleFederation;\n },\n ],\n void\n >(),\n // maybe will change, temporarily for internal use only\n beforeInitContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n origin: ModuleFederation;\n }>('beforeInitContainer'),\n // maybe will change, temporarily for internal use only\n initContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n origin: ModuleFederation;\n id?: string;\n remoteSnapshot?: ModuleInfo;\n }>('initContainer'),\n });\n version: string = __VERSION__;\n name: string;\n moduleCache: Map<string, Module> = new Map();\n snapshotHandler: SnapshotHandler;\n sharedHandler: SharedHandler;\n remoteHandler: RemoteHandler;\n shareScopeMap: ShareScopeMap;\n loaderHook = new PluginSystem({\n // FIXME: may not be suitable , not open to the public yet\n getModuleInfo: new SyncHook<\n [\n {\n target: Record<string, any>;\n key: any;\n },\n ],\n { value: any | undefined; key: string } | void\n >(),\n createScript: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n },\n ],\n CreateScriptHookReturn\n >(),\n createLink: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n },\n ],\n HTMLLinkElement | void\n >(),\n fetch: new AsyncHook<\n [string, RequestInit, RemoteInfo?],\n Promise<Response> | void | false\n >(),\n loadEntryError: new AsyncHook<\n [\n {\n getRemoteEntry: typeof getRemoteEntry;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n globalLoading: Record<\n string,\n Promise<void | RemoteEntryExports> | undefined\n >;\n uniqueKey: string;\n },\n ],\n Promise<Promise<RemoteEntryExports | undefined> | undefined>\n >(),\n getModuleFactory: new AsyncHook<\n [\n {\n remoteEntryExports: RemoteEntryExports;\n expose: string;\n moduleInfo: RemoteInfo;\n },\n ],\n Promise<(() => Promise<Module>) | undefined>\n >(),\n });\n bridgeHook = new PluginSystem({\n beforeBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n beforeBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n });\n moduleInfo?: GlobalModuleInfo[string];\n\n constructor(userOptions: UserOptions) {\n const plugins = USE_SNAPSHOT\n ? [snapshotPlugin(), generatePreloadAssetsPlugin()]\n : [];\n // TODO: Validate the details of the options\n // Initialize options with default values\n const defaultOptions: Options = {\n id: getBuilderId(),\n name: userOptions.name,\n plugins,\n remotes: [],\n shared: {},\n inBrowser: isBrowserEnvValue,\n };\n\n this.name = userOptions.name;\n this.options = defaultOptions;\n this.snapshotHandler = new SnapshotHandler(this);\n this.sharedHandler = new SharedHandler(this);\n this.remoteHandler = new RemoteHandler(this);\n this.shareScopeMap = this.sharedHandler.shareScopeMap;\n this.registerPlugins([\n ...defaultOptions.plugins,\n ...(userOptions.plugins || []),\n ]);\n this.options = this.formatOptions(defaultOptions, userOptions);\n }\n\n initOptions(userOptions: UserOptions): Options {\n if (userOptions.name && userOptions.name !== this.options.name) {\n error(getShortErrorMsg(RUNTIME_010, runtimeDescMap));\n }\n this.registerPlugins(userOptions.plugins);\n const options = this.formatOptions(this.options, userOptions);\n\n this.options = options;\n\n return options;\n }\n\n async loadShare<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): Promise<false | (() => T | undefined)> {\n return this.sharedHandler.loadShare(pkgName, extraOptions);\n }\n\n // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.\n // 1. If the loaded shared already exists globally, then it will be reused\n // 2. If lib exists in local shared, it will be used directly\n // 3. If the local get returns something other than Promise, then it will be used directly\n loadShareSync<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n from?: 'build' | 'runtime';\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): () => T | never {\n return this.sharedHandler.loadShareSync(pkgName, extraOptions);\n }\n\n initializeSharing(\n shareScopeName = DEFAULT_SCOPE,\n extraOptions?: {\n initScope?: InitScope;\n from?: CallFrom;\n strategy?: Shared['strategy'];\n },\n ): Array<Promise<void>> {\n return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host: this, remoteInfo });\n\n module.remoteEntryExports = container;\n this.moduleCache.set(name, module);\n\n return module;\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n return this.remoteHandler.loadRemote(id, options);\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n return this.remoteHandler.preloadRemote(preloadOptions);\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n extraOptions: { hostShareScopeMap?: ShareScopeMap } = {},\n ): void {\n this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);\n }\n\n formatOptions(globalOptions: Options, userOptions: UserOptions): Options {\n const { allShareInfos: shared } = formatShareConfigs(\n globalOptions,\n userOptions,\n );\n const { userOptions: userOptionsRes, options: globalOptionsRes } =\n this.hooks.lifecycle.beforeInit.emit({\n origin: this,\n userOptions,\n options: globalOptions,\n shareInfo: shared,\n });\n\n const remotes = this.remoteHandler.formatAndRegisterRemote(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const { allShareInfos } = this.sharedHandler.registerShared(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const plugins = [...globalOptionsRes.plugins];\n\n if (userOptionsRes.plugins) {\n userOptionsRes.plugins.forEach((plugin) => {\n if (!plugins.includes(plugin)) {\n plugins.push(plugin);\n }\n });\n }\n\n const optionsRes: Options = {\n ...globalOptions,\n ...userOptions,\n plugins,\n remotes,\n shared: allShareInfos,\n id: userOptionsRes.id || globalOptions.id,\n };\n\n this.hooks.lifecycle.init.emit({\n origin: this,\n options: optionsRes,\n });\n return optionsRes;\n }\n\n registerPlugins(plugins: UserOptions['plugins']) {\n const pluginRes = registerPlugins(plugins, this);\n // Merge plugin\n this.options.plugins = this.options.plugins.reduce((res, plugin) => {\n if (!plugin) return res;\n if (res && !res.find((item) => item.name === plugin.name)) {\n res.push(plugin);\n }\n return res;\n }, pluginRes || []);\n }\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n return this.remoteHandler.registerRemotes(remotes, options);\n }\n\n registerShared(shared: UserOptions['shared']) {\n this.sharedHandler.registerShared(this.options, {\n ...this.options,\n shared,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,eACJ,OAAO,2CAA2C,YAC9C,CAAC,yCACD;AAEN,IAAa,mBAAb,MAA8B;CA4I5B,YAAY,aAA0B;eA1I9B,IAAIA,kCAAa;GACvB,YAAY,IAAIC,4CAQb,aAAa;GAChB,MAAM,IAAIC,2BAQP;GAEH,qBAAqB,IAAIC,+CAMtB,sBAAsB;GAEzB,eAAe,IAAIA,+CAShB,gBAAgB;GACpB,CAAC;;qCAGiC,IAAI,KAAK;oBAK/B,IAAIH,kCAAa;GAE5B,eAAe,IAAIE,2BAQhB;GACH,cAAc,IAAIA,2BAcf;GACH,YAAY,IAAIA,2BAcb;GACH,OAAO,IAAIE,6BAGR;GACH,gBAAgB,IAAIA,6BAejB;GACH,kBAAkB,IAAIA,6BASnB;GACJ,CAAC;oBACW,IAAIJ,kCAAa;GAC5B,oBAAoB,IAAIE,2BAGrB;GACH,mBAAmB,IAAIA,2BAGpB;GACH,qBAAqB,IAAIA,2BAGtB;GACH,oB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;CAG7D,eAAe,QAA+B;AAC5C,OAAK,cAAc,eAAe,KAAK,SAAS;GAC9C,GAAG,KAAK;GACR;GACD,CAAC"}
1
+ {"version":3,"file":"core.cjs","names":["PluginSystem","SyncWaterfallHook","SyncHook","AsyncWaterfallHook","AsyncHook","snapshotPlugin","generatePreloadAssetsPlugin","getBuilderId","isBrowserEnvValue","SnapshotHandler","SharedHandler","RemoteHandler","RUNTIME_010","runtimeDescMap","DEFAULT_SCOPE","getRemoteInfo","Module","formatShareConfigs","registerPlugins"],"sources":["../src/core.ts"],"sourcesContent":["import { isBrowserEnvValue } from '@module-federation/sdk';\nimport type {\n CreateLinkHookReturnDom,\n CreateScriptHookReturn,\n GlobalModuleInfo,\n ModuleInfo,\n} from '@module-federation/sdk';\nimport {\n Options,\n PreloadRemoteArgs,\n RemoteEntryExports,\n Remote,\n Shared,\n ShareInfos,\n UserOptions,\n RemoteInfo,\n ShareScopeMap,\n InitScope,\n RemoteEntryInitOptions,\n CallFrom,\n ResourceLoadContext,\n} from './type';\nimport { getBuilderId, registerPlugins, getRemoteEntry, error } from './utils';\nimport {\n getShortErrorMsg,\n RUNTIME_010,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Module, type RemoteModuleFactory } from './module';\nimport {\n AsyncHook,\n AsyncWaterfallHook,\n PluginSystem,\n SyncHook,\n SyncWaterfallHook,\n} from './utils/hooks';\nimport { generatePreloadAssetsPlugin } from './plugins/generate-preload-assets';\nimport { snapshotPlugin } from './plugins/snapshot';\nimport { getRemoteInfo } from './utils/load';\nimport { DEFAULT_SCOPE } from './constant';\nimport { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';\nimport { SharedHandler } from './shared';\nimport { RemoteHandler } from './remote';\nimport { formatShareConfigs } from './utils/share';\n\n// Declare the global constant that will be defined by DefinePlugin\n// Default to true if not defined (e.g., when runtime-core is used outside of webpack)\n// so that snapshot functionality is included by default.\ndeclare const FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN: boolean;\nconst USE_SNAPSHOT =\n typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN\n : true; // Default to true (use snapshot) when not explicitly defined\n\nexport class ModuleFederation {\n options: Options;\n hooks = new PluginSystem({\n beforeInit: new SyncWaterfallHook<{\n userOptions: UserOptions;\n options: Options;\n origin: ModuleFederation;\n /**\n * @deprecated shareInfo will be removed soon, please use userOptions directly!\n */\n shareInfo: ShareInfos;\n }>('beforeInit'),\n init: new SyncHook<\n [\n {\n options: Options;\n origin: ModuleFederation;\n },\n ],\n void\n >(),\n // maybe will change, temporarily for internal use only\n beforeInitContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n origin: ModuleFederation;\n }>('beforeInitContainer'),\n // maybe will change, temporarily for internal use only\n initContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n origin: ModuleFederation;\n id?: string;\n remoteSnapshot?: ModuleInfo;\n }>('initContainer'),\n });\n version: string = __VERSION__;\n name: string;\n moduleCache: Map<string, Module> = new Map();\n snapshotHandler: SnapshotHandler;\n sharedHandler: SharedHandler;\n remoteHandler: RemoteHandler;\n shareScopeMap: ShareScopeMap;\n loaderHook = new PluginSystem({\n // FIXME: may not be suitable , not open to the public yet\n getModuleInfo: new SyncHook<\n [\n {\n target: Record<string, any>;\n key: any;\n },\n ],\n { value: any | undefined; key: string } | void\n >(),\n createScript: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n resourceContext?: ResourceLoadContext;\n },\n ],\n CreateScriptHookReturn\n >(),\n createLink: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n resourceContext?: ResourceLoadContext;\n },\n ],\n CreateLinkHookReturnDom\n >(),\n fetch: new AsyncHook<\n [string, RequestInit, RemoteInfo?, ResourceLoadContext?],\n Promise<Response> | void | false\n >(),\n loadEntryError: new AsyncHook<\n [\n {\n getRemoteEntry: typeof getRemoteEntry;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n globalLoading: Record<\n string,\n Promise<void | RemoteEntryExports> | undefined\n >;\n uniqueKey: string;\n },\n ],\n Promise<Promise<RemoteEntryExports | undefined> | undefined>\n >(),\n afterLoadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | false | void;\n error?: unknown;\n recovered?: boolean;\n },\n ],\n void\n >('afterLoadEntry'),\n beforeInitRemote: new AsyncHook<\n [\n {\n id?: string;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeInitRemote'),\n afterInitRemote: new AsyncHook<\n [\n {\n id?: string;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n remoteEntryExports?: RemoteEntryExports;\n error?: unknown;\n cached?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterInitRemote'),\n beforeGetExpose: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeGetExpose'),\n afterGetExpose: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n moduleFactory?: RemoteModuleFactory;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterGetExpose'),\n beforeExecuteFactory: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n loadFactory: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeExecuteFactory'),\n afterExecuteFactory: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n loadFactory: boolean;\n exposeModule?: unknown;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterExecuteFactory'),\n getModuleFactory: new AsyncHook<\n [\n {\n remoteEntryExports: RemoteEntryExports;\n expose: string;\n moduleInfo: RemoteInfo;\n },\n ],\n RemoteModuleFactory | Promise<RemoteModuleFactory | undefined> | undefined\n >(),\n });\n bridgeHook = new PluginSystem({\n beforeBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n beforeBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n });\n moduleInfo?: GlobalModuleInfo[string];\n\n constructor(userOptions: UserOptions) {\n const plugins = USE_SNAPSHOT\n ? [snapshotPlugin(), generatePreloadAssetsPlugin()]\n : [];\n // TODO: Validate the details of the options\n // Initialize options with default values\n const defaultOptions: Options = {\n id: getBuilderId(),\n name: userOptions.name,\n plugins,\n remotes: [],\n shared: {},\n inBrowser: isBrowserEnvValue,\n };\n\n this.name = userOptions.name;\n this.options = defaultOptions;\n this.snapshotHandler = new SnapshotHandler(this);\n this.sharedHandler = new SharedHandler(this);\n this.remoteHandler = new RemoteHandler(this);\n this.shareScopeMap = this.sharedHandler.shareScopeMap;\n this.registerPlugins([\n ...defaultOptions.plugins,\n ...(userOptions.plugins || []),\n ]);\n this.options = this.formatOptions(defaultOptions, userOptions);\n }\n\n initOptions(userOptions: UserOptions): Options {\n if (userOptions.name && userOptions.name !== this.options.name) {\n error(getShortErrorMsg(RUNTIME_010, runtimeDescMap));\n }\n this.registerPlugins(userOptions.plugins);\n const options = this.formatOptions(this.options, userOptions);\n\n this.options = options;\n\n return options;\n }\n\n async loadShare<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): Promise<false | (() => T | undefined)> {\n return this.sharedHandler.loadShare(pkgName, extraOptions);\n }\n\n // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.\n // 1. If the loaded shared already exists globally, then it will be reused\n // 2. If lib exists in local shared, it will be used directly\n // 3. If the local get returns something other than Promise, then it will be used directly\n loadShareSync<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n from?: 'build' | 'runtime';\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): () => T | never {\n return this.sharedHandler.loadShareSync(pkgName, extraOptions);\n }\n\n initializeSharing(\n shareScopeName = DEFAULT_SCOPE,\n extraOptions?: {\n initScope?: InitScope;\n from?: CallFrom;\n strategy?: Shared['strategy'];\n },\n ): Array<Promise<void>> {\n return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host: this, remoteInfo });\n\n module.remoteEntryExports = container;\n this.moduleCache.set(name, module);\n\n return module;\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n return this.remoteHandler.loadRemote(id, options);\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n return this.remoteHandler.preloadRemote(preloadOptions);\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n extraOptions: { hostShareScopeMap?: ShareScopeMap } = {},\n ): void {\n this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);\n }\n\n formatOptions(globalOptions: Options, userOptions: UserOptions): Options {\n const { allShareInfos: shared } = formatShareConfigs(\n globalOptions,\n userOptions,\n );\n const { userOptions: userOptionsRes, options: globalOptionsRes } =\n this.hooks.lifecycle.beforeInit.emit({\n origin: this,\n userOptions,\n options: globalOptions,\n shareInfo: shared,\n });\n\n const remotes = this.remoteHandler.formatAndRegisterRemote(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const { allShareInfos } = this.sharedHandler.registerShared(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const plugins = [...globalOptionsRes.plugins];\n\n if (userOptionsRes.plugins) {\n userOptionsRes.plugins.forEach((plugin) => {\n if (!plugins.includes(plugin)) {\n plugins.push(plugin);\n }\n });\n }\n\n const optionsRes: Options = {\n ...globalOptions,\n ...userOptions,\n plugins,\n remotes,\n shared: allShareInfos,\n id: userOptionsRes.id || globalOptions.id,\n };\n\n this.hooks.lifecycle.init.emit({\n origin: this,\n options: optionsRes,\n });\n return optionsRes;\n }\n\n registerPlugins(plugins: UserOptions['plugins']) {\n const pluginRes = registerPlugins(plugins, this);\n // Merge plugin\n this.options.plugins = this.options.plugins.reduce((res, plugin) => {\n if (!plugin) return res;\n if (res && !res.find((item) => item.name === plugin.name)) {\n res.push(plugin);\n }\n return res;\n }, pluginRes || []);\n }\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n return this.remoteHandler.registerRemotes(remotes, options);\n }\n\n registerShared(shared: UserOptions['shared']) {\n this.sharedHandler.registerShared(this.options, {\n ...this.options,\n shared,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,eACJ,OAAO,2CAA2C,YAC9C,CAAC,yCACD;AAEN,IAAa,m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AU,KAAK,cAAc,wBACjC,kBACA,eACD;EAED,MAAM,EAAE,kBAAkB,KAAK,cAAc,eAC3C,kBACA,eACD;EAED,MAAM,UAAU,CAAC,GAAG,iBAAiB,QAAQ;AAE7C,MAAI,eAAe,QACjB,gBAAe,QAAQ,SAAS,WAAW;AACzC,OAAI,CAAC,QAAQ,SAAS,OAAO,CAC3B,SAAQ,KAAK,OAAO;IAEtB;EAGJ,MAAM,aAAsB;GAC1B,GAAG;GACH,GAAG;GACH;GACA;GACA,QAAQ;GACR,IAAI,eAAe,MAAM,cAAc;GACxC;AAED,OAAK,MAAM,UAAU,KAAK,KAAK;GAC7B,QAAQ;GACR,SAAS;GACV,CAAC;AACF,SAAO;;CAGT,gBAAgB,SAAiC;EAC/C,MAAM,YAAYC,+BAAgB,SAAS,KAAK;AAEhD,OAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,QAAQ,KAAK,WAAW;AAClE,OAAI,CAAC,OAAQ,QAAO;AACpB,OAAI,OAAO,CAAC,IAAI,MAAM,SAAS,KAAK,SAAS,OAAO,KAAK,CACvD,KAAI,KAAK,OAAO;AAElB,UAAO;KACN,aAAa,EAAE,CAAC;;CAErB,gBAAgB,SAAmB,SAAqC;AACtE,SAAO,KAAK,cAAc,gBAAgB,SAAS,QAAQ;;CAG7D,eAAe,QAA+B;AAC5C,OAAK,cAAc,eAAe,KAAK,SAAS;GAC9C,GAAG,KAAK;GACR;GACD,CAAC"}
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { Module as Module$1 } from "./module/index.js";
1
+ import { Module as Module$1, RemoteModuleFactory } from "./module/index.js";
2
2
  import { SyncHook } from "./utils/hooks/syncHook.js";
3
3
  import { AsyncHook } from "./utils/hooks/asyncHook.js";
4
4
  import { SyncWaterfallHook } from "./utils/hooks/syncWaterfallHook.js";
@@ -8,9 +8,9 @@ import { SnapshotHandler } from "./plugins/snapshot/SnapshotHandler.js";
8
8
  import { RemoteHandler } from "./remote/index.js";
9
9
  import { SharedHandler } from "./shared/index.js";
10
10
  import { CallFrom, InitScope, Options, Remote, RemoteEntryExports, RemoteEntryInitOptions, RemoteInfo, ShareInfos, ShareScopeMap, Shared, UserOptions } from "./type/config.js";
11
- import { PreloadRemoteArgs } from "./type/preload.js";
11
+ import { PreloadRemoteArgs, ResourceLoadContext } from "./type/preload.js";
12
12
  import { getRemoteEntry } from "./utils/load.js";
13
- import { CreateScriptHookReturn, GlobalModuleInfo, ModuleInfo } from "@module-federation/sdk";
13
+ import { CreateLinkHookReturnDom, CreateScriptHookReturn, GlobalModuleInfo, ModuleInfo } from "@module-federation/sdk";
14
14
 
15
15
  //#region src/core.d.ts
16
16
  declare class ModuleFederation {
@@ -71,6 +71,7 @@ declare class ModuleFederation {
71
71
  * (e.g. preloadRemote / loading remoteEntry).
72
72
  */
73
73
  remoteInfo?: RemoteInfo;
74
+ resourceContext?: ResourceLoadContext;
74
75
  }], CreateScriptHookReturn>;
75
76
  createLink: SyncHook<[{
76
77
  url: string;
@@ -81,8 +82,9 @@ declare class ModuleFederation {
81
82
  * (e.g. preloadRemote / loading remoteEntry).
82
83
  */
83
84
  remoteInfo?: RemoteInfo;
84
- }], void | HTMLLinkElement>;
85
- fetch: AsyncHook<[string, RequestInit, (RemoteInfo | undefined)?], false | void | Promise<Response>>;
85
+ resourceContext?: ResourceLoadContext;
86
+ }], CreateLinkHookReturnDom>;
87
+ fetch: AsyncHook<[string, RequestInit, (RemoteInfo | undefined)?, (ResourceLoadContext | undefined)?], false | void | Promise<Response>>;
86
88
  loadEntryError: AsyncHook<[{
87
89
  getRemoteEntry: typeof getRemoteEntry;
88
90
  origin: ModuleFederation;
@@ -91,11 +93,65 @@ declare class ModuleFederation {
91
93
  globalLoading: Record<string, Promise<void | RemoteEntryExports> | undefined>;
92
94
  uniqueKey: string;
93
95
  }], Promise<Promise<RemoteEntryExports | undefined> | undefined>>;
96
+ afterLoadEntry: AsyncHook<[{
97
+ origin: ModuleFederation;
98
+ remoteInfo: RemoteInfo;
99
+ remoteEntryExports?: false | void | RemoteEntryExports | undefined;
100
+ error?: unknown;
101
+ recovered?: boolean;
102
+ }], void>;
103
+ beforeInitRemote: AsyncHook<[{
104
+ id?: string;
105
+ remoteInfo: RemoteInfo;
106
+ remoteSnapshot?: ModuleInfo;
107
+ origin: ModuleFederation;
108
+ }], void>;
109
+ afterInitRemote: AsyncHook<[{
110
+ id?: string;
111
+ remoteInfo: RemoteInfo;
112
+ remoteSnapshot?: ModuleInfo;
113
+ remoteEntryExports?: RemoteEntryExports;
114
+ error?: unknown;
115
+ cached?: boolean;
116
+ origin: ModuleFederation;
117
+ }], void>;
118
+ beforeGetExpose: AsyncHook<[{
119
+ id: string;
120
+ expose: string;
121
+ moduleInfo: RemoteInfo;
122
+ remoteEntryExports: RemoteEntryExports;
123
+ origin: ModuleFederation;
124
+ }], void>;
125
+ afterGetExpose: AsyncHook<[{
126
+ id: string;
127
+ expose: string;
128
+ moduleInfo: RemoteInfo;
129
+ remoteEntryExports: RemoteEntryExports;
130
+ moduleFactory?: RemoteModuleFactory;
131
+ error?: unknown;
132
+ origin: ModuleFederation;
133
+ }], void>;
134
+ beforeExecuteFactory: AsyncHook<[{
135
+ id: string;
136
+ expose: string;
137
+ moduleInfo: RemoteInfo;
138
+ loadFactory: boolean;
139
+ origin: ModuleFederation;
140
+ }], void>;
141
+ afterExecuteFactory: AsyncHook<[{
142
+ id: string;
143
+ expose: string;
144
+ moduleInfo: RemoteInfo;
145
+ loadFactory: boolean;
146
+ exposeModule?: unknown;
147
+ error?: unknown;
148
+ origin: ModuleFederation;
149
+ }], void>;
94
150
  getModuleFactory: AsyncHook<[{
95
151
  remoteEntryExports: RemoteEntryExports;
96
152
  expose: string;
97
153
  moduleInfo: RemoteInfo;
98
- }], Promise<(() => Promise<Module$1>) | undefined>>;
154
+ }], RemoteModuleFactory | Promise<RemoteModuleFactory | undefined> | undefined>;
99
155
  }>;
100
156
  bridgeHook: PluginSystem<{
101
157
  beforeBridgeRender: SyncHook<[Record<string, any>], void | Record<string, any>>;
package/dist/core.js CHANGED
@@ -30,7 +30,7 @@ var ModuleFederation = class {
30
30
  beforeInitContainer: new AsyncWaterfallHook("beforeInitContainer"),
31
31
  initContainer: new AsyncWaterfallHook("initContainer")
32
32
  });
33
- this.version = "2.4.0";
33
+ this.version = "2.5.0";
34
34
  this.moduleCache = /* @__PURE__ */ new Map();
35
35
  this.loaderHook = new PluginSystem({
36
36
  getModuleInfo: new SyncHook(),
@@ -38,6 +38,13 @@ var ModuleFederation = class {
38
38
  createLink: new SyncHook(),
39
39
  fetch: new AsyncHook(),
40
40
  loadEntryError: new AsyncHook(),
41
+ afterLoadEntry: new AsyncHook("afterLoadEntry"),
42
+ beforeInitRemote: new AsyncHook("beforeInitRemote"),
43
+ afterInitRemote: new AsyncHook("afterInitRemote"),
44
+ beforeGetExpose: new AsyncHook("beforeGetExpose"),
45
+ afterGetExpose: new AsyncHook("afterGetExpose"),
46
+ beforeExecuteFactory: new AsyncHook("beforeExecuteFactory"),
47
+ afterExecuteFactory: new AsyncHook("afterExecuteFactory"),
41
48
  getModuleFactory: new AsyncHook()
42
49
  });
43
50
  this.bridgeHook = new PluginSystem({
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","names":["Module"],"sources":["../src/core.ts"],"sourcesContent":["import { isBrowserEnvValue } from '@module-federation/sdk';\nimport type {\n CreateScriptHookReturn,\n GlobalModuleInfo,\n ModuleInfo,\n} from '@module-federation/sdk';\nimport {\n Options,\n PreloadRemoteArgs,\n RemoteEntryExports,\n Remote,\n Shared,\n ShareInfos,\n UserOptions,\n RemoteInfo,\n ShareScopeMap,\n InitScope,\n RemoteEntryInitOptions,\n CallFrom,\n} from './type';\nimport { getBuilderId, registerPlugins, getRemoteEntry, error } from './utils';\nimport {\n getShortErrorMsg,\n RUNTIME_010,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Module } from './module';\nimport {\n AsyncHook,\n AsyncWaterfallHook,\n PluginSystem,\n SyncHook,\n SyncWaterfallHook,\n} from './utils/hooks';\nimport { generatePreloadAssetsPlugin } from './plugins/generate-preload-assets';\nimport { snapshotPlugin } from './plugins/snapshot';\nimport { getRemoteInfo } from './utils/load';\nimport { DEFAULT_SCOPE } from './constant';\nimport { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';\nimport { SharedHandler } from './shared';\nimport { RemoteHandler } from './remote';\nimport { formatShareConfigs } from './utils/share';\n\n// Declare the global constant that will be defined by DefinePlugin\n// Default to true if not defined (e.g., when runtime-core is used outside of webpack)\n// so that snapshot functionality is included by default.\ndeclare const FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN: boolean;\nconst USE_SNAPSHOT =\n typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN\n : true; // Default to true (use snapshot) when not explicitly defined\n\nexport class ModuleFederation {\n options: Options;\n hooks = new PluginSystem({\n beforeInit: new SyncWaterfallHook<{\n userOptions: UserOptions;\n options: Options;\n origin: ModuleFederation;\n /**\n * @deprecated shareInfo will be removed soon, please use userOptions directly!\n */\n shareInfo: ShareInfos;\n }>('beforeInit'),\n init: new SyncHook<\n [\n {\n options: Options;\n origin: ModuleFederation;\n },\n ],\n void\n >(),\n // maybe will change, temporarily for internal use only\n beforeInitContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n origin: ModuleFederation;\n }>('beforeInitContainer'),\n // maybe will change, temporarily for internal use only\n initContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n origin: ModuleFederation;\n id?: string;\n remoteSnapshot?: ModuleInfo;\n }>('initContainer'),\n });\n version: string = __VERSION__;\n name: string;\n moduleCache: Map<string, Module> = new Map();\n snapshotHandler: SnapshotHandler;\n sharedHandler: SharedHandler;\n remoteHandler: RemoteHandler;\n shareScopeMap: ShareScopeMap;\n loaderHook = new PluginSystem({\n // FIXME: may not be suitable , not open to the public yet\n getModuleInfo: new SyncHook<\n [\n {\n target: Record<string, any>;\n key: any;\n },\n ],\n { value: any | undefined; key: string } | void\n >(),\n createScript: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n },\n ],\n CreateScriptHookReturn\n >(),\n createLink: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n },\n ],\n HTMLLinkElement | void\n >(),\n fetch: new AsyncHook<\n [string, RequestInit, RemoteInfo?],\n Promise<Response> | void | false\n >(),\n loadEntryError: new AsyncHook<\n [\n {\n getRemoteEntry: typeof getRemoteEntry;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n globalLoading: Record<\n string,\n Promise<void | RemoteEntryExports> | undefined\n >;\n uniqueKey: string;\n },\n ],\n Promise<Promise<RemoteEntryExports | undefined> | undefined>\n >(),\n getModuleFactory: new AsyncHook<\n [\n {\n remoteEntryExports: RemoteEntryExports;\n expose: string;\n moduleInfo: RemoteInfo;\n },\n ],\n Promise<(() => Promise<Module>) | undefined>\n >(),\n });\n bridgeHook = new PluginSystem({\n beforeBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n beforeBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n });\n moduleInfo?: GlobalModuleInfo[string];\n\n constructor(userOptions: UserOptions) {\n const plugins = USE_SNAPSHOT\n ? [snapshotPlugin(), generatePreloadAssetsPlugin()]\n : [];\n // TODO: Validate the details of the options\n // Initialize options with default values\n const defaultOptions: Options = {\n id: getBuilderId(),\n name: userOptions.name,\n plugins,\n remotes: [],\n shared: {},\n inBrowser: isBrowserEnvValue,\n };\n\n this.name = userOptions.name;\n this.options = defaultOptions;\n this.snapshotHandler = new SnapshotHandler(this);\n this.sharedHandler = new SharedHandler(this);\n this.remoteHandler = new RemoteHandler(this);\n this.shareScopeMap = this.sharedHandler.shareScopeMap;\n this.registerPlugins([\n ...defaultOptions.plugins,\n ...(userOptions.plugins || []),\n ]);\n this.options = this.formatOptions(defaultOptions, userOptions);\n }\n\n initOptions(userOptions: UserOptions): Options {\n if (userOptions.name && userOptions.name !== this.options.name) {\n error(getShortErrorMsg(RUNTIME_010, runtimeDescMap));\n }\n this.registerPlugins(userOptions.plugins);\n const options = this.formatOptions(this.options, userOptions);\n\n this.options = options;\n\n return options;\n }\n\n async loadShare<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): Promise<false | (() => T | undefined)> {\n return this.sharedHandler.loadShare(pkgName, extraOptions);\n }\n\n // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.\n // 1. If the loaded shared already exists globally, then it will be reused\n // 2. If lib exists in local shared, it will be used directly\n // 3. If the local get returns something other than Promise, then it will be used directly\n loadShareSync<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n from?: 'build' | 'runtime';\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): () => T | never {\n return this.sharedHandler.loadShareSync(pkgName, extraOptions);\n }\n\n initializeSharing(\n shareScopeName = DEFAULT_SCOPE,\n extraOptions?: {\n initScope?: InitScope;\n from?: CallFrom;\n strategy?: Shared['strategy'];\n },\n ): Array<Promise<void>> {\n return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host: this, remoteInfo });\n\n module.remoteEntryExports = container;\n this.moduleCache.set(name, module);\n\n return module;\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n return this.remoteHandler.loadRemote(id, options);\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n return this.remoteHandler.preloadRemote(preloadOptions);\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n extraOptions: { hostShareScopeMap?: ShareScopeMap } = {},\n ): void {\n this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);\n }\n\n formatOptions(globalOptions: Options, userOptions: UserOptions): Options {\n const { allShareInfos: shared } = formatShareConfigs(\n globalOptions,\n userOptions,\n );\n const { userOptions: userOptionsRes, options: globalOptionsRes } =\n this.hooks.lifecycle.beforeInit.emit({\n origin: this,\n userOptions,\n options: globalOptions,\n shareInfo: shared,\n });\n\n const remotes = this.remoteHandler.formatAndRegisterRemote(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const { allShareInfos } = this.sharedHandler.registerShared(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const plugins = [...globalOptionsRes.plugins];\n\n if (userOptionsRes.plugins) {\n userOptionsRes.plugins.forEach((plugin) => {\n if (!plugins.includes(plugin)) {\n plugins.push(plugin);\n }\n });\n }\n\n const optionsRes: Options = {\n ...globalOptions,\n ...userOptions,\n plugins,\n remotes,\n shared: allShareInfos,\n id: userOptionsRes.id || globalOptions.id,\n };\n\n this.hooks.lifecycle.init.emit({\n origin: this,\n options: optionsRes,\n });\n return optionsRes;\n }\n\n registerPlugins(plugins: UserOptions['plugins']) {\n const pluginRes = registerPlugins(plugins, this);\n // Merge plugin\n this.options.plugins = this.options.plugins.reduce((res, plugin) => {\n if (!plugin) return res;\n if (res && !res.find((item) => item.name === plugin.name)) {\n res.push(plugin);\n }\n return res;\n }, pluginRes || []);\n }\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n return this.remoteHandler.registerRemotes(remotes, options);\n }\n\n registerShared(shared: UserOptions['shared']) {\n this.sharedHandler.registerShared(this.options, {\n ...this.options,\n shared,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAM,eACJ,OAAO,2CAA2C,YAC9C,CAAC,yCACD;AAEN,IAAa,mBAAb,MAA8B;CA4I5B,YAAY,aAA0B;eA1I9B,IAAI,aAAa;GACvB,YAAY,IAAI,kBAQb,aAAa;GAChB,MAAM,IAAI,UAQP;GAEH,qBAAqB,IAAI,mBAMtB,sBAAsB;GAEzB,eAAe,IAAI,mBAShB,gBAAgB;GACpB,CAAC;;qCAGiC,IAAI,KAAK;oBAK/B,IAAI,aAAa;GAE5B,eAAe,IAAI,UAQhB;GACH,cAAc,IAAI,UAcf;GACH,YAAY,IAAI,UAcb;GACH,OAAO,IAAI,WAGR;GACH,gBAAgB,IAAI,WAejB;GACH,kBAAkB,IAAI,WASnB;GACJ,CAAC;oBACW,IAAI,aAAa;GAC5B,oBAAoB,IAAI,UAGrB;GACH,mBAAmB,IAAI,UAGpB;GACH,qBAAqB,IAAI,UAGtB;GACH,oBAAoB,IAAI,UAGrB;GACJ,CAAC;EAIA,MAAM,UAAU,eACZ,CAAC,gBAAgB,EAAE,6BAA6B,CAAC,GACjD,EAAE;EAGN,MAAM,iBAA0B;GAC9B,IAAI,cAAc;GAClB,MAAM,YAAY;GAClB;GACA,SAAS,EAAE;GACX,QAAQ,EA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3E,cAAc,eAAwB,aAAmC;EACvE,MAAM,EAAE,eAAe,WAAW,mBAChC,eACA,YACD;EACD,MAAM,EAAE,aAAa,gBAAgB,SAAS,qBAC5C,KAAK,MAAM,UAAU,WAAW,KAAK;GACnC,QAAQ;GACR;GACA,SAAS;GACT,WAAW;GACZ,CAAC;EAEJ,MAAM,UAAU,KAAK,cAAc,wBACjC,kBACA,eACD;EAED,MAAM,EAAE,kBAAkB,KAAK,cAAc,eAC3C,kBACA,eACD;EAED,MAAM,UAAU,CAAC,GAAG,iBAAiB,QAAQ;AAE7C,MAAI,eAAe,QACjB,gBAAe,QAAQ,SAAS,WAAW;AACzC,OAAI,CAAC,QAAQ,SAAS,OAAO,CAC3B,SAAQ,KAAK,OAAO;IAEtB;EAGJ,MAAM,aAAsB;GAC1B,GAAG;GACH,GAAG;GACH;GACA;GACA,QAAQ;GACR,IAAI,eAAe,MAAM,cAAc;GACxC;AAED,OAAK,MAAM,UAAU,KAAK,KAAK;GAC7B,QAAQ;GACR,SAAS;GACV,CAAC;AACF,SAAO;;CAGT,gBAAgB,SAAiC;EAC/C,MAAM,YAAY,gBAAgB,SAAS,KAAK;AAEhD,OAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,QAAQ,KAAK,WAAW;AAClE,OAAI,CAAC,OAAQ,QAAO;AACpB,OAAI,OAAO,CAAC,IAAI,MAAM,SAAS,KAAK,SAAS,OAAO,KAAK,CACvD,KAAI,KAAK,OAAO;AAElB,UAAO;KACN,aAAa,EAAE,CAAC;;CAErB,gBAAgB,SAAmB,SAAqC;AACtE,SAAO,KAAK,cAAc,gBAAgB,SAAS,QAAQ;;CAG7D,eAAe,QAA+B;AAC5C,OAAK,cAAc,eAAe,KAAK,SAAS;GAC9C,GAAG,KAAK;GACR;GACD,CAAC"}
1
+ {"version":3,"file":"core.js","names":["Module"],"sources":["../src/core.ts"],"sourcesContent":["import { isBrowserEnvValue } from '@module-federation/sdk';\nimport type {\n CreateLinkHookReturnDom,\n CreateScriptHookReturn,\n GlobalModuleInfo,\n ModuleInfo,\n} from '@module-federation/sdk';\nimport {\n Options,\n PreloadRemoteArgs,\n RemoteEntryExports,\n Remote,\n Shared,\n ShareInfos,\n UserOptions,\n RemoteInfo,\n ShareScopeMap,\n InitScope,\n RemoteEntryInitOptions,\n CallFrom,\n ResourceLoadContext,\n} from './type';\nimport { getBuilderId, registerPlugins, getRemoteEntry, error } from './utils';\nimport {\n getShortErrorMsg,\n RUNTIME_010,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { Module, type RemoteModuleFactory } from './module';\nimport {\n AsyncHook,\n AsyncWaterfallHook,\n PluginSystem,\n SyncHook,\n SyncWaterfallHook,\n} from './utils/hooks';\nimport { generatePreloadAssetsPlugin } from './plugins/generate-preload-assets';\nimport { snapshotPlugin } from './plugins/snapshot';\nimport { getRemoteInfo } from './utils/load';\nimport { DEFAULT_SCOPE } from './constant';\nimport { SnapshotHandler } from './plugins/snapshot/SnapshotHandler';\nimport { SharedHandler } from './shared';\nimport { RemoteHandler } from './remote';\nimport { formatShareConfigs } from './utils/share';\n\n// Declare the global constant that will be defined by DefinePlugin\n// Default to true if not defined (e.g., when runtime-core is used outside of webpack)\n// so that snapshot functionality is included by default.\ndeclare const FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN: boolean;\nconst USE_SNAPSHOT =\n typeof FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SNAPSHOT_PLUGIN\n : true; // Default to true (use snapshot) when not explicitly defined\n\nexport class ModuleFederation {\n options: Options;\n hooks = new PluginSystem({\n beforeInit: new SyncWaterfallHook<{\n userOptions: UserOptions;\n options: Options;\n origin: ModuleFederation;\n /**\n * @deprecated shareInfo will be removed soon, please use userOptions directly!\n */\n shareInfo: ShareInfos;\n }>('beforeInit'),\n init: new SyncHook<\n [\n {\n options: Options;\n origin: ModuleFederation;\n },\n ],\n void\n >(),\n // maybe will change, temporarily for internal use only\n beforeInitContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n origin: ModuleFederation;\n }>('beforeInitContainer'),\n // maybe will change, temporarily for internal use only\n initContainer: new AsyncWaterfallHook<{\n shareScope: ShareScopeMap[string];\n initScope: InitScope;\n remoteEntryInitOptions: RemoteEntryInitOptions;\n remoteInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n origin: ModuleFederation;\n id?: string;\n remoteSnapshot?: ModuleInfo;\n }>('initContainer'),\n });\n version: string = __VERSION__;\n name: string;\n moduleCache: Map<string, Module> = new Map();\n snapshotHandler: SnapshotHandler;\n sharedHandler: SharedHandler;\n remoteHandler: RemoteHandler;\n shareScopeMap: ShareScopeMap;\n loaderHook = new PluginSystem({\n // FIXME: may not be suitable , not open to the public yet\n getModuleInfo: new SyncHook<\n [\n {\n target: Record<string, any>;\n key: any;\n },\n ],\n { value: any | undefined; key: string } | void\n >(),\n createScript: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n resourceContext?: ResourceLoadContext;\n },\n ],\n CreateScriptHookReturn\n >(),\n createLink: new SyncHook<\n [\n {\n url: string;\n attrs?: Record<string, any>;\n /**\n * The producer(remote) info bound to this resource.\n * Only present when the loader is invoked in a remote-related context\n * (e.g. preloadRemote / loading remoteEntry).\n */\n remoteInfo?: RemoteInfo;\n resourceContext?: ResourceLoadContext;\n },\n ],\n CreateLinkHookReturnDom\n >(),\n fetch: new AsyncHook<\n [string, RequestInit, RemoteInfo?, ResourceLoadContext?],\n Promise<Response> | void | false\n >(),\n loadEntryError: new AsyncHook<\n [\n {\n getRemoteEntry: typeof getRemoteEntry;\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | undefined;\n globalLoading: Record<\n string,\n Promise<void | RemoteEntryExports> | undefined\n >;\n uniqueKey: string;\n },\n ],\n Promise<Promise<RemoteEntryExports | undefined> | undefined>\n >(),\n afterLoadEntry: new AsyncHook<\n [\n {\n origin: ModuleFederation;\n remoteInfo: RemoteInfo;\n remoteEntryExports?: RemoteEntryExports | false | void;\n error?: unknown;\n recovered?: boolean;\n },\n ],\n void\n >('afterLoadEntry'),\n beforeInitRemote: new AsyncHook<\n [\n {\n id?: string;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeInitRemote'),\n afterInitRemote: new AsyncHook<\n [\n {\n id?: string;\n remoteInfo: RemoteInfo;\n remoteSnapshot?: ModuleInfo;\n remoteEntryExports?: RemoteEntryExports;\n error?: unknown;\n cached?: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterInitRemote'),\n beforeGetExpose: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeGetExpose'),\n afterGetExpose: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n remoteEntryExports: RemoteEntryExports;\n moduleFactory?: RemoteModuleFactory;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterGetExpose'),\n beforeExecuteFactory: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n loadFactory: boolean;\n origin: ModuleFederation;\n },\n ],\n void\n >('beforeExecuteFactory'),\n afterExecuteFactory: new AsyncHook<\n [\n {\n id: string;\n expose: string;\n moduleInfo: RemoteInfo;\n loadFactory: boolean;\n exposeModule?: unknown;\n error?: unknown;\n origin: ModuleFederation;\n },\n ],\n void\n >('afterExecuteFactory'),\n getModuleFactory: new AsyncHook<\n [\n {\n remoteEntryExports: RemoteEntryExports;\n expose: string;\n moduleInfo: RemoteInfo;\n },\n ],\n RemoteModuleFactory | Promise<RemoteModuleFactory | undefined> | undefined\n >(),\n });\n bridgeHook = new PluginSystem({\n beforeBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeRender: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n beforeBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n afterBridgeDestroy: new SyncHook<\n [Record<string, any>],\n void | Record<string, any>\n >(),\n });\n moduleInfo?: GlobalModuleInfo[string];\n\n constructor(userOptions: UserOptions) {\n const plugins = USE_SNAPSHOT\n ? [snapshotPlugin(), generatePreloadAssetsPlugin()]\n : [];\n // TODO: Validate the details of the options\n // Initialize options with default values\n const defaultOptions: Options = {\n id: getBuilderId(),\n name: userOptions.name,\n plugins,\n remotes: [],\n shared: {},\n inBrowser: isBrowserEnvValue,\n };\n\n this.name = userOptions.name;\n this.options = defaultOptions;\n this.snapshotHandler = new SnapshotHandler(this);\n this.sharedHandler = new SharedHandler(this);\n this.remoteHandler = new RemoteHandler(this);\n this.shareScopeMap = this.sharedHandler.shareScopeMap;\n this.registerPlugins([\n ...defaultOptions.plugins,\n ...(userOptions.plugins || []),\n ]);\n this.options = this.formatOptions(defaultOptions, userOptions);\n }\n\n initOptions(userOptions: UserOptions): Options {\n if (userOptions.name && userOptions.name !== this.options.name) {\n error(getShortErrorMsg(RUNTIME_010, runtimeDescMap));\n }\n this.registerPlugins(userOptions.plugins);\n const options = this.formatOptions(this.options, userOptions);\n\n this.options = options;\n\n return options;\n }\n\n async loadShare<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): Promise<false | (() => T | undefined)> {\n return this.sharedHandler.loadShare(pkgName, extraOptions);\n }\n\n // The lib function will only be available if the shared set by eager or runtime init is set or the shared is successfully loaded.\n // 1. If the loaded shared already exists globally, then it will be reused\n // 2. If lib exists in local shared, it will be used directly\n // 3. If the local get returns something other than Promise, then it will be used directly\n loadShareSync<T>(\n pkgName: string,\n extraOptions?: {\n customShareInfo?: Partial<Shared>;\n from?: 'build' | 'runtime';\n resolver?: (sharedOptions: ShareInfos[string]) => Shared;\n },\n ): () => T | never {\n return this.sharedHandler.loadShareSync(pkgName, extraOptions);\n }\n\n initializeSharing(\n shareScopeName = DEFAULT_SCOPE,\n extraOptions?: {\n initScope?: InitScope;\n from?: CallFrom;\n strategy?: Shared['strategy'];\n },\n ): Array<Promise<void>> {\n return this.sharedHandler.initializeSharing(shareScopeName, extraOptions);\n }\n\n initRawContainer(\n name: string,\n url: string,\n container: RemoteEntryExports,\n ): Module {\n const remoteInfo = getRemoteInfo({ name, entry: url });\n const module = new Module({ host: this, remoteInfo });\n\n module.remoteEntryExports = container;\n this.moduleCache.set(name, module);\n\n return module;\n }\n\n // eslint-disable-next-line max-lines-per-function\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async loadRemote<T>(\n id: string,\n options?: { loadFactory?: boolean; from: CallFrom },\n ): Promise<T | null> {\n return this.remoteHandler.loadRemote(id, options);\n }\n\n // eslint-disable-next-line @typescript-eslint/member-ordering\n async preloadRemote(preloadOptions: Array<PreloadRemoteArgs>): Promise<void> {\n return this.remoteHandler.preloadRemote(preloadOptions);\n }\n\n initShareScopeMap(\n scopeName: string,\n shareScope: ShareScopeMap[string],\n extraOptions: { hostShareScopeMap?: ShareScopeMap } = {},\n ): void {\n this.sharedHandler.initShareScopeMap(scopeName, shareScope, extraOptions);\n }\n\n formatOptions(globalOptions: Options, userOptions: UserOptions): Options {\n const { allShareInfos: shared } = formatShareConfigs(\n globalOptions,\n userOptions,\n );\n const { userOptions: userOptionsRes, options: globalOptionsRes } =\n this.hooks.lifecycle.beforeInit.emit({\n origin: this,\n userOptions,\n options: globalOptions,\n shareInfo: shared,\n });\n\n const remotes = this.remoteHandler.formatAndRegisterRemote(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const { allShareInfos } = this.sharedHandler.registerShared(\n globalOptionsRes,\n userOptionsRes,\n );\n\n const plugins = [...globalOptionsRes.plugins];\n\n if (userOptionsRes.plugins) {\n userOptionsRes.plugins.forEach((plugin) => {\n if (!plugins.includes(plugin)) {\n plugins.push(plugin);\n }\n });\n }\n\n const optionsRes: Options = {\n ...globalOptions,\n ...userOptions,\n plugins,\n remotes,\n shared: allShareInfos,\n id: userOptionsRes.id || globalOptions.id,\n };\n\n this.hooks.lifecycle.init.emit({\n origin: this,\n options: optionsRes,\n });\n return optionsRes;\n }\n\n registerPlugins(plugins: UserOptions['plugins']) {\n const pluginRes = registerPlugins(plugins, this);\n // Merge plugin\n this.options.plugins = this.options.plugins.reduce((res, plugin) => {\n if (!plugin) return res;\n if (res && !res.find((item) => item.name === plugin.name)) {\n res.push(plugin);\n }\n return res;\n }, pluginRes || []);\n }\n registerRemotes(remotes: Remote[], options?: { force?: boolean }): void {\n return this.remoteHandler.registerRemotes(remotes, options);\n }\n\n registerShared(shared: UserOptions['shared']) {\n this.sharedHandler.registerShared(this.options, {\n ...this.options,\n shared,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAiDA,MAAM,eACJ,OAAO,2CAA2C,YAC9C,CAAC,yCACD;AAEN,IAAa,mBAAb,MAA8B;CAuO5B,YAAY,aAA0B;eArO9B,IAAI,aAAa;GACvB,YAAY,IAAI,kBAQb,aAAa;GAChB,MAAM,IAAI,UAQP;GAEH,qBAAqB,IAAI,mBAMtB,sBAAsB;GAEzB,eAAe,IAAI,mBAShB,gBAAgB;GACpB,CAAC;;qCAGiC,IAAI,KAAK;oBAK/B,IAAI,aAAa;GAE5B,eAAe,IAAI,UAQhB;GACH,cAAc,IAAI,UAef;GACH,YAAY,IAAI,UAeb;GACH,OAAO,IAAI,WAGR;GACH,gBAAgB,IAAI,WAejB;GACH,gBAAgB,IAAI,UAWlB,iBAAiB;GACnB,kBAAkB,IAAI,UAUpB,m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AAS,KAAK;AAEhD,OAAK,QAAQ,UAAU,KAAK,QAAQ,QAAQ,QAAQ,KAAK,WAAW;AAClE,OAAI,CAAC,OAAQ,QAAO;AACpB,OAAI,OAAO,CAAC,IAAI,MAAM,SAAS,KAAK,SAAS,OAAO,KAAK,CACvD,KAAI,KAAK,OAAO;AAElB,UAAO;KACN,aAAa,EAAE,CAAC;;CAErB,gBAAgB,SAAmB,SAAqC;AACtE,SAAO,KAAK,cAAc,gBAAgB,SAAS,QAAQ;;CAG7D,eAAe,QAA+B;AAC5C,OAAK,cAAc,eAAe,KAAK,SAAS;GAC9C,GAAG,KAAK;GACR;GACD,CAAC"}
package/dist/global.cjs CHANGED
@@ -65,7 +65,7 @@ function getGlobalFederationConstructor() {
65
65
  function setGlobalFederationConstructor(FederationConstructor, isDebug = (0, _module_federation_sdk.isDebugMode)()) {
66
66
  if (isDebug) {
67
67
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
68
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.4.0";
68
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.5.0";
69
69
  }
70
70
  }
71
71
  function getInfoWithoutType(target, key) {
package/dist/global.js CHANGED
@@ -65,7 +65,7 @@ function getGlobalFederationConstructor() {
65
65
  function setGlobalFederationConstructor(FederationConstructor, isDebug = isDebugMode()) {
66
66
  if (isDebug) {
67
67
  CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
68
- CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.4.0";
68
+ CurrentGlobal.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "2.5.0";
69
69
  }
70
70
  }
71
71
  function getInfoWithoutType(target, key) {
@@ -1,5 +1,6 @@
1
1
  const require_logger = require('../utils/logger.cjs');
2
2
  const require_tool = require('../utils/tool.cjs');
3
+ const require_manifest = require('../utils/manifest.cjs');
3
4
  const require_load = require('../utils/load.cjs');
4
5
  const require_context = require('../utils/context.cjs');
5
6
  require('../utils/index.cjs');
@@ -7,6 +8,11 @@ let _module_federation_sdk = require("@module-federation/sdk");
7
8
  let _module_federation_error_codes = require("@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 = 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 require_load.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: require_manifest.composeRemoteRequestId(this.remoteInfo.name, expose),
54
+ resourceType: "remoteEntry"
55
+ }
45
56
  });
46
57
  require_logger.assert(remoteEntryExports, `remoteEntryExports is undefined \n ${(0, _module_federation_sdk.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 = class {
70
118
  remoteEntryUrl: this.remoteInfo.entry,
71
119
  remoteEntryKey: this.remoteInfo.entryGlobalName
72
120
  }, void 0, require_context.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
+ require_logger.error(_module_federation_error_codes.RUNTIME_015, _module_federation_error_codes.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}`, require_context.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 = 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 = 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
- require_logger.assert(moduleFactory, `${require_tool.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) require_logger.error(_module_federation_error_codes.RUNTIME_014, _module_federation_error_codes.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, require_context.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 = require_tool.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 = 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.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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AAE,aAAa,MAAM;EAE/D,MAAM,qBAAqB,MAAM,KAAK,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,wBACE,eACA,GAAGC,qBAAQ,KAAK,WAAW,CAAC,uBAAuB,OAAO,GAC3D;EAGD,MAAM,aAAaC,gCAAmB,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"}
1
+ {"version":3,"file":"index.cjs","names":["getRemoteEntry","composeRemoteRequestId","RUNTIME_002","runtimeDescMap","optionsToMFContext","RUNTIME_015","RUNTIME_014","processModuleAlias"],"sources":["../../src/module/index.ts"],"sourcesContent":["import {\n assert,\n error,\n processModuleAlias,\n optionsToMFContext,\n composeRemoteRequestId,\n} from '../utils';\nimport { safeToString, ModuleInfo } from '@module-federation/sdk';\nimport {\n RUNTIME_002,\n RUNTIME_014,\n RUNTIME_015,\n runtimeDescMap,\n} from '@module-federation/error-codes';\nimport { getRemoteEntry } from '../utils/load';\nimport { ModuleFederation } from '../core';\nimport {\n RemoteEntryExports,\n RemoteInfo,\n InitScope,\n ShareScopeMap,\n} 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);\n return res;\n };\n }\n}\n\nexport { Module };\n"],"mappings":";;;;;;;;;;AA0BA,SAAS,wBACP,gBACoB;AACpB,KACE,CAAC,kBACD,EAAE,aAAa,mBACf,CAAC,MAAM,QAAQ,eAAe,QAAQ,CAEtC;CAGF,MAAM,UAAU,eAAe,QAC5B,KAAK,WAAW,OAAO,WAAW,CAClC,OAAO,QAAQ;AAElB,QAAO,QAAQ,SAAS,QAAQ,KAAK,IAAI,GAAG;;AAG9C,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,CA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