@module-federation/enhanced 2.9.2 → 2.9.3

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 (52) hide show
  1. package/dist/CHANGELOG.md +42 -0
  2. package/dist/src/lib/container/ContainerEntryDependency.js +2 -2
  3. package/dist/src/lib/container/ContainerEntryDependency.js.map +1 -1
  4. package/dist/src/lib/container/ContainerEntryModule.js +2 -2
  5. package/dist/src/lib/container/ContainerEntryModule.js.map +1 -1
  6. package/dist/src/lib/container/ContainerExposedDependency.js +2 -2
  7. package/dist/src/lib/container/ContainerExposedDependency.js.map +1 -1
  8. package/dist/src/lib/container/FallbackDependency.js +2 -2
  9. package/dist/src/lib/container/FallbackDependency.js.map +1 -1
  10. package/dist/src/lib/container/FallbackItemDependency.js +2 -2
  11. package/dist/src/lib/container/FallbackItemDependency.js.map +1 -1
  12. package/dist/src/lib/container/FallbackModule.js +2 -2
  13. package/dist/src/lib/container/FallbackModule.js.map +1 -1
  14. package/dist/src/lib/container/HoistContainerReferencesPlugin.js +1 -0
  15. package/dist/src/lib/container/HoistContainerReferencesPlugin.js.map +1 -1
  16. package/dist/src/lib/container/ModuleFederationPlugin.js +2 -2
  17. package/dist/src/lib/container/RemoteModule.js +2 -2
  18. package/dist/src/lib/container/RemoteModule.js.map +1 -1
  19. package/dist/src/lib/container/RemoteRuntimeModule.js +2 -1
  20. package/dist/src/lib/container/RemoteRuntimeModule.js.map +1 -1
  21. package/dist/src/lib/container/RemoteToExternalDependency.js +2 -2
  22. package/dist/src/lib/container/RemoteToExternalDependency.js.map +1 -1
  23. package/dist/src/lib/container/runtime/FederationRuntimePlugin.js +29 -5
  24. package/dist/src/lib/container/runtime/FederationRuntimePlugin.js.map +1 -1
  25. package/dist/src/lib/makeSerializable.d.ts +15 -0
  26. package/dist/src/lib/makeSerializable.js +20 -0
  27. package/dist/src/lib/makeSerializable.js.map +1 -0
  28. package/dist/src/lib/sharing/ConsumeSharedFallbackDependency.js +2 -2
  29. package/dist/src/lib/sharing/ConsumeSharedFallbackDependency.js.map +1 -1
  30. package/dist/src/lib/sharing/ConsumeSharedModule.js +6 -6
  31. package/dist/src/lib/sharing/ConsumeSharedModule.js.map +1 -1
  32. package/dist/src/lib/sharing/ConsumeSharedPlugin.d.ts +1 -1
  33. package/dist/src/lib/sharing/ConsumeSharedPlugin.js +29 -40
  34. package/dist/src/lib/sharing/ConsumeSharedPlugin.js.map +1 -1
  35. package/dist/src/lib/sharing/ProvideForSharedDependency.js +2 -2
  36. package/dist/src/lib/sharing/ProvideForSharedDependency.js.map +1 -1
  37. package/dist/src/lib/sharing/ProvideSharedDependency.js +2 -2
  38. package/dist/src/lib/sharing/ProvideSharedDependency.js.map +1 -1
  39. package/dist/src/lib/sharing/ProvideSharedModule.js +2 -2
  40. package/dist/src/lib/sharing/ProvideSharedModule.js.map +1 -1
  41. package/dist/src/lib/sharing/ProvideSharedPlugin.js +16 -67
  42. package/dist/src/lib/sharing/ProvideSharedPlugin.js.map +1 -1
  43. package/dist/src/lib/sharing/SharePlugin.js +2 -2
  44. package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.js +46 -36
  45. package/dist/src/lib/sharing/tree-shaking/IndependentSharedPlugin.js.map +1 -1
  46. package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.js +2 -2
  47. package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedDependency.js.map +1 -1
  48. package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.js +2 -2
  49. package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryDependency.js.map +1 -1
  50. package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.js +2 -2
  51. package/dist/src/lib/sharing/tree-shaking/SharedContainerPlugin/SharedEntryModule.js.map +1 -1
  52. package/package.json +13 -13
@@ -1 +1 @@
1
- {"version":3,"file":"RemoteRuntimeModule.js","names":["getFederationGlobalScope"],"sources":["../../../../src/lib/container/RemoteRuntimeModule.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compilation } from 'webpack';\nimport RemoteModule from './RemoteModule';\nimport { getFederationGlobalScope } from './runtime/utils';\nimport type ExternalModule from 'webpack/lib/ExternalModule';\nimport type FallbackModule from './FallbackModule';\nimport type {\n ModuleIdToRemoteDataMapping,\n RemotesOptions,\n} from '@module-federation/webpack-bundler-runtime';\n\nconst extractUrlAndGlobal = require(\n normalizeWebpackPath('webpack/lib/util/extractUrlAndGlobal'),\n) as typeof import('webpack/lib/util/extractUrlAndGlobal');\n\nconst { Template, RuntimeModule, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nclass RemoteRuntimeModule extends RuntimeModule {\n constructor() {\n super('remotes loading');\n }\n\n /**\n * @returns {string | null} runtime code\n */\n override generate(): string | null {\n const { compilation, chunkGraph } = this;\n const { runtimeTemplate, moduleGraph } = compilation as Compilation;\n const chunkToRemotesMapping: Record<string, any> = {};\n const idToExternalAndNameMapping: Record<string | number, any> = {};\n const idToRemoteMap: RemotesOptions['idToRemoteMap'] = {};\n const moduleIdToRemoteDataMapping: ModuleIdToRemoteDataMapping = {};\n\n const allChunks = [\n ...Array.from(this.chunk?.getAllReferencedChunks() || []),\n ];\n\n for (const chunk of allChunks) {\n if (chunk.id === null || chunk.id === undefined) {\n continue;\n }\n const modules = chunkGraph?.getChunkModulesIterableBySourceType(\n chunk,\n 'remote',\n );\n if (!modules) {\n continue;\n }\n // @ts-ignore\n const remotes = (chunkToRemotesMapping[chunk.id] = []);\n for (const m of modules) {\n const module: RemoteModule = m as unknown as RemoteModule;\n const name = module.internalRequest;\n // @ts-ignore\n const id = chunkGraph ? chunkGraph.getModuleId(module) : undefined;\n const { shareScope } = module;\n const dep = module.dependencies[0];\n // @ts-ignore\n const externalModule = moduleGraph.getModule(dep) as\n | ExternalModule\n | FallbackModule;\n const externalModuleId =\n chunkGraph && externalModule\n ? // @ts-ignore\n chunkGraph.getModuleId(externalModule)\n : undefined;\n if (id !== undefined && id !== null) {\n //@ts-ignore\n remotes.push(id);\n\n const normalizedExternalModuleId =\n externalModuleId === null || externalModuleId === undefined\n ? undefined\n : externalModuleId;\n idToExternalAndNameMapping[id] = [\n shareScope,\n name,\n normalizedExternalModuleId,\n ];\n const remoteModules: ExternalModule[] = [];\n // FallbackModule has requests\n if ('requests' in externalModule && externalModule.requests) {\n externalModule.dependencies.forEach((dependency) => {\n const remoteModule = moduleGraph.getModule(dependency);\n if (remoteModule) {\n // @ts-ignore\n remoteModules.push(remoteModule as ExternalModule);\n }\n });\n } else {\n remoteModules.push(externalModule as ExternalModule);\n }\n\n idToRemoteMap[id] = [];\n remoteModules.forEach((remoteModule) => {\n let remoteName = '';\n try {\n const [_url, name] = extractUrlAndGlobal(\n remoteModule.request as string,\n );\n remoteName = name;\n } catch (err) {\n //noop\n }\n const externalModuleId =\n chunkGraph &&\n remoteModule &&\n // @ts-ignore\n chunkGraph.getModuleId(remoteModule);\n\n idToRemoteMap[id].push({\n externalType: remoteModule.externalType,\n name: remoteModule.externalType === 'script' ? remoteName : '',\n });\n if (externalModuleId !== null && externalModuleId !== undefined) {\n moduleIdToRemoteDataMapping[id] = {\n shareScope: shareScope,\n name,\n externalModuleId: externalModuleId as string | number,\n // Preserve the extracted remote name so lazy updates can\n // rebuild idToRemoteMap via updateRemoteOptions.\n remoteName: remoteName,\n };\n }\n });\n }\n }\n }\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n return Template.asString([\n `var chunkMapping = ${JSON.stringify(\n chunkToRemotesMapping,\n null,\n '\\t',\n )};`,\n `var idToExternalAndNameMapping = ${JSON.stringify(\n idToExternalAndNameMapping,\n null,\n '\\t',\n )};`,\n `var idToRemoteMap = ${JSON.stringify(idToRemoteMap, null, '\\t')};`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes.chunkMapping = chunkMapping;`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes.idToExternalAndNameMapping = idToExternalAndNameMapping;`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes.idToRemoteMap = idToRemoteMap;`,\n `${RuntimeGlobals.require}.remotesLoadingData.moduleIdToRemoteDataMapping = ${JSON.stringify(\n moduleIdToRemoteDataMapping,\n null,\n '\\t',\n )};`,\n `${\n RuntimeGlobals.ensureChunkHandlers\n }.remotes = ${runtimeTemplate.basicFunction('chunkId, promises', [\n `${federationGlobal}.bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${RuntimeGlobals.require}});`,\n ])}`,\n ]);\n }\n}\n\nexport default RemoteRuntimeModule;\n"],"mappings":";;;;;;AAeA,MAAM,sBAAsB,gFACL,uCAAuC,CAC7D;AAED,MAAM,EAAE,UAAU,eAAe,mBAAmB,gFAC7B,UAAU,CAChC;AAED,IAAM,sBAAN,cAAkC,cAAc;CAC9C,cAAc;AACZ,QAAM,kBAAkB;;;;;CAM1B,AAAS,WAA0B;EACjC,MAAM,EAAE,aAAa,eAAe;EACpC,MAAM,EAAE,iBAAiB,gBAAgB;EACzC,MAAM,wBAA6C,EAAE;EACrD,MAAM,6BAA2D,EAAE;EACnE,MAAM,gBAAiD,EAAE;EACzD,MAAM,8BAA2D,EAAE;EAEnE,MAAM,YAAY,CAChB,GAAG,MAAM,KAAK,KAAK,OAAO,wBAAwB,IAAI,EAAE,CAAC,CAC1D;AAED,OAAK,MAAM,SAAS,WAAW;AAC7B,OAAI,MAAM,OAAO,QAAQ,MAAM,OAAO,OACpC;GAEF,MAAM,UAAU,YAAY,oCAC1B,OACA,SACD;AACD,OAAI,CAAC,QACH;GAGF,MAAM,UAAW,sBAAsB,MAAM,MAAM,EAAE;AACrD,QAAK,MAAM,KAAK,SAAS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AAiB;GACpB,GAAG,iBAAiB;GACpB,GAAG,eAAe,QAAQ,oDAAoD,KAAK,UACjF,6BACA,MACA,IACD,CAAC;GACF,GACE,eAAe,oBAChB,aAAa,gBAAgB,cAAc,qBAAqB,CAC/D,GAAG,iBAAiB,qHAAqH,eAAe,QAAQ,KACjK,CAAC;GACH,CAAC"}
1
+ {"version":3,"file":"RemoteRuntimeModule.js","names":["getFederationGlobalScope"],"sources":["../../../../src/lib/container/RemoteRuntimeModule.ts"],"sourcesContent":["/*\n MIT License http://www.opensource.org/licenses/mit-license.php\n Author Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type { Compilation } from 'webpack';\nimport RemoteModule from './RemoteModule';\nimport { getFederationGlobalScope } from './runtime/utils';\nimport type ExternalModule from 'webpack/lib/ExternalModule';\nimport type FallbackModule from './FallbackModule';\nimport type {\n ModuleIdToRemoteDataMapping,\n RemotesOptions,\n} from '@module-federation/webpack-bundler-runtime';\n\nconst extractUrlAndGlobal = require(\n normalizeWebpackPath('webpack/lib/util/extractUrlAndGlobal'),\n) as typeof import('webpack/lib/util/extractUrlAndGlobal');\n\nconst { Template, RuntimeModule, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { compareModulesByIdentifier } = require(\n normalizeWebpackPath('webpack/lib/util/comparators'),\n) as typeof import('webpack/lib/util/comparators');\n\nclass RemoteRuntimeModule extends RuntimeModule {\n constructor() {\n super('remotes loading');\n }\n\n /**\n * @returns {string | null} runtime code\n */\n override generate(): string | null {\n const { compilation, chunkGraph } = this;\n const { runtimeTemplate, moduleGraph } = compilation as Compilation;\n const chunkToRemotesMapping: Record<string, any> = {};\n const idToExternalAndNameMapping: Record<string | number, any> = {};\n const idToRemoteMap: RemotesOptions['idToRemoteMap'] = {};\n const moduleIdToRemoteDataMapping: ModuleIdToRemoteDataMapping = {};\n\n const allChunks = [\n ...Array.from(this.chunk?.getAllReferencedChunks() || []),\n ];\n\n for (const chunk of allChunks) {\n if (chunk.id === null || chunk.id === undefined) {\n continue;\n }\n const modules = chunkGraph?.getOrderedChunkModulesIterableBySourceType(\n chunk,\n 'remote',\n compareModulesByIdentifier,\n );\n if (!modules) {\n continue;\n }\n // @ts-ignore\n const remotes = (chunkToRemotesMapping[chunk.id] = []);\n for (const m of modules) {\n const module: RemoteModule = m as unknown as RemoteModule;\n const name = module.internalRequest;\n // @ts-ignore\n const id = chunkGraph ? chunkGraph.getModuleId(module) : undefined;\n const { shareScope } = module;\n const dep = module.dependencies[0];\n // @ts-ignore\n const externalModule = moduleGraph.getModule(dep) as\n | ExternalModule\n | FallbackModule;\n const externalModuleId =\n chunkGraph && externalModule\n ? // @ts-ignore\n chunkGraph.getModuleId(externalModule)\n : undefined;\n if (id !== undefined && id !== null) {\n //@ts-ignore\n remotes.push(id);\n\n const normalizedExternalModuleId =\n externalModuleId === null || externalModuleId === undefined\n ? undefined\n : externalModuleId;\n idToExternalAndNameMapping[id] = [\n shareScope,\n name,\n normalizedExternalModuleId,\n ];\n const remoteModules: ExternalModule[] = [];\n // FallbackModule has requests\n if ('requests' in externalModule && externalModule.requests) {\n externalModule.dependencies.forEach((dependency) => {\n const remoteModule = moduleGraph.getModule(dependency);\n if (remoteModule) {\n // @ts-ignore\n remoteModules.push(remoteModule as ExternalModule);\n }\n });\n } else {\n remoteModules.push(externalModule as ExternalModule);\n }\n\n idToRemoteMap[id] = [];\n remoteModules.forEach((remoteModule) => {\n let remoteName = '';\n try {\n const [_url, name] = extractUrlAndGlobal(\n remoteModule.request as string,\n );\n remoteName = name;\n } catch (err) {\n //noop\n }\n const externalModuleId =\n chunkGraph &&\n remoteModule &&\n // @ts-ignore\n chunkGraph.getModuleId(remoteModule);\n\n idToRemoteMap[id].push({\n externalType: remoteModule.externalType,\n name: remoteModule.externalType === 'script' ? remoteName : '',\n });\n if (externalModuleId !== null && externalModuleId !== undefined) {\n moduleIdToRemoteDataMapping[id] = {\n shareScope: shareScope,\n name,\n externalModuleId: externalModuleId as string | number,\n // Preserve the extracted remote name so lazy updates can\n // rebuild idToRemoteMap via updateRemoteOptions.\n remoteName: remoteName,\n };\n }\n });\n }\n }\n }\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n return Template.asString([\n `var chunkMapping = ${JSON.stringify(\n chunkToRemotesMapping,\n null,\n '\\t',\n )};`,\n `var idToExternalAndNameMapping = ${JSON.stringify(\n idToExternalAndNameMapping,\n null,\n '\\t',\n )};`,\n `var idToRemoteMap = ${JSON.stringify(idToRemoteMap, null, '\\t')};`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes.chunkMapping = chunkMapping;`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes.idToExternalAndNameMapping = idToExternalAndNameMapping;`,\n `${federationGlobal}.bundlerRuntimeOptions.remotes.idToRemoteMap = idToRemoteMap;`,\n `${RuntimeGlobals.require}.remotesLoadingData.moduleIdToRemoteDataMapping = ${JSON.stringify(\n moduleIdToRemoteDataMapping,\n null,\n '\\t',\n )};`,\n `${\n RuntimeGlobals.ensureChunkHandlers\n }.remotes = ${runtimeTemplate.basicFunction('chunkId, promises', [\n `${federationGlobal}.bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${RuntimeGlobals.require}});`,\n ])}`,\n ]);\n }\n}\n\nexport default RemoteRuntimeModule;\n"],"mappings":";;;;;;AAeA,MAAM,sBAAsB,gFACL,uCAAuC,CAC7D;AAED,MAAM,EAAE,UAAU,eAAe,mBAAmB,gFAC7B,UAAU,CAChC;AACD,MAAM,EAAE,+BAA+B,gFAChB,+BAA+B,CACrD;AAED,IAAM,sBAAN,cAAkC,cAAc;CAC9C,cAAc;AACZ,QAAM,kBAAkB;;;;;CAM1B,AAAS,WAA0B;EACjC,MAAM,EAAE,aAAa,eAAe;EACpC,MAAM,EAAE,iBAAiB,gBA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KAAK;OACrB,cAAc,aAAa;OAC3B,MAAM,aAAa,iBAAiB,WAAW,aAAa;OAC7D,CAAC;AACF,UAAI,qBAAqB,QAAQ,qBAAqB,OACpD,6BAA4B,MAAM;OACpB;OACZ;OACkB;OAGN;OACb;OAEH;;;;EAIR,MAAM,mBAAmBA,6DACvB,kBAAmB,EAAE,CACtB;AAED,SAAO,SAAS,SAAS;GACvB,sBAAsB,KAAK,UACzB,uBACA,MACA,IACD,CAAC;GACF,oCAAoC,KAAK,UACvC,4BACA,MACA,IACD,CAAC;GACF,uBAAuB,KAAK,UAAU,eAAe,MAAM,IAAK,CAAC;GACjE,GAAG,iBAAiB;GACpB,GAAG,iBAAiB;GACpB,GAAG,iBAAiB;GACpB,GAAG,eAAe,QAAQ,oDAAoD,KAAK,UACjF,6BACA,MACA,IACD,CAAC;GACF,GACE,eAAe,oBAChB,aAAa,gBAAgB,cAAc,qBAAqB,CAC/D,GAAG,iBAAiB,qHAAqH,eAAe,QAAQ,KACjK,CAAC;GACH,CAAC"}
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
  const require_runtime = require('../../_virtual/_rolldown/runtime.js');
5
+ const require_lib_makeSerializable = require('../makeSerializable.js');
5
6
  let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
6
7
 
7
8
  //#region src/lib/container/RemoteToExternalDependency.ts
8
- const makeSerializable = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/makeSerializable"));
9
9
  const { dependencies } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
10
10
  var RemoteToExternalDependency = class extends dependencies.ModuleDependency {
11
11
  /**
@@ -21,7 +21,7 @@ var RemoteToExternalDependency = class extends dependencies.ModuleDependency {
21
21
  return "esm";
22
22
  }
23
23
  };
24
- makeSerializable(RemoteToExternalDependency, "enhanced/lib/container/RemoteToExternalDependency");
24
+ require_lib_makeSerializable.default(RemoteToExternalDependency, "enhanced/lib/container/RemoteToExternalDependency");
25
25
 
26
26
  //#endregion
27
27
  exports.default = RemoteToExternalDependency;
@@ -1 +1 @@
1
- {"version":3,"file":"RemoteToExternalDependency.js","names":[],"sources":["../../../../src/lib/container/RemoteToExternalDependency.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst { dependencies } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nclass RemoteToExternalDependency extends dependencies.ModuleDependency {\n /**\n * @param {string} request request\n */\n constructor(request: string) {\n super(request);\n }\n override get type() {\n return 'remote to external';\n }\n\n override get category() {\n return 'esm';\n }\n}\n\nmakeSerializable(\n RemoteToExternalDependency,\n 'enhanced/lib/container/RemoteToExternalDependency',\n);\n\nexport default RemoteToExternalDependency;\n"],"mappings":";;;;;;;AAQA,MAAM,mBAAmB,gFACF,oCAAoC,CAC1D;AACD,MAAM,EAAE,iBAAiB,gFACF,UAAU,CAChC;AAED,IAAM,6BAAN,cAAyC,aAAa,iBAAiB;;;;CAIrE,YAAY,SAAiB;AAC3B,QAAM,QAAQ;;CAEhB,IAAa,OAAO;AAClB,SAAO;;CAGT,IAAa,WAAW;AACtB,SAAO;;;AAIX,iBACE,4BACA,oDACD"}
1
+ {"version":3,"file":"RemoteToExternalDependency.js","names":["makeSerializable"],"sources":["../../../../src/lib/container/RemoteToExternalDependency.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nimport makeSerializable from '../makeSerializable';\nconst { dependencies } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nclass RemoteToExternalDependency extends dependencies.ModuleDependency {\n /**\n * @param {string} request request\n */\n constructor(request: string) {\n super(request);\n }\n override get type() {\n return 'remote to external';\n }\n\n override get category() {\n return 'esm';\n }\n}\n\nmakeSerializable(\n RemoteToExternalDependency,\n 'enhanced/lib/container/RemoteToExternalDependency',\n);\n\nexport default RemoteToExternalDependency;\n"],"mappings":";;;;;;;;AASA,MAAM,EAAE,iBAAiB,gFACF,UAAU,CAChC;AAED,IAAM,6BAAN,cAAyC,aAAa,iBAAiB;;;;CAIrE,YAAY,SAAiB;AAC3B,QAAM,QAAQ;;CAEhB,IAAa,OAAO;AAClB,SAAO;;CAGT,IAAa,WAAW;AACtB,SAAO;;;AAIXA,qCACE,4BACA,oDACD"}
@@ -64,6 +64,23 @@ const { runtimeToolsPath: RuntimeToolsPath, bundlerRuntimePath: BundlerRuntimePa
64
64
  const federationGlobal = require_lib_container_runtime_utils.getFederationGlobalScope(RuntimeGlobals);
65
65
  const onceForCompiler = /* @__PURE__ */ new WeakSet();
66
66
  const onceForCompilerEntryMap = /* @__PURE__ */ new WeakMap();
67
+ const fallbackWarnings = /* @__PURE__ */ new WeakMap();
68
+ function warn(compiler, message) {
69
+ let messages = fallbackWarnings.get(compiler);
70
+ if (!messages) {
71
+ messages = /* @__PURE__ */ new Set();
72
+ fallbackWarnings.set(compiler, messages);
73
+ }
74
+ messages.add(message);
75
+ }
76
+ function resolveRuntimePluginPath(compiler, entry) {
77
+ const fromContext = path.default.resolve(compiler.context, entry);
78
+ if (path.default.isAbsolute(entry) || fs.default.existsSync(fromContext)) return fromContext;
79
+ const fromCwd = path.default.resolve(entry);
80
+ if (!fs.default.existsSync(fromCwd)) return fromContext;
81
+ warn(compiler, `runtimePlugins entry ${JSON.stringify(entry)} was found relative to the working directory, not the compiler context ${compiler.context}. Relative runtimePlugins paths resolve against the context. Update the path; the working-directory fallback will be removed.`);
82
+ return fromCwd;
83
+ }
67
84
  var FederationRuntimePlugin = class FederationRuntimePlugin {
68
85
  constructor(options) {
69
86
  this.options = options ? { ...options } : void 0;
@@ -81,10 +98,9 @@ var FederationRuntimePlugin = class FederationRuntimePlugin {
81
98
  if (Array.isArray(runtimePlugins)) runtimePlugins.forEach((runtimePlugin, index) => {
82
99
  if (!runtimePlugin) return;
83
100
  const runtimePluginName = `plugin_${index}`;
84
- const runtimePluginEntry = Array.isArray(runtimePlugin) ? runtimePlugin[0] : runtimePlugin;
85
- const runtimePluginPath = require_lib_container_runtime_normalizeToPosixPath.normalizeToPosixPath(path.default.isAbsolute(runtimePluginEntry) ? runtimePluginEntry : path.default.join(process.cwd(), runtimePluginEntry));
101
+ const runtimePluginPath = require_lib_container_runtime_normalizeToPosixPath.normalizeToPosixPath(resolveRuntimePluginPath(compiler, Array.isArray(runtimePlugin) ? runtimePlugin[0] : runtimePlugin));
86
102
  const paramsStr = Array.isArray(runtimePlugin) && runtimePlugin.length > 1 ? JSON.stringify(runtimePlugin[1]) : "undefined";
87
- runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\n`;
103
+ runtimePluginTemplates += `import ${runtimePluginName} from ${JSON.stringify(runtimePluginPath)};\n`;
88
104
  runtimePluginCalls.push(`${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`);
89
105
  });
90
106
  const embedRuntimeLines = Template.asString([
@@ -102,7 +118,7 @@ var FederationRuntimePlugin = class FederationRuntimePlugin {
102
118
  "}"
103
119
  ]);
104
120
  return Template.asString([
105
- `import federation from '${normalizedBundlerRuntimePath}';`,
121
+ `import federation from ${JSON.stringify(normalizedBundlerRuntimePath)};`,
106
122
  runtimePluginTemplates,
107
123
  embedRuntimeLines,
108
124
  `if(!${federationGlobal}.instance){`,
@@ -243,7 +259,7 @@ var FederationRuntimePlugin = class FederationRuntimePlugin {
243
259
  };
244
260
  if (this.options && !this.options?.name)
245
261
  //! the instance may get the same one if the name is the same https://github.com/module-federation/core/blob/main/packages/runtime/src/index.ts#L18
246
- this.options.name = compiler.options.output.uniqueName || `container_${Date.now()}`;
262
+ this.options.name = compiler.options.output.uniqueName || `container_${require_lib_container_runtime_utils.createHash(`${compiler.options.name ?? ""} ${compiler.context}`).slice(0, 8)}`;
247
263
  const resolvedPaths = resolveRuntimePaths(this.options?.implementation);
248
264
  this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;
249
265
  this.runtimePath = resolvedPaths.runtimePath;
@@ -255,6 +271,14 @@ var FederationRuntimePlugin = class FederationRuntimePlugin {
255
271
  this.prependEntry(compiler);
256
272
  this.injectRuntime(compiler);
257
273
  this.setRuntimeAlias(compiler);
274
+ compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => {
275
+ for (const message of fallbackWarnings.get(compiler) ?? []) {
276
+ const warning = new compiler.webpack.WebpackError(message);
277
+ warning.name = "FederationRuntimePluginWarning";
278
+ warning.hideStack = true;
279
+ compilation.warnings.push(warning);
280
+ }
281
+ });
258
282
  onceForCompiler.add(compiler);
259
283
  }
260
284
  }
@@ -1 +1 @@
1
- {"version":3,"file":"FederationRuntimePlugin.js","names":["getFederationGlobalScope","normalizeToPosixPath","createHash","TEMP_DIR","FederationRuntimeDependency","FederationModulesPlugin","normalizeRuntimeInitOptionsWithOutShared","FederationRuntimeModule","EmbedFederationRuntimePlugin","HoistContainerReferences"],"sources":["../../../../../src/lib/container/runtime/FederationRuntimePlugin.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type {\n Compiler,\n WebpackPluginInstance,\n Compilation,\n Chunk,\n} from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { moduleFederationPlugin } from '@module-federation/sdk';\nimport FederationRuntimeModule from './FederationRuntimeModule';\nimport {\n getFederationGlobalScope,\n normalizeRuntimeInitOptionsWithOutShared,\n createHash,\n normalizeToPosixPath,\n} from './utils';\nimport { TEMP_DIR } from '../constant';\nimport EmbedFederationRuntimePlugin from './EmbedFederationRuntimePlugin';\nimport FederationModulesPlugin from './FederationModulesPlugin';\nimport HoistContainerReferences from '../HoistContainerReferencesPlugin';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\nconst ModuleDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'),\n) as typeof import('webpack/lib/dependencies/ModuleDependency');\n\nconst { RuntimeGlobals, Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { mkdirpSync } = require(\n normalizeWebpackPath('webpack/lib/util/fs'),\n) as typeof import('webpack/lib/util/fs');\n\ntype ResolveFn = typeof require.resolve;\ntype RuntimeEntrySpec = {\n bundler: string;\n esm: string;\n cjs: string;\n};\n\nfunction resolveRuntimeEntry(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n const candidates = [spec.bundler, spec.esm, spec.cjs];\n const modulePaths = implementation ? [implementation] : undefined;\n let lastError: unknown;\n\n for (const candidate of candidates) {\n try {\n return modulePaths\n ? resolve(candidate, { paths: modulePaths })\n : resolve(candidate);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw lastError;\n}\n\nfunction resolveRuntimeEntryWithFallback(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n if (implementation) {\n try {\n return resolveRuntimeEntry(spec, implementation, resolve);\n } catch {\n // Fall back to the workspace runtime packages when a custom\n // implementation hasn't published the newer subpath yet.\n }\n }\n\n return resolveRuntimeEntry(spec, undefined, resolve);\n}\nexport function resolveRuntimePaths(\n implementation?: string,\n resolve: ResolveFn = require.resolve,\n) {\n // Prefer the dedicated bundler subpath so webpack can tree-shake across the\n // runtime package boundary. Fall back to the legacy dist contract for older\n // custom implementations that have not published /bundler yet.\n const runtimeToolsPath = resolveRuntimeEntryWithFallback(\n {\n bundler: '@module-federation/runtime-tools/bundler',\n esm: '@module-federation/runtime-tools/dist/index.js',\n cjs: '@module-federation/runtime-tools/dist/index.cjs',\n },\n implementation,\n resolve,\n );\n const moduleBase = implementation || runtimeToolsPath;\n\n return {\n runtimeToolsPath,\n bundlerRuntimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/webpack-bundler-runtime/bundler',\n esm: '@module-federation/webpack-bundler-runtime/dist/index.js',\n cjs: '@module-federation/webpack-bundler-runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n runtimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/runtime/bundler',\n esm: '@module-federation/runtime/dist/index.js',\n cjs: '@module-federation/runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n };\n}\n\nconst {\n runtimeToolsPath: RuntimeToolsPath,\n bundlerRuntimePath: BundlerRuntimePath,\n runtimePath: RuntimePath,\n} = resolveRuntimePaths();\nconst federationGlobal = getFederationGlobalScope(RuntimeGlobals);\n\nconst onceForCompiler = new WeakSet<Compiler>();\nconst onceForCompilerEntryMap = new WeakMap<Compiler, string>();\n\nclass FederationRuntimePlugin {\n options?: moduleFederationPlugin.ModuleFederationPluginOptions;\n entryFilePath: string;\n bundlerRuntimePath: string;\n runtimePath: string;\n runtimeToolsPath: string;\n federationRuntimeDependency?: FederationRuntimeDependency; // Add this line\n\n constructor(options?: moduleFederationPlugin.ModuleFederationPluginOptions) {\n this.options = options ? { ...options } : undefined;\n this.entryFilePath = '';\n this.bundlerRuntimePath = BundlerRuntimePath;\n this.runtimePath = RuntimePath;\n this.runtimeToolsPath = RuntimeToolsPath;\n this.federationRuntimeDependency = undefined; // Initialize as undefined\n }\n\n static getTemplate(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n bundlerRuntimePath?: string,\n ) {\n // internal runtime plugin\n const runtimePlugins = options.runtimePlugins;\n const normalizedBundlerRuntimePath = normalizeToPosixPath(\n bundlerRuntimePath || BundlerRuntimePath,\n );\n\n let runtimePluginTemplates = '';\n const runtimePluginCalls: string[] = [];\n\n if (Array.isArray(runtimePlugins)) {\n runtimePlugins.forEach((runtimePlugin, index) => {\n if (!runtimePlugin) {\n return;\n }\n const runtimePluginName = `plugin_${index}`;\n const runtimePluginEntry = Array.isArray(runtimePlugin)\n ? runtimePlugin[0]\n : runtimePlugin;\n const runtimePluginPath = normalizeToPosixPath(\n path.isAbsolute(runtimePluginEntry)\n ? runtimePluginEntry\n : path.join(process.cwd(), runtimePluginEntry),\n );\n const paramsStr =\n Array.isArray(runtimePlugin) && runtimePlugin.length > 1\n ? JSON.stringify(runtimePlugin[1])\n : 'undefined';\n runtimePluginTemplates += `import ${runtimePluginName} from '${runtimePluginPath}';\\n`;\n runtimePluginCalls.push(\n `${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`,\n );\n });\n }\n const embedRuntimeLines = Template.asString([\n `if(!${federationGlobal}.runtime || !${federationGlobal}.bundlerRuntime){`,\n Template.indent([\n `var prevFederation = ${federationGlobal};`,\n `${federationGlobal} = {}`,\n `for(var key in federation){`,\n Template.indent([`${federationGlobal}[key] = federation[key];`]),\n '}',\n `for(var key in prevFederation){`,\n Template.indent([`${federationGlobal}[key] = prevFederation[key];`]),\n '}',\n ]),\n '}',\n ]);\n\n return Template.asString([\n `import federation from '${normalizedBundlerRuntimePath}';`,\n runtimePluginTemplates,\n embedRuntimeLines,\n `if(!${federationGlobal}.instance){`,\n Template.indent([\n runtimePluginCalls.length\n ? Template.asString([\n `var pluginsToAdd = [`,\n Template.indent(\n Template.indent(runtimePluginCalls.map((call) => `${call},`)),\n ),\n `].filter(Boolean);`,\n `${federationGlobal}.initOptions.plugins = ${federationGlobal}.initOptions.plugins ? `,\n `${federationGlobal}.initOptions.plugins.concat(pluginsToAdd) : pluginsToAdd;`,\n ])\n : '',\n // `${federationGlobal}.instance = ${federationGlobal}.runtime.init(${federationGlobal}.initOptions);`,\n `${federationGlobal}.instance = ${federationGlobal}.bundlerRuntime.init({webpackRequire:${RuntimeGlobals.require}});`,\n `if(${federationGlobal}.attachShareScopeMap){`,\n Template.indent([\n `${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`,\n ]),\n '}',\n `if(${federationGlobal}.installInitialConsumes){`,\n Template.indent([`${federationGlobal}.installInitialConsumes()`]),\n '}',\n ]),\n '}',\n ]);\n }\n\n getFilePath(compiler: Compiler) {\n if (!this.options) {\n return '';\n }\n\n const existedFilePath = onceForCompilerEntryMap.get(compiler);\n\n if (existedFilePath) {\n return existedFilePath;\n }\n\n let entryFilePath = '';\n if (!this.options?.virtualRuntimeEntry) {\n const containerName = this.options.name;\n const hash = createHash(\n `${containerName} ${FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n )}`,\n );\n entryFilePath = path.join(TEMP_DIR, `entry.${hash}.js`);\n } else {\n entryFilePath = `data:text/javascript;charset=utf-8;base64,${Buffer.from(\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n 'utf8',\n ).toString('base64')}`;\n }\n\n onceForCompilerEntryMap.set(compiler, entryFilePath);\n\n return entryFilePath;\n }\n\n ensureFile(compiler: Compiler) {\n if (!this.options) {\n return;\n }\n // skip virtual entry\n if (this.options?.virtualRuntimeEntry) {\n return;\n }\n const filePath = this.entryFilePath;\n const outputFs = (compiler as unknown as { outputFileSystem?: unknown })\n .outputFileSystem;\n const fsLike =\n outputFs &&\n typeof (outputFs as typeof fs).readFileSync === 'function' &&\n typeof (outputFs as typeof fs).writeFileSync === 'function'\n ? (outputFs as typeof fs)\n : fs;\n try {\n fsLike.readFileSync(filePath);\n } catch {\n mkdirpSync(fsLike as any, TEMP_DIR);\n fsLike.writeFileSync(\n filePath,\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n );\n }\n }\n\n getDependency(compiler: Compiler) {\n if (this.federationRuntimeDependency)\n return this.federationRuntimeDependency;\n\n this.ensureFile(compiler);\n\n this.federationRuntimeDependency = new FederationRuntimeDependency(\n this.entryFilePath,\n );\n return this.federationRuntimeDependency;\n }\n\n prependEntry(compiler: Compiler) {\n if (!this.options?.virtualRuntimeEntry) {\n this.ensureFile(compiler);\n }\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n FederationRuntimeDependency,\n normalModuleFactory,\n );\n compilation.dependencyTemplates.set(\n FederationRuntimeDependency,\n new ModuleDependency.Template(),\n );\n },\n );\n compiler.hooks.make.tapAsync(\n this.constructor.name,\n (compilation: Compilation, callback) => {\n const federationRuntimeDependency = this.getDependency(compiler);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n compilation.addInclude(\n compiler.context,\n federationRuntimeDependency,\n { name: undefined },\n (err) => {\n if (err) {\n return callback(err);\n }\n hooks.addFederationRuntimeDependency.call(\n federationRuntimeDependency,\n );\n callback();\n },\n );\n },\n );\n }\n\n injectRuntime(compiler: Compiler) {\n if (!this.options || !this.options.name) {\n return;\n }\n const name = this.options.name;\n const initOptionsWithoutShared = normalizeRuntimeInitOptionsWithOutShared(\n this.options,\n );\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation) => {\n const handler = (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (runtimeRequirements.has(federationGlobal)) return;\n runtimeRequirements.add(federationGlobal);\n runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);\n runtimeRequirements.add(RuntimeGlobals.moduleCache);\n runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);\n\n compilation.addRuntimeModule(\n chunk,\n new FederationRuntimeModule(\n runtimeRequirements,\n name,\n initOptionsWithoutShared,\n ),\n );\n };\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n this.constructor.name,\n (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (!chunk.hasRuntime()) return;\n if (runtimeRequirements.has(RuntimeGlobals.initializeSharing))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.currentRemoteGetScope))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.shareScopeMap)) return;\n if (runtimeRequirements.has(federationGlobal)) return;\n handler(chunk, runtimeRequirements);\n },\n );\n\n // if federation runtime requirements exist\n // attach runtime module to the chunk\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.initializeSharing)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.currentRemoteGetScope)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.shareScopeMap)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(federationGlobal)\n .tap(this.constructor.name, handler);\n },\n );\n }\n\n getRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n\n const resolvedPaths = resolveRuntimePaths(implementation);\n\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n\n if (alias['@module-federation/runtime$']) {\n this.runtimePath = alias['@module-federation/runtime$'];\n return this.runtimePath;\n }\n\n this.runtimePath = resolvedPaths.runtimePath;\n\n return this.runtimePath;\n }\n\n setRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n const runtimePath = this.getRuntimeAlias(compiler);\n alias['@module-federation/runtime$'] =\n alias['@module-federation/runtime$'] || runtimePath;\n alias['@module-federation/runtime-tools$'] =\n alias['@module-federation/runtime-tools$'] ||\n implementation ||\n this.runtimeToolsPath;\n\n // Set up aliases for the federation runtime and tools\n // This ensures that the correct versions are used throughout the project\n compiler.options.resolve.alias = alias;\n }\n\n apply(compiler: Compiler) {\n const useSharedContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'SharedContainerPlugin';\n },\n );\n // share container plugin should not inject mf runtime\n if (useSharedContainerPlugin) {\n return;\n }\n const useModuleFederationPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'ModuleFederationPlugin';\n },\n );\n\n if (useModuleFederationPlugin && !this.options) {\n this.options = useModuleFederationPlugin._options;\n }\n\n const useContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ContainerPlugin';\n },\n );\n\n if (useContainerPlugin && !this.options) {\n this.options = useContainerPlugin._options;\n }\n\n if (!useContainerPlugin && !useModuleFederationPlugin) {\n this.options = {\n remotes: {},\n ...this.options,\n };\n }\n if (this.options && !this.options?.name) {\n //! the instance may get the same one if the name is the same https://github.com/module-federation/core/blob/main/packages/runtime/src/index.ts#L18\n this.options.name =\n compiler.options.output.uniqueName || `container_${Date.now()}`;\n }\n\n const resolvedPaths = resolveRuntimePaths(this.options?.implementation);\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n this.runtimePath = resolvedPaths.runtimePath;\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n\n this.entryFilePath = this.getFilePath(compiler);\n\n new EmbedFederationRuntimePlugin().apply(compiler);\n\n new HoistContainerReferences().apply(compiler);\n\n // dont run multiple times on every apply()\n if (!onceForCompiler.has(compiler)) {\n this.prependEntry(compiler);\n this.injectRuntime(compiler);\n this.setRuntimeAlias(compiler);\n onceForCompiler.add(compiler);\n }\n }\n}\n\nexport default FederationRuntimePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAM,mBAAmB,gFACF,4CAA4C,CAClE;AAED,MAAM,EAAE,gBAAgB,aAAa,gFACd,UAAU,CAChC;AACD,MAA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IAExB,CAGC;EAEF,MAAM,4BAA4B,SAAS,QAAQ,QAAQ,MACxD,MAAuD;AACtD,OAAI,OAAO,MAAM,YAAY,CAAC,EAC5B,QAAO;AAET,UAAO,EAAE,YAAY;IAExB;AAED,MAAI,6BAA6B,CAAC,KAAK,QACrC,MAAK,UAAU,0BAA0B;EAG3C,MAAM,qBAAqB,SAAS,QAAQ,QAAQ,MACjD,MAAuD;AACtD,OAAI,OAAO,MAAM,YAAY,CAAC,EAC5B,QAAO;AAGT,UAAO,EAAE,YAAY;IAExB;AAED,MAAI,sBAAsB,CAAC,KAAK,QAC9B,MAAK,UAAU,mBAAmB;AAGpC,MAAI,CAAC,sBAAsB,CAAC,0BAC1B,MAAK,UAAU;GACb,SAAS,EAAE;GACX,GAAG,KAAK;GACT;AAEH,MAAI,KAAK,WAAW,CAAC,KAAK,SAAS;;AAEjC,OAAK,QAAQ,OACX,SAAS,QAAQ,OAAO,cAAc,aAAa,KAAK,KAAK;EAGjE,MAAM,gBAAgB,oBAAoB,KAAK,SAAS,eAAe;AACvE,OAAK,qBAAqB,cAAc;AACxC,OAAK,cAAc,cAAc;AACjC,OAAK,mBAAmB,cAAc;AAEtC,OAAK,gBAAgB,KAAK,YAAY,SAAS;AAE/C,MAAIC,oEAA8B,CAAC,MAAM,SAAS;AAElD,MAAIC,8DAA0B,CAAC,MAAM,SAAS;AAG9C,MAAI,CAAC,gBAAgB,IAAI,SAAS,EAAE;AAClC,QAAK,aAAa,SAAS;AAC3B,QAAK,cAAc,SAAS;AAC5B,QAAK,gBAAgB,SAAS;AAC9B,mBAAgB,IAAI,SAAS"}
1
+ {"version":3,"file":"FederationRuntimePlugin.js","names":["getFederationGlobalScope","normalizeToPosixPath","createHash","TEMP_DIR","FederationRuntimeDependency","FederationModulesPlugin","normalizeRuntimeInitOptionsWithOutShared","FederationRuntimeModule","EmbedFederationRuntimePlugin","HoistContainerReferences"],"sources":["../../../../../src/lib/container/runtime/FederationRuntimePlugin.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\nimport type {\n Compiler,\n WebpackPluginInstance,\n Compilation,\n Chunk,\n} from 'webpack';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { moduleFederationPlugin } from '@module-federation/sdk';\nimport FederationRuntimeModule from './FederationRuntimeModule';\nimport {\n getFederationGlobalScope,\n normalizeRuntimeInitOptionsWithOutShared,\n createHash,\n normalizeToPosixPath,\n} from './utils';\nimport { TEMP_DIR } from '../constant';\nimport EmbedFederationRuntimePlugin from './EmbedFederationRuntimePlugin';\nimport FederationModulesPlugin from './FederationModulesPlugin';\nimport HoistContainerReferences from '../HoistContainerReferencesPlugin';\nimport FederationRuntimeDependency from './FederationRuntimeDependency';\n\nconst ModuleDependency = require(\n normalizeWebpackPath('webpack/lib/dependencies/ModuleDependency'),\n) as typeof import('webpack/lib/dependencies/ModuleDependency');\n\nconst { RuntimeGlobals, Template } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { mkdirpSync } = require(\n normalizeWebpackPath('webpack/lib/util/fs'),\n) as typeof import('webpack/lib/util/fs');\n\ntype ResolveFn = typeof require.resolve;\ntype RuntimeEntrySpec = {\n bundler: string;\n esm: string;\n cjs: string;\n};\n\nfunction resolveRuntimeEntry(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n const candidates = [spec.bundler, spec.esm, spec.cjs];\n const modulePaths = implementation ? [implementation] : undefined;\n let lastError: unknown;\n\n for (const candidate of candidates) {\n try {\n return modulePaths\n ? resolve(candidate, { paths: modulePaths })\n : resolve(candidate);\n } catch (error) {\n lastError = error;\n }\n }\n\n throw lastError;\n}\n\nfunction resolveRuntimeEntryWithFallback(\n spec: RuntimeEntrySpec,\n implementation: string | undefined,\n resolve: ResolveFn = require.resolve,\n) {\n if (implementation) {\n try {\n return resolveRuntimeEntry(spec, implementation, resolve);\n } catch {\n // Fall back to the workspace runtime packages when a custom\n // implementation hasn't published the newer subpath yet.\n }\n }\n\n return resolveRuntimeEntry(spec, undefined, resolve);\n}\nexport function resolveRuntimePaths(\n implementation?: string,\n resolve: ResolveFn = require.resolve,\n) {\n // Prefer the dedicated bundler subpath so webpack can tree-shake across the\n // runtime package boundary. Fall back to the legacy dist contract for older\n // custom implementations that have not published /bundler yet.\n const runtimeToolsPath = resolveRuntimeEntryWithFallback(\n {\n bundler: '@module-federation/runtime-tools/bundler',\n esm: '@module-federation/runtime-tools/dist/index.js',\n cjs: '@module-federation/runtime-tools/dist/index.cjs',\n },\n implementation,\n resolve,\n );\n const moduleBase = implementation || runtimeToolsPath;\n\n return {\n runtimeToolsPath,\n bundlerRuntimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/webpack-bundler-runtime/bundler',\n esm: '@module-federation/webpack-bundler-runtime/dist/index.js',\n cjs: '@module-federation/webpack-bundler-runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n runtimePath: resolveRuntimeEntry(\n {\n bundler: '@module-federation/runtime/bundler',\n esm: '@module-federation/runtime/dist/index.js',\n cjs: '@module-federation/runtime/dist/index.cjs',\n },\n moduleBase,\n resolve,\n ),\n };\n}\n\nconst {\n runtimeToolsPath: RuntimeToolsPath,\n bundlerRuntimePath: BundlerRuntimePath,\n runtimePath: RuntimePath,\n} = resolveRuntimePaths();\nconst federationGlobal = getFederationGlobalScope(RuntimeGlobals);\n\nconst onceForCompiler = new WeakSet<Compiler>();\nconst onceForCompilerEntryMap = new WeakMap<Compiler, string>();\nconst fallbackWarnings = new WeakMap<Compiler, Set<string>>();\n\nfunction warn(compiler: Compiler, message: string) {\n let messages = fallbackWarnings.get(compiler);\n if (!messages) {\n messages = new Set();\n fallbackWarnings.set(compiler, messages);\n }\n messages.add(message);\n}\n\nfunction resolveRuntimePluginPath(compiler: Compiler, entry: string) {\n const fromContext = path.resolve(compiler.context, entry);\n if (path.isAbsolute(entry) || fs.existsSync(fromContext)) {\n return fromContext;\n }\n const fromCwd = path.resolve(entry);\n if (!fs.existsSync(fromCwd)) {\n return fromContext;\n }\n warn(\n compiler,\n `runtimePlugins entry ${JSON.stringify(entry)} was found relative to the working directory, not the compiler context ${compiler.context}. Relative runtimePlugins paths resolve against the context. Update the path; the working-directory fallback will be removed.`,\n );\n return fromCwd;\n}\n\nclass FederationRuntimePlugin {\n options?: moduleFederationPlugin.ModuleFederationPluginOptions;\n entryFilePath: string;\n bundlerRuntimePath: string;\n runtimePath: string;\n runtimeToolsPath: string;\n federationRuntimeDependency?: FederationRuntimeDependency; // Add this line\n\n constructor(options?: moduleFederationPlugin.ModuleFederationPluginOptions) {\n this.options = options ? { ...options } : undefined;\n this.entryFilePath = '';\n this.bundlerRuntimePath = BundlerRuntimePath;\n this.runtimePath = RuntimePath;\n this.runtimeToolsPath = RuntimeToolsPath;\n this.federationRuntimeDependency = undefined; // Initialize as undefined\n }\n\n static getTemplate(\n compiler: Compiler,\n options: moduleFederationPlugin.ModuleFederationPluginOptions,\n bundlerRuntimePath?: string,\n ) {\n // internal runtime plugin\n const runtimePlugins = options.runtimePlugins;\n const normalizedBundlerRuntimePath = normalizeToPosixPath(\n bundlerRuntimePath || BundlerRuntimePath,\n );\n\n let runtimePluginTemplates = '';\n const runtimePluginCalls: string[] = [];\n\n if (Array.isArray(runtimePlugins)) {\n runtimePlugins.forEach((runtimePlugin, index) => {\n if (!runtimePlugin) {\n return;\n }\n const runtimePluginName = `plugin_${index}`;\n const runtimePluginEntry = Array.isArray(runtimePlugin)\n ? runtimePlugin[0]\n : runtimePlugin;\n const runtimePluginPath = normalizeToPosixPath(\n resolveRuntimePluginPath(compiler, runtimePluginEntry),\n );\n const paramsStr =\n Array.isArray(runtimePlugin) && runtimePlugin.length > 1\n ? JSON.stringify(runtimePlugin[1])\n : 'undefined';\n runtimePluginTemplates += `import ${runtimePluginName} from ${JSON.stringify(runtimePluginPath)};\\n`;\n runtimePluginCalls.push(\n `${runtimePluginName} ? (${runtimePluginName}.default || ${runtimePluginName})(${paramsStr}) : false`,\n );\n });\n }\n const embedRuntimeLines = Template.asString([\n `if(!${federationGlobal}.runtime || !${federationGlobal}.bundlerRuntime){`,\n Template.indent([\n `var prevFederation = ${federationGlobal};`,\n `${federationGlobal} = {}`,\n `for(var key in federation){`,\n Template.indent([`${federationGlobal}[key] = federation[key];`]),\n '}',\n `for(var key in prevFederation){`,\n Template.indent([`${federationGlobal}[key] = prevFederation[key];`]),\n '}',\n ]),\n '}',\n ]);\n\n return Template.asString([\n `import federation from ${JSON.stringify(normalizedBundlerRuntimePath)};`,\n runtimePluginTemplates,\n embedRuntimeLines,\n `if(!${federationGlobal}.instance){`,\n Template.indent([\n runtimePluginCalls.length\n ? Template.asString([\n `var pluginsToAdd = [`,\n Template.indent(\n Template.indent(runtimePluginCalls.map((call) => `${call},`)),\n ),\n `].filter(Boolean);`,\n `${federationGlobal}.initOptions.plugins = ${federationGlobal}.initOptions.plugins ? `,\n `${federationGlobal}.initOptions.plugins.concat(pluginsToAdd) : pluginsToAdd;`,\n ])\n : '',\n // `${federationGlobal}.instance = ${federationGlobal}.runtime.init(${federationGlobal}.initOptions);`,\n `${federationGlobal}.instance = ${federationGlobal}.bundlerRuntime.init({webpackRequire:${RuntimeGlobals.require}});`,\n `if(${federationGlobal}.attachShareScopeMap){`,\n Template.indent([\n `${federationGlobal}.attachShareScopeMap(${RuntimeGlobals.require})`,\n ]),\n '}',\n `if(${federationGlobal}.installInitialConsumes){`,\n Template.indent([`${federationGlobal}.installInitialConsumes()`]),\n '}',\n ]),\n '}',\n ]);\n }\n\n getFilePath(compiler: Compiler) {\n if (!this.options) {\n return '';\n }\n\n const existedFilePath = onceForCompilerEntryMap.get(compiler);\n\n if (existedFilePath) {\n return existedFilePath;\n }\n\n let entryFilePath = '';\n if (!this.options?.virtualRuntimeEntry) {\n const containerName = this.options.name;\n const hash = createHash(\n `${containerName} ${FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n )}`,\n );\n entryFilePath = path.join(TEMP_DIR, `entry.${hash}.js`);\n } else {\n entryFilePath = `data:text/javascript;charset=utf-8;base64,${Buffer.from(\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n 'utf8',\n ).toString('base64')}`;\n }\n\n onceForCompilerEntryMap.set(compiler, entryFilePath);\n\n return entryFilePath;\n }\n\n ensureFile(compiler: Compiler) {\n if (!this.options) {\n return;\n }\n // skip virtual entry\n if (this.options?.virtualRuntimeEntry) {\n return;\n }\n const filePath = this.entryFilePath;\n const outputFs = (compiler as unknown as { outputFileSystem?: unknown })\n .outputFileSystem;\n const fsLike =\n outputFs &&\n typeof (outputFs as typeof fs).readFileSync === 'function' &&\n typeof (outputFs as typeof fs).writeFileSync === 'function'\n ? (outputFs as typeof fs)\n : fs;\n try {\n fsLike.readFileSync(filePath);\n } catch {\n mkdirpSync(fsLike as any, TEMP_DIR);\n fsLike.writeFileSync(\n filePath,\n FederationRuntimePlugin.getTemplate(\n compiler,\n this.options,\n this.bundlerRuntimePath,\n ),\n );\n }\n }\n\n getDependency(compiler: Compiler) {\n if (this.federationRuntimeDependency)\n return this.federationRuntimeDependency;\n\n this.ensureFile(compiler);\n\n this.federationRuntimeDependency = new FederationRuntimeDependency(\n this.entryFilePath,\n );\n return this.federationRuntimeDependency;\n }\n\n prependEntry(compiler: Compiler) {\n if (!this.options?.virtualRuntimeEntry) {\n this.ensureFile(compiler);\n }\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation, { normalModuleFactory }) => {\n compilation.dependencyFactories.set(\n FederationRuntimeDependency,\n normalModuleFactory,\n );\n compilation.dependencyTemplates.set(\n FederationRuntimeDependency,\n new ModuleDependency.Template(),\n );\n },\n );\n compiler.hooks.make.tapAsync(\n this.constructor.name,\n (compilation: Compilation, callback) => {\n const federationRuntimeDependency = this.getDependency(compiler);\n const hooks = FederationModulesPlugin.getCompilationHooks(compilation);\n compilation.addInclude(\n compiler.context,\n federationRuntimeDependency,\n { name: undefined },\n (err) => {\n if (err) {\n return callback(err);\n }\n hooks.addFederationRuntimeDependency.call(\n federationRuntimeDependency,\n );\n callback();\n },\n );\n },\n );\n }\n\n injectRuntime(compiler: Compiler) {\n if (!this.options || !this.options.name) {\n return;\n }\n const name = this.options.name;\n const initOptionsWithoutShared = normalizeRuntimeInitOptionsWithOutShared(\n this.options,\n );\n const federationGlobal = getFederationGlobalScope(\n RuntimeGlobals || ({} as typeof RuntimeGlobals),\n );\n\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation) => {\n const handler = (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (runtimeRequirements.has(federationGlobal)) return;\n runtimeRequirements.add(federationGlobal);\n runtimeRequirements.add(RuntimeGlobals.interceptModuleExecution);\n runtimeRequirements.add(RuntimeGlobals.moduleCache);\n runtimeRequirements.add(RuntimeGlobals.compatGetDefaultExport);\n\n compilation.addRuntimeModule(\n chunk,\n new FederationRuntimeModule(\n runtimeRequirements,\n name,\n initOptionsWithoutShared,\n ),\n );\n };\n\n compilation.hooks.additionalTreeRuntimeRequirements.tap(\n this.constructor.name,\n (chunk: Chunk, runtimeRequirements: Set<string>) => {\n if (!chunk.hasRuntime()) return;\n if (runtimeRequirements.has(RuntimeGlobals.initializeSharing))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.currentRemoteGetScope))\n return;\n if (runtimeRequirements.has(RuntimeGlobals.shareScopeMap)) return;\n if (runtimeRequirements.has(federationGlobal)) return;\n handler(chunk, runtimeRequirements);\n },\n );\n\n // if federation runtime requirements exist\n // attach runtime module to the chunk\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.initializeSharing)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.currentRemoteGetScope)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(RuntimeGlobals.shareScopeMap)\n .tap(this.constructor.name, handler);\n compilation.hooks.runtimeRequirementInTree\n .for(federationGlobal)\n .tap(this.constructor.name, handler);\n },\n );\n }\n\n getRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n\n const resolvedPaths = resolveRuntimePaths(implementation);\n\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n\n if (alias['@module-federation/runtime$']) {\n this.runtimePath = alias['@module-federation/runtime$'];\n return this.runtimePath;\n }\n\n this.runtimePath = resolvedPaths.runtimePath;\n\n return this.runtimePath;\n }\n\n setRuntimeAlias(compiler: Compiler) {\n const { implementation } = this.options || {};\n const alias: any = compiler.options.resolve.alias || {};\n const runtimePath = this.getRuntimeAlias(compiler);\n alias['@module-federation/runtime$'] =\n alias['@module-federation/runtime$'] || runtimePath;\n alias['@module-federation/runtime-tools$'] =\n alias['@module-federation/runtime-tools$'] ||\n implementation ||\n this.runtimeToolsPath;\n\n // Set up aliases for the federation runtime and tools\n // This ensures that the correct versions are used throughout the project\n compiler.options.resolve.alias = alias;\n }\n\n apply(compiler: Compiler) {\n const useSharedContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'SharedContainerPlugin';\n },\n );\n // share container plugin should not inject mf runtime\n if (useSharedContainerPlugin) {\n return;\n }\n const useModuleFederationPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n return p['name'] === 'ModuleFederationPlugin';\n },\n );\n\n if (useModuleFederationPlugin && !this.options) {\n this.options = useModuleFederationPlugin._options;\n }\n\n const useContainerPlugin = compiler.options.plugins.find(\n (p): p is WebpackPluginInstance & { _options?: any } => {\n if (typeof p !== 'object' || !p) {\n return false;\n }\n\n return p['name'] === 'ContainerPlugin';\n },\n );\n\n if (useContainerPlugin && !this.options) {\n this.options = useContainerPlugin._options;\n }\n\n if (!useContainerPlugin && !useModuleFederationPlugin) {\n this.options = {\n remotes: {},\n ...this.options,\n };\n }\n if (this.options && !this.options?.name) {\n //! the instance may get the same one if the name is the same https://github.com/module-federation/core/blob/main/packages/runtime/src/index.ts#L18\n this.options.name =\n compiler.options.output.uniqueName ||\n `container_${createHash(`${compiler.options.name ?? ''} ${compiler.context}`).slice(0, 8)}`;\n }\n\n const resolvedPaths = resolveRuntimePaths(this.options?.implementation);\n this.bundlerRuntimePath = resolvedPaths.bundlerRuntimePath;\n this.runtimePath = resolvedPaths.runtimePath;\n this.runtimeToolsPath = resolvedPaths.runtimeToolsPath;\n\n this.entryFilePath = this.getFilePath(compiler);\n\n new EmbedFederationRuntimePlugin().apply(compiler);\n\n new HoistContainerReferences().apply(compiler);\n\n // dont run multiple times on every apply()\n if (!onceForCompiler.has(compiler)) {\n this.prependEntry(compiler);\n this.injectRuntime(compiler);\n this.setRuntimeAlias(compiler);\n compiler.hooks.thisCompilation.tap(\n this.constructor.name,\n (compilation: Compilation) => {\n for (const message of fallbackWarnings.get(compiler) ?? []) {\n const warning = new compiler.webpack.WebpackError(message);\n warning.name = 'FederationRuntimePluginWarning';\n warning.hideStack = true;\n compilation.warnings.push(warning);\n }\n },\n );\n onceForCompiler.add(compiler);\n }\n }\n}\n\nexport default FederationRuntimePlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAM,mBAAmB,gFACF,4CAA4C,CAClE;AAED,MAAM,EAAE,gBAAgB,aAAa,gFACd,UAAU,CAChC;AACD,MAAM,EAAE,eAAe,gFACA,sBAAsB,CAC5C;AASD,SAAS,oBACP,MACA,gBACA,UAAqB,QAAQ,SAC7B;CACA,MAAM,aAAa;EAAC,KAAK;EAAS,KAAK;EAAK,KAAK;EAAI;CACrD,MAAM,cAAc,iBAAiB,CAAC,eAAe,GAAG;CACxD,IAAI;AAEJ,MAAK,MAAM,aAAa,WACtB,KAAI;AACF,SAAO,cACH,QAAQ,WAAW,EAAE,O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cAAc,SAAS;AAC5B,QAAK,gBAAgB,SAAS;AAC9B,YAAS,MAAM,gBAAgB,IAC7B,KAAK,YAAY,OAChB,gBAA6B;AAC5B,SAAK,MAAM,WAAW,iBAAiB,IAAI,SAAS,IAAI,EAAE,EAAE;KAC1D,MAAM,UAAU,IAAI,SAAS,QAAQ,aAAa,QAAQ;AAC1D,aAAQ,OAAO;AACf,aAAQ,YAAY;AACpB,iBAAY,SAAS,KAAK,QAAQ;;KAGvC;AACD,mBAAgB,IAAI,SAAS"}
@@ -0,0 +1,15 @@
1
+ import * as webpack_lib_util_makeSerializable0 from "webpack/lib/util/makeSerializable";
2
+
3
+ //#region src/lib/makeSerializable.d.ts
4
+ declare const webpackMakeSerializable: typeof webpack_lib_util_makeSerializable0;
5
+ /**
6
+ * Webpack's serializer registry is process-wide and throws on a duplicate key.
7
+ * Naming each registration after this copy's install directory lets two copies
8
+ * of enhanced (for example the app's and the one @module-federation/node
9
+ * depends on) share one webpack, and keeps each copy's cache entries restored
10
+ * by its own classes.
11
+ */
12
+ declare function makeSerializable(Constructor: Parameters<typeof webpackMakeSerializable>[0], request: string): void;
13
+ //#endregion
14
+ export { makeSerializable as default };
15
+ //# sourceMappingURL=makeSerializable.d.ts.map
@@ -0,0 +1,20 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('../_virtual/_rolldown/runtime.js');
3
+ let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
4
+
5
+ //#region src/lib/makeSerializable.ts
6
+ const webpackMakeSerializable = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/makeSerializable"));
7
+ /**
8
+ * Webpack's serializer registry is process-wide and throws on a duplicate key.
9
+ * Naming each registration after this copy's install directory lets two copies
10
+ * of enhanced (for example the app's and the one @module-federation/node
11
+ * depends on) share one webpack, and keeps each copy's cache entries restored
12
+ * by its own classes.
13
+ */
14
+ function makeSerializable(Constructor, request) {
15
+ webpackMakeSerializable(Constructor, request, __dirname);
16
+ }
17
+
18
+ //#endregion
19
+ exports.default = makeSerializable;
20
+ //# sourceMappingURL=makeSerializable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeSerializable.js","names":[],"sources":["../../../src/lib/makeSerializable.ts"],"sourcesContent":["import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\n\nconst webpackMakeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\n/**\n * Webpack's serializer registry is process-wide and throws on a duplicate key.\n * Naming each registration after this copy's install directory lets two copies\n * of enhanced (for example the app's and the one @module-federation/node\n * depends on) share one webpack, and keeps each copy's cache entries restored\n * by its own classes.\n */\nexport default function makeSerializable(\n Constructor: Parameters<typeof webpackMakeSerializable>[0],\n request: string,\n): void {\n webpackMakeSerializable(Constructor, request, __dirname);\n}\n"],"mappings":";;;;;AAEA,MAAM,0BAA0B,gFACT,oCAAoC,CAC1D;;;;;;;;AASD,SAAwB,iBACtB,aACA,SACM;AACN,yBAAwB,aAAa,SAAS,UAAU"}
@@ -2,10 +2,10 @@
2
2
 
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
  const require_runtime = require('../../_virtual/_rolldown/runtime.js');
5
+ const require_lib_makeSerializable = require('../makeSerializable.js');
5
6
  let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
6
7
 
7
8
  //#region src/lib/sharing/ConsumeSharedFallbackDependency.ts
8
- const makeSerializable = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/makeSerializable"));
9
9
  const { dependencies } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
10
10
  var ConsumeSharedFallbackDependency = class extends dependencies.ModuleDependency {
11
11
  /**
@@ -23,7 +23,7 @@ var ConsumeSharedFallbackDependency = class extends dependencies.ModuleDependenc
23
23
  return "esm";
24
24
  }
25
25
  };
26
- makeSerializable(ConsumeSharedFallbackDependency, "enhanced/lib/sharing/ConsumeSharedFallbackDependency");
26
+ require_lib_makeSerializable.default(ConsumeSharedFallbackDependency, "enhanced/lib/sharing/ConsumeSharedFallbackDependency");
27
27
 
28
28
  //#endregion
29
29
  exports.default = ConsumeSharedFallbackDependency;
@@ -1 +1 @@
1
- {"version":3,"file":"ConsumeSharedFallbackDependency.js","names":[],"sources":["../../../../src/lib/sharing/ConsumeSharedFallbackDependency.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\nconst { dependencies } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nclass ConsumeSharedFallbackDependency extends dependencies.ModuleDependency {\n layer?: string | null;\n\n /**\n * @param {string} request the request\n * @param {string | null} layer the layer for the fallback module\n */\n constructor(request: string, layer?: string | null) {\n super(request);\n this.layer = layer;\n }\n\n override get type(): string {\n return 'consume shared fallback';\n }\n\n override get category(): string {\n return 'esm';\n }\n}\n\nmakeSerializable(\n ConsumeSharedFallbackDependency,\n 'enhanced/lib/sharing/ConsumeSharedFallbackDependency',\n);\n\nexport default ConsumeSharedFallbackDependency;\n"],"mappings":";;;;;;;AAOA,MAAM,mBAAmB,gFACF,oCAAoC,CAC1D;AACD,MAAM,EAAE,iBAAiB,gFACF,UAAU,CAChC;AAED,IAAM,kCAAN,cAA8C,aAAa,iBAAiB;;;;;CAO1E,YAAY,SAAiB,OAAuB;AAClD,QAAM,QAAQ;AACd,OAAK,QAAQ;;CAGf,IAAa,OAAe;AAC1B,SAAO;;CAGT,IAAa,WAAmB;AAC9B,SAAO;;;AAIX,iBACE,iCACA,uDACD"}
1
+ {"version":3,"file":"ConsumeSharedFallbackDependency.js","names":["makeSerializable"],"sources":["../../../../src/lib/sharing/ConsumeSharedFallbackDependency.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport makeSerializable from '../makeSerializable';\nconst { dependencies } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\n\nclass ConsumeSharedFallbackDependency extends dependencies.ModuleDependency {\n layer?: string | null;\n\n /**\n * @param {string} request the request\n * @param {string | null} layer the layer for the fallback module\n */\n constructor(request: string, layer?: string | null) {\n super(request);\n this.layer = layer;\n }\n\n override get type(): string {\n return 'consume shared fallback';\n }\n\n override get category(): string {\n return 'esm';\n }\n}\n\nmakeSerializable(\n ConsumeSharedFallbackDependency,\n 'enhanced/lib/sharing/ConsumeSharedFallbackDependency',\n);\n\nexport default ConsumeSharedFallbackDependency;\n"],"mappings":";;;;;;;;AAQA,MAAM,EAAE,iBAAiB,gFACF,UAAU,CAChC;AAED,IAAM,kCAAN,cAA8C,aAAa,iBAAiB;;;;;CAO1E,YAAY,SAAiB,OAAuB;AAClD,QAAM,QAAQ;AACd,OAAK,QAAQ;;CAGf,IAAa,OAAe;AAC1B,SAAO;;CAGT,IAAa,WAAmB;AAC9B,SAAO;;;AAIXA,qCACE,iCACA,uDACD"}
@@ -3,22 +3,22 @@
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
  const require_runtime = require('../../_virtual/_rolldown/runtime.js');
5
5
  const require_lib_Constants = require('../Constants.js');
6
+ const require_lib_makeSerializable = require('../makeSerializable.js');
6
7
  const require_lib_sharing_utils = require('./utils.js');
7
8
  const require_lib_sharing_ConsumeSharedFallbackDependency = require('./ConsumeSharedFallbackDependency.js');
8
9
  let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
9
10
 
10
11
  //#region src/lib/sharing/ConsumeSharedModule.ts
11
- const { rangeToString, stringifyHoley } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/semver"));
12
+ const { stringifyHoley } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/semver"));
12
13
  const { AsyncDependenciesBlock, Module, RuntimeGlobals } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
13
14
  const { sources: webpackSources } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
14
- const makeSerializable = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/makeSerializable"));
15
15
  /**
16
16
  * @typedef {Object} ConsumeOptions
17
17
  * @property {string=} import fallback request
18
18
  * @property {string=} importResolved resolved fallback request
19
19
  * @property {string} shareKey global share key
20
20
  * @property {string} shareScope share scope
21
- * @property {SemVerRange | false | undefined} requiredVersion version requirement
21
+ * @property {string | false | undefined} requiredVersion version requirement
22
22
  * @property {string} packageName package name to determine required version automatically
23
23
  * @property {boolean} strictVersion don't use shared version even if version isn't valid
24
24
  * @property {boolean} singleton use single global version
@@ -45,7 +45,7 @@ var ConsumeSharedModule = class extends Module {
45
45
  */
46
46
  identifier() {
47
47
  const { shareKey, shareScope, importResolved, requiredVersion, strictVersion, singleton, eager, layer } = this.options;
48
- return `${require_lib_Constants.WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE}|${Array.isArray(shareScope) ? shareScope.join("|") : shareScope}|${shareKey}|${requiredVersion && rangeToString(requiredVersion)}|${strictVersion}|${importResolved}|${singleton}|${eager}|${layer}`;
48
+ return `${require_lib_Constants.WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE}|${Array.isArray(shareScope) ? shareScope.join("|") : shareScope}|${shareKey}|${requiredVersion}|${strictVersion}|${importResolved}|${singleton}|${eager}|${layer}`;
49
49
  }
50
50
  /**
51
51
  * @param {RequestShortener} requestShortener the request shortener
@@ -53,7 +53,7 @@ var ConsumeSharedModule = class extends Module {
53
53
  */
54
54
  readableIdentifier(requestShortener) {
55
55
  const { shareKey, shareScope, importResolved, requiredVersion, strictVersion, singleton, eager, layer } = this.options;
56
- return `consume shared module (${Array.isArray(shareScope) ? shareScope.join("|") : shareScope}) ${shareKey}@${requiredVersion ? rangeToString(requiredVersion) : "*"}${strictVersion ? " (strict)" : ""}${singleton ? " (singleton)" : ""}${importResolved ? ` (fallback: ${requestShortener.shorten(importResolved)})` : ""}${eager ? " (eager)" : ""}${layer ? ` (${layer})` : ""}`;
56
+ return `consume shared module (${Array.isArray(shareScope) ? shareScope.join("|") : shareScope}) ${shareKey}@${requiredVersion || "*"}${strictVersion ? " (strict)" : ""}${singleton ? " (singleton)" : ""}${importResolved ? ` (fallback: ${requestShortener.shorten(importResolved)})` : ""}${eager ? " (eager)" : ""}${layer ? ` (${layer})` : ""}`;
57
57
  }
58
58
  /**
59
59
  * @param {LibIdentOptions} options options
@@ -187,7 +187,7 @@ var ConsumeSharedModule = class extends Module {
187
187
  super.deserialize(context);
188
188
  }
189
189
  };
190
- makeSerializable(ConsumeSharedModule, "enhanced/lib/sharing/ConsumeSharedModule");
190
+ require_lib_makeSerializable.default(ConsumeSharedModule, "enhanced/lib/sharing/ConsumeSharedModule");
191
191
 
192
192
  //#endregion
193
193
  exports.default = ConsumeSharedModule;
@@ -1 +1 @@
1
- {"version":3,"file":"ConsumeSharedModule.js","names":["WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE","ConsumeSharedFallbackDependency","normalizeConsumeShareOptions"],"sources":["../../../../src/lib/sharing/ConsumeSharedModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type {\n WebpackOptions,\n Compilation,\n UpdateHashContext,\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n RequestShortener,\n ResolverWithOptions,\n WebpackError,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n Hash,\n InputFileSystem,\n} from 'webpack/lib/Module';\nimport ConsumeSharedFallbackDependency from './ConsumeSharedFallbackDependency';\nimport { normalizeConsumeShareOptions } from './utils';\nimport { WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE } from '../Constants';\nimport type { ConsumeOptions } from '@module-federation/sdk';\n\nconst { rangeToString, stringifyHoley } = require(\n normalizeWebpackPath('webpack/lib/util/semver'),\n) as typeof import('webpack/lib/util/semver');\nconst { AsyncDependenciesBlock, Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst makeSerializable = require(\n normalizeWebpackPath('webpack/lib/util/makeSerializable'),\n) as typeof import('webpack/lib/util/makeSerializable');\n\n/**\n * @typedef {Object} ConsumeOptions\n * @property {string=} import fallback request\n * @property {string=} importResolved resolved fallback request\n * @property {string} shareKey global share key\n * @property {string} shareScope share scope\n * @property {SemVerRange | false | undefined} requiredVersion version requirement\n * @property {string} packageName package name to determine required version automatically\n * @property {boolean} strictVersion don't use shared version even if version isn't valid\n * @property {boolean} singleton use single global version\n * @property {boolean} eager include the fallback module in a sync way\n * @property {string | null=} layer Share a specific layer of the module, if the module supports layers\n * @property {string | null=} issuerLayer Issuer layer in which the module should be resolved\n * @property {{ version?: string; fallbackVersion?: string }} exclude Options for excluding certain versions\n * @property {{ version?: string; fallbackVersion?: string }} include Options for including only certain versions\n */\n\nconst TYPES = new Set(['consume-shared']);\nconst JAVASCRIPT_TYPES = new Set(['javascript']);\n\nclass ConsumeSharedModule extends Module {\n options: ConsumeOptions;\n\n /**\n * @param {string} context context\n * @param {ConsumeOptions} options consume options\n */\n constructor(context: string, options: ConsumeOptions) {\n super(\n WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE,\n context,\n options?.layer ?? null,\n );\n this.layer = options?.layer ?? null;\n this.options = options;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n const {\n shareKey,\n shareScope,\n importResolved,\n requiredVersion,\n strictVersion,\n singleton,\n eager,\n layer,\n } = this.options;\n\n // Convert shareScope array to string for the identifier\n const normalizedShareScope = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n\n return `${WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE}|${normalizedShareScope}|${shareKey}|${\n requiredVersion && rangeToString(requiredVersion)\n }|${strictVersion}|${importResolved}|${singleton}|${eager}|${layer}`;\n }\n\n /**\n * @param {RequestShortener} requestShortener the request shortener\n * @returns {string} a user readable identifier of the module\n */\n override readableIdentifier(requestShortener: RequestShortener): string {\n const {\n shareKey,\n shareScope,\n importResolved,\n requiredVersion,\n strictVersion,\n singleton,\n eager,\n layer,\n } = this.options;\n const normalizedShareScope = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n\n return `consume shared module (${normalizedShareScope}) ${shareKey}@${\n requiredVersion ? rangeToString(requiredVersion) : '*'\n }${strictVersion ? ' (strict)' : ''}${singleton ? ' (singleton)' : ''}${\n importResolved\n ? ` (fallback: ${requestShortener.shorten(importResolved)})`\n : ''\n }${eager ? ' (eager)' : ''}${layer ? ` (${layer})` : ''}`;\n }\n\n /**\n * @param {LibIdentOptions} options options\n * @returns {string | null} an identifier for library inclusion\n */\n override libIdent(options: LibIdentOptions): string | null {\n const { shareKey, shareScope, import: request } = this.options;\n const normalizedShareScope = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n\n return `${\n this.layer ? `(${this.layer})/` : ''\n }webpack/sharing/consume/${normalizedShareScope}/${shareKey}${\n request ? `/${request}` : ''\n }`;\n }\n\n /**\n * @param {NeedBuildContext} context context info\n * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild\n * @returns {void}\n */\n override needBuild(\n context: NeedBuildContext,\n callback: (error?: WebpackError | null, needsRebuild?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\n\n /**\n * @param {WebpackOptions} options webpack options\n * @param {Compilation} compilation the compilation\n * @param {ResolverWithOptions} resolver the resolver\n * @param {InputFileSystem} fs the file system\n * @param {function(WebpackError=): void} callback callback function\n * @returns {void}\n */\n override build(\n options: WebpackOptions,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (error?: WebpackError) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {};\n if (this.options.import) {\n const dep = new ConsumeSharedFallbackDependency(\n this.options.import,\n this.options.layer,\n );\n if (this.options.eager) {\n this.addDependency(dep);\n } else {\n const block = new AsyncDependenciesBlock({});\n block.addDependency(dep);\n this.addBlock(block);\n }\n }\n callback();\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n override getSourceBasicTypes(): Set<string> {\n return JAVASCRIPT_TYPES;\n }\n\n /**\n * @param {string=} type the source type for which the size should be estimated\n * @returns {number} the estimated size of the module (must be non-zero)\n */\n override size(type?: string): number {\n return 42;\n }\n\n /**\n * @param {Hash} hash the hash used to track dependencies\n * @param {UpdateHashContext} context context\n * @returns {void}\n */\n override updateHash(hash: Hash, context: UpdateHashContext): void {\n hash.update(JSON.stringify(this.options));\n super.updateHash(hash, context);\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n override codeGeneration({\n chunkGraph,\n moduleGraph,\n runtimeTemplate,\n }: CodeGenerationContext): CodeGenerationResult {\n const runtimeRequirements = new Set([RuntimeGlobals.shareScopeMap]);\n const {\n shareScope,\n shareKey,\n strictVersion,\n requiredVersion,\n import: request,\n singleton,\n eager,\n } = this.options;\n let fallbackCode;\n if (request) {\n if (eager) {\n const dep = this.dependencies[0];\n fallbackCode = runtimeTemplate.syncModuleFactory({\n dependency: dep,\n chunkGraph,\n runtimeRequirements,\n request: this.options.import,\n });\n } else {\n const block = this.blocks[0];\n fallbackCode = runtimeTemplate.asyncModuleFactory({\n block,\n chunkGraph,\n runtimeRequirements,\n request: this.options.import,\n });\n }\n }\n let fn = 'load';\n const args = [JSON.stringify(shareScope), JSON.stringify(shareKey)];\n if (requiredVersion) {\n if (strictVersion) {\n fn += 'Strict';\n }\n if (singleton) {\n fn += 'Singleton';\n }\n args.push(stringifyHoley(requiredVersion));\n fn += 'VersionCheck';\n } else {\n if (singleton) {\n fn += 'Singleton';\n }\n }\n if (fallbackCode) {\n fn += 'Fallback';\n args.push(fallbackCode);\n }\n // const code = runtimeTemplate.returningFunction(`${fn}(${args.join(', ')})`);\n const sources = new Map();\n sources.set(\n 'consume-shared',\n new webpackSources.RawSource(\n fallbackCode ||\n `()=>()=>{throw new Error(\"Can not get '${shareKey}'\")}`,\n ),\n );\n\n const data = new Map();\n data.set('consume-shared', normalizeConsumeShareOptions(this.options));\n\n return {\n runtimeRequirements,\n sources,\n data,\n };\n }\n\n /**\n * @param {ObjectSerializerContext} context context\n */\n override serialize(context: ObjectSerializerContext): void {\n const { write } = context;\n write(this.options);\n write(this.layer);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n */\n override deserialize(context: ObjectDeserializerContext): void {\n const { read } = context;\n const options = read();\n const layer = read();\n this.options = options;\n this.layer = layer;\n super.deserialize(context);\n }\n}\n\nmakeSerializable(\n ConsumeSharedModule,\n 'enhanced/lib/sharing/ConsumeSharedModule',\n);\n\nexport default ConsumeSharedModule;\n"],"mappings":";;;;;;;;;;AA4BA,MAAM,EAAE,eAAe,mBAAmB,gFACnB,0BAA0B,CAChD;AACD,MAAM,EAAE,wBAAwB,QAAQ,mBAAmB,gFACpC,UAAU,CAChC;AACD,MAAM,EAAE,SAAS,m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;AACnE,MAAI,iBAAiB;AACnB,OAAI,cACF,OAAM;AAER,OAAI,UACF,OAAM;AAER,QAAK,KAAK,eAAe,gBAAgB,CAAC;AAC1C,SAAM;aAEF,UACF,OAAM;AAGV,MAAI,cAAc;AAChB,SAAM;AACN,QAAK,KAAK,aAAa;;EAGzB,MAAM,0BAAU,IAAI,KAAK;AACzB,UAAQ,IACN,kBACA,IAAI,eAAe,UACjB,gBACE,0CAA0C,SAAS,MACtD,CACF;EAED,MAAM,uBAAO,IAAI,KAAK;AACtB,OAAK,IAAI,kBAAkBC,uDAA6B,KAAK,QAAQ,CAAC;AAEtE,SAAO;GACL;GACA;GACA;GACD;;;;;CAMH,AAAS,UAAU,SAAwC;EACzD,MAAM,EAAE,UAAU;AAClB,QAAM,KAAK,QAAQ;AACnB,QAAM,KAAK,MAAM;AACjB,QAAM,UAAU,QAAQ;;;;;CAM1B,AAAS,YAAY,SAA0C;EAC7D,MAAM,EAAE,SAAS;EACjB,MAAM,UAAU,MAAM;EACtB,MAAM,QAAQ,MAAM;AACpB,OAAK,UAAU;AACf,OAAK,QAAQ;AACb,QAAM,YAAY,QAAQ;;;AAI9B,iBACE,qBACA,2CACD"}
1
+ {"version":3,"file":"ConsumeSharedModule.js","names":["WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE","ConsumeSharedFallbackDependency","normalizeConsumeShareOptions","makeSerializable"],"sources":["../../../../src/lib/sharing/ConsumeSharedModule.ts"],"sourcesContent":["/*\n\tMIT License http://www.opensource.org/licenses/mit-license.php\n\tAuthor Tobias Koppers @sokra, Zackary Jackson @ScriptedAlchemy\n*/\n\n'use strict';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport type {\n WebpackOptions,\n Compilation,\n UpdateHashContext,\n CodeGenerationContext,\n CodeGenerationResult,\n LibIdentOptions,\n NeedBuildContext,\n RequestShortener,\n ResolverWithOptions,\n WebpackError,\n ObjectDeserializerContext,\n ObjectSerializerContext,\n Hash,\n InputFileSystem,\n} from 'webpack/lib/Module';\nimport ConsumeSharedFallbackDependency from './ConsumeSharedFallbackDependency';\nimport { normalizeConsumeShareOptions } from './utils';\nimport { WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE } from '../Constants';\nimport type { ConsumeOptions } from '@module-federation/sdk';\n\nconst { stringifyHoley } = require(\n normalizeWebpackPath('webpack/lib/util/semver'),\n) as typeof import('webpack/lib/util/semver');\nconst { AsyncDependenciesBlock, Module, RuntimeGlobals } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nconst { sources: webpackSources } = require(\n normalizeWebpackPath('webpack'),\n) as typeof import('webpack');\nimport makeSerializable from '../makeSerializable';\n\n/**\n * @typedef {Object} ConsumeOptions\n * @property {string=} import fallback request\n * @property {string=} importResolved resolved fallback request\n * @property {string} shareKey global share key\n * @property {string} shareScope share scope\n * @property {string | false | undefined} requiredVersion version requirement\n * @property {string} packageName package name to determine required version automatically\n * @property {boolean} strictVersion don't use shared version even if version isn't valid\n * @property {boolean} singleton use single global version\n * @property {boolean} eager include the fallback module in a sync way\n * @property {string | null=} layer Share a specific layer of the module, if the module supports layers\n * @property {string | null=} issuerLayer Issuer layer in which the module should be resolved\n * @property {{ version?: string; fallbackVersion?: string }} exclude Options for excluding certain versions\n * @property {{ version?: string; fallbackVersion?: string }} include Options for including only certain versions\n */\n\nconst TYPES = new Set(['consume-shared']);\nconst JAVASCRIPT_TYPES = new Set(['javascript']);\n\nclass ConsumeSharedModule extends Module {\n options: ConsumeOptions;\n\n /**\n * @param {string} context context\n * @param {ConsumeOptions} options consume options\n */\n constructor(context: string, options: ConsumeOptions) {\n super(\n WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE,\n context,\n options?.layer ?? null,\n );\n this.layer = options?.layer ?? null;\n this.options = options;\n }\n\n /**\n * @returns {string} a unique identifier of the module\n */\n override identifier(): string {\n const {\n shareKey,\n shareScope,\n importResolved,\n requiredVersion,\n strictVersion,\n singleton,\n eager,\n layer,\n } = this.options;\n\n // Convert shareScope array to string for the identifier\n const normalizedShareScope = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n\n return `${WEBPACK_MODULE_TYPE_CONSUME_SHARED_MODULE}|${normalizedShareScope}|${shareKey}|${\n requiredVersion\n }|${strictVersion}|${importResolved}|${singleton}|${eager}|${layer}`;\n }\n\n /**\n * @param {RequestShortener} requestShortener the request shortener\n * @returns {string} a user readable identifier of the module\n */\n override readableIdentifier(requestShortener: RequestShortener): string {\n const {\n shareKey,\n shareScope,\n importResolved,\n requiredVersion,\n strictVersion,\n singleton,\n eager,\n layer,\n } = this.options;\n const normalizedShareScope = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n\n return `consume shared module (${normalizedShareScope}) ${shareKey}@${\n requiredVersion || '*'\n }${strictVersion ? ' (strict)' : ''}${singleton ? ' (singleton)' : ''}${\n importResolved\n ? ` (fallback: ${requestShortener.shorten(importResolved)})`\n : ''\n }${eager ? ' (eager)' : ''}${layer ? ` (${layer})` : ''}`;\n }\n\n /**\n * @param {LibIdentOptions} options options\n * @returns {string | null} an identifier for library inclusion\n */\n override libIdent(options: LibIdentOptions): string | null {\n const { shareKey, shareScope, import: request } = this.options;\n const normalizedShareScope = Array.isArray(shareScope)\n ? shareScope.join('|')\n : shareScope;\n\n return `${\n this.layer ? `(${this.layer})/` : ''\n }webpack/sharing/consume/${normalizedShareScope}/${shareKey}${\n request ? `/${request}` : ''\n }`;\n }\n\n /**\n * @param {NeedBuildContext} context context info\n * @param {function((WebpackError | null)=, boolean=): void} callback callback function, returns true, if the module needs a rebuild\n * @returns {void}\n */\n override needBuild(\n context: NeedBuildContext,\n callback: (error?: WebpackError | null, needsRebuild?: boolean) => void,\n ): void {\n callback(null, !this.buildInfo);\n }\n\n /**\n * @param {WebpackOptions} options webpack options\n * @param {Compilation} compilation the compilation\n * @param {ResolverWithOptions} resolver the resolver\n * @param {InputFileSystem} fs the file system\n * @param {function(WebpackError=): void} callback callback function\n * @returns {void}\n */\n override build(\n options: WebpackOptions,\n compilation: Compilation,\n resolver: ResolverWithOptions,\n fs: InputFileSystem,\n callback: (error?: WebpackError) => void,\n ): void {\n this.buildMeta = {};\n this.buildInfo = {};\n if (this.options.import) {\n const dep = new ConsumeSharedFallbackDependency(\n this.options.import,\n this.options.layer,\n );\n if (this.options.eager) {\n this.addDependency(dep);\n } else {\n const block = new AsyncDependenciesBlock({});\n block.addDependency(dep);\n this.addBlock(block);\n }\n }\n callback();\n }\n\n /**\n * @returns {Set<string>} types available (do not mutate)\n */\n override getSourceTypes(): Set<string> {\n return TYPES;\n }\n\n override getSourceBasicTypes(): Set<string> {\n return JAVASCRIPT_TYPES;\n }\n\n /**\n * @param {string=} type the source type for which the size should be estimated\n * @returns {number} the estimated size of the module (must be non-zero)\n */\n override size(type?: string): number {\n return 42;\n }\n\n /**\n * @param {Hash} hash the hash used to track dependencies\n * @param {UpdateHashContext} context context\n * @returns {void}\n */\n override updateHash(hash: Hash, context: UpdateHashContext): void {\n hash.update(JSON.stringify(this.options));\n super.updateHash(hash, context);\n }\n\n /**\n * @param {CodeGenerationContext} context context for code generation\n * @returns {CodeGenerationResult} result\n */\n override codeGeneration({\n chunkGraph,\n moduleGraph,\n runtimeTemplate,\n }: CodeGenerationContext): CodeGenerationResult {\n const runtimeRequirements = new Set([RuntimeGlobals.shareScopeMap]);\n const {\n shareScope,\n shareKey,\n strictVersion,\n requiredVersion,\n import: request,\n singleton,\n eager,\n } = this.options;\n let fallbackCode;\n if (request) {\n if (eager) {\n const dep = this.dependencies[0];\n fallbackCode = runtimeTemplate.syncModuleFactory({\n dependency: dep,\n chunkGraph,\n runtimeRequirements,\n request: this.options.import,\n });\n } else {\n const block = this.blocks[0];\n fallbackCode = runtimeTemplate.asyncModuleFactory({\n block,\n chunkGraph,\n runtimeRequirements,\n request: this.options.import,\n });\n }\n }\n let fn = 'load';\n const args = [JSON.stringify(shareScope), JSON.stringify(shareKey)];\n if (requiredVersion) {\n if (strictVersion) {\n fn += 'Strict';\n }\n if (singleton) {\n fn += 'Singleton';\n }\n args.push(stringifyHoley(requiredVersion));\n fn += 'VersionCheck';\n } else {\n if (singleton) {\n fn += 'Singleton';\n }\n }\n if (fallbackCode) {\n fn += 'Fallback';\n args.push(fallbackCode);\n }\n // const code = runtimeTemplate.returningFunction(`${fn}(${args.join(', ')})`);\n const sources = new Map();\n sources.set(\n 'consume-shared',\n new webpackSources.RawSource(\n fallbackCode ||\n `()=>()=>{throw new Error(\"Can not get '${shareKey}'\")}`,\n ),\n );\n\n const data = new Map();\n data.set('consume-shared', normalizeConsumeShareOptions(this.options));\n\n return {\n runtimeRequirements,\n sources,\n data,\n };\n }\n\n /**\n * @param {ObjectSerializerContext} context context\n */\n override serialize(context: ObjectSerializerContext): void {\n const { write } = context;\n write(this.options);\n write(this.layer);\n super.serialize(context);\n }\n\n /**\n * @param {ObjectDeserializerContext} context context\n */\n override deserialize(context: ObjectDeserializerContext): void {\n const { read } = context;\n const options = read();\n const layer = read();\n this.options = options;\n this.layer = layer;\n super.deserialize(context);\n }\n}\n\nmakeSerializable(\n ConsumeSharedModule,\n 'enhanced/lib/sharing/ConsumeSharedModule',\n);\n\nexport default ConsumeSharedModule;\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,EAAE,mBAAmB,gFACJ,0BAA0B,CAChD;AACD,MAAM,EAAE,wBAAwB,QAAQ,mBAAmB,gFACpC,UAAU,CAChC;AACD,MAAM,EAAE,SAAS,mBAAmB,gFACb,UAAU,CAChC;;;;;;;;;;;;;;;;;AAoBD,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC;AACzC,MAAM,mBAAmB,IAAI,IAAI,CAAC,aAAa,CAAC;AAEhD,IAAM,sBAAN,cAAkC,OAAO;;;;;CAOvC,YAAY,SAAiB,SAAyB;AACpD,QACEA,iEACA,SACA,SAAS,SAAS,KACnB;AACD,OAAK,QAAQ,SAAS,SAAS;AAC/B,OAAK,UAAU;;;;;CAMjB,AAAS,aAA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;;;;;CAMH,AAAS,UAAU,SAAwC;EACzD,MAAM,EAAE,UAAU;AAClB,QAAM,KAAK,QAAQ;AACnB,QAAM,KAAK,MAAM;AACjB,QAAM,UAAU,QAAQ;;;;;CAM1B,AAAS,YAAY,SAA0C;EAC7D,MAAM,EAAE,SAAS;EACjB,MAAM,UAAU,MAAM;EACtB,MAAM,QAAQ,MAAM;AACpB,OAAK,UAAU;AACf,OAAK,QAAQ;AACb,QAAM,YAAY,QAAQ;;;AAI9BC,qCACE,qBACA,2CACD"}
@@ -7,7 +7,7 @@ type ConsumeSharedPluginOptions = consumeSharedPlugin.ConsumeSharedPluginOptions
7
7
  declare class ConsumeSharedPlugin {
8
8
  private _consumes;
9
9
  constructor(options: ConsumeSharedPluginOptions);
10
- createConsumeSharedModule(compilation: Compilation, context: string, request: string, config: ConsumeOptions): Promise<ConsumeSharedModule>;
10
+ createConsumeSharedModule(compilation: Compilation, context: string, request: string, config: ConsumeOptions): Promise<ConsumeSharedModule | undefined>;
11
11
  apply(compiler: Compiler): void;
12
12
  }
13
13
  //#endregion
@@ -4,8 +4,6 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
4
4
  const require_runtime = require('../../_virtual/_rolldown/runtime.js');
5
5
  const require_lib_container_options = require('../container/options.js');
6
6
  const require_utils = require('../../utils.js');
7
- const require_schemas_sharing_ConsumeSharedPlugin_check = require('../../schemas/sharing/ConsumeSharedPlugin.check.js');
8
- const require_schemas_sharing_ConsumeSharedPlugin = require('../../schemas/sharing/ConsumeSharedPlugin.js');
9
7
  const require_lib_container_runtime_FederationRuntimePlugin = require('../container/runtime/FederationRuntimePlugin.js');
10
8
  const require_lib_sharing_resolveMatchedConfigs = require('./resolveMatchedConfigs.js');
11
9
  const require_lib_sharing_utils = require('./utils.js');
@@ -14,6 +12,8 @@ const require_lib_sharing_ConsumeSharedModule = require('./ConsumeSharedModule.j
14
12
  const require_lib_sharing_ConsumeSharedRuntimeModule = require('./ConsumeSharedRuntimeModule.js');
15
13
  const require_lib_sharing_ProvideForSharedDependency = require('./ProvideForSharedDependency.js');
16
14
  const require_lib_sharing_ShareRuntimeModule = require('./ShareRuntimeModule.js');
15
+ const require_schemas_sharing_ConsumeSharedPlugin_check = require('../../schemas/sharing/ConsumeSharedPlugin.check.js');
16
+ const require_schemas_sharing_ConsumeSharedPlugin = require('../../schemas/sharing/ConsumeSharedPlugin.js');
17
17
  let _module_federation_sdk = require("@module-federation/sdk");
18
18
  let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
19
19
  let path = require("path");
@@ -35,6 +35,11 @@ const validate = require_utils.createSchemaValidation((require_schemas_sharing_C
35
35
  });
36
36
  const RESOLVE_OPTIONS = { dependencyType: "esm" };
37
37
  const PLUGIN_NAME = "ConsumeSharedPlugin";
38
+ function getPackageVersion(fs, resource, packageName) {
39
+ return new Promise((resolve) => {
40
+ require_lib_sharing_utils.getDescriptionFile(fs, path.default.dirname(resource), ["package.json"], (err, result) => resolve(err ? void 0 : result?.data["version"]), (result) => !!result && typeof result.data["version"] === "string" && result.data["name"] === packageName);
41
+ });
42
+ }
38
43
  var ConsumeSharedPlugin = class {
39
44
  constructor(options) {
40
45
  if (typeof options !== "string") validate(options);
@@ -101,6 +106,7 @@ var ConsumeSharedPlugin = class {
101
106
  compilation.warnings.push(error);
102
107
  };
103
108
  const directFallback = config.import && DIRECT_FALLBACK_REGEX.test(config.import);
109
+ const packageName = config.packageName ?? (ABSOLUTE_PATH_REGEX.test(request) ? void 0 : PACKAGE_NAME_REGEX.exec(request)?.[0]);
104
110
  const resolver = compilation.resolverFactory.get("normal", RESOLVE_OPTIONS);
105
111
  return Promise.all([new Promise((resolve) => {
106
112
  if (!config.import) return resolve(void 0);
@@ -121,15 +127,9 @@ var ConsumeSharedPlugin = class {
121
127
  });
122
128
  }), new Promise((resolve) => {
123
129
  if (config.requiredVersion !== void 0) return resolve(config.requiredVersion);
124
- let packageName = config.packageName;
125
130
  if (packageName === void 0) {
126
- if (ABSOLUTE_PATH_REGEX.test(request)) return resolve(void 0);
127
- const match = PACKAGE_NAME_REGEX.exec(request);
128
- if (!match) {
129
- requiredVersionWarning("Unable to extract the package name from request.");
130
- return resolve(void 0);
131
- }
132
- packageName = match[0];
131
+ if (!ABSOLUTE_PATH_REGEX.test(request)) requiredVersionWarning("Unable to extract the package name from request.");
132
+ return resolve(void 0);
133
133
  }
134
134
  require_lib_sharing_utils.getDescriptionFile(compilation.inputFileSystem, context, ["package.json"], (err, result, checkedDescriptionFilePaths) => {
135
135
  if (err) {
@@ -162,40 +162,29 @@ var ConsumeSharedPlugin = class {
162
162
  requiredVersion
163
163
  };
164
164
  const consumedModule = new require_lib_sharing_ConsumeSharedModule.default(directFallback ? compilation.compiler.context : context, currentConfig);
165
- if (config.include && typeof config.include.version === "string") {
166
- if (!importResolved) return consumedModule;
167
- return new Promise((resolveFilter) => {
168
- require_lib_sharing_utils.getDescriptionFile(compilation.inputFileSystem, path.default.dirname(importResolved), ["package.json"], (err, result) => {
169
- if (err) return resolveFilter(consumedModule);
170
- const { data } = result || {};
171
- if (!data || !data["version"] || data["name"] !== request) return resolveFilter(consumedModule);
172
- if (config.include && satisfy(parseRange(config.include.version), data["version"])) {
173
- if (config.include && config.include.version && config.singleton) require_lib_sharing_utils.addSingletonFilterWarning(compilation, config.shareKey || request, "include", "version", config.include.version, request, importResolved);
174
- return resolveFilter(consumedModule);
175
- }
176
- if (config.include && typeof config.include.fallbackVersion === "string" && config.include.fallbackVersion) {
177
- if (satisfy(parseRange(config.include.version), config.include.fallbackVersion)) return resolveFilter(consumedModule);
178
- return resolveFilter(void 0);
179
- }
180
- return resolveFilter(void 0);
181
- });
165
+ const { include, exclude } = config;
166
+ if (include && typeof include.version === "string") {
167
+ if (!importResolved || packageName === void 0) return consumedModule;
168
+ const includeVersion = include.version;
169
+ return getPackageVersion(compilation.inputFileSystem, importResolved, packageName).then((version) => {
170
+ if (!version) return consumedModule;
171
+ if (satisfy(parseRange(includeVersion), version)) {
172
+ if (config.singleton) require_lib_sharing_utils.addSingletonFilterWarning(compilation, config.shareKey || request, "include", "version", includeVersion, request, importResolved);
173
+ return consumedModule;
174
+ }
175
+ if (typeof include.fallbackVersion === "string" && include.fallbackVersion && satisfy(parseRange(includeVersion), include.fallbackVersion)) return consumedModule;
182
176
  });
183
177
  }
184
- if (config.exclude && typeof config.exclude.version === "string") {
178
+ if (exclude && typeof exclude.version === "string") {
185
179
  if (!importResolved) return consumedModule;
186
- if (config.exclude && typeof config.exclude.fallbackVersion === "string" && config.exclude.fallbackVersion) {
187
- if (satisfy(parseRange(config.exclude.version), config.exclude.fallbackVersion)) return;
180
+ const excludeVersion = exclude.version;
181
+ if (typeof exclude.fallbackVersion === "string" && exclude.fallbackVersion) return satisfy(parseRange(excludeVersion), exclude.fallbackVersion) ? void 0 : consumedModule;
182
+ if (packageName === void 0) return consumedModule;
183
+ return getPackageVersion(compilation.inputFileSystem, importResolved, packageName).then((version) => {
184
+ if (!version) return consumedModule;
185
+ if (satisfy(parseRange(excludeVersion), version)) return;
186
+ if (config.singleton) require_lib_sharing_utils.addSingletonFilterWarning(compilation, config.shareKey || request, "exclude", "version", excludeVersion, request, importResolved);
188
187
  return consumedModule;
189
- }
190
- return new Promise((resolveFilter) => {
191
- require_lib_sharing_utils.getDescriptionFile(compilation.inputFileSystem, path.default.dirname(importResolved), ["package.json"], (err, result) => {
192
- if (err) return resolveFilter(consumedModule);
193
- const { data } = result || {};
194
- if (!data || !data["version"] || data["name"] !== request) return resolveFilter(consumedModule);
195
- if (config.exclude && typeof config.exclude.version === "string" && satisfy(parseRange(config.exclude.version), data["version"])) return resolveFilter(void 0);
196
- if (config.exclude && config.exclude.version && config.singleton) require_lib_sharing_utils.addSingletonFilterWarning(compilation, config.shareKey || request, "exclude", "version", config.exclude.version, request, importResolved);
197
- return resolveFilter(consumedModule);
198
- });
199
188
  });
200
189
  }
201
190
  return consumedModule;