@module-federation/webpack-bundler-runtime 2.0.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  2. package/dist/attachShareScopeMap.cjs +11 -0
  3. package/dist/attachShareScopeMap.cjs.map +1 -0
  4. package/dist/attachShareScopeMap.d.ts +7 -0
  5. package/dist/attachShareScopeMap.js +10 -0
  6. package/dist/attachShareScopeMap.js.map +1 -0
  7. package/dist/constant.cjs +8 -0
  8. package/dist/constant.cjs.map +1 -0
  9. package/dist/constant.d.ts +5 -1
  10. package/dist/constant.js +6 -0
  11. package/dist/constant.js.map +1 -0
  12. package/dist/consumes.cjs +55 -0
  13. package/dist/consumes.cjs.map +1 -0
  14. package/dist/consumes.js +55 -0
  15. package/dist/consumes.js.map +1 -0
  16. package/dist/getSharedFallbackGetter.cjs +27 -0
  17. package/dist/getSharedFallbackGetter.cjs.map +1 -0
  18. package/dist/getSharedFallbackGetter.js +26 -0
  19. package/dist/getSharedFallbackGetter.js.map +1 -0
  20. package/dist/getUsedExports.cjs +11 -0
  21. package/dist/getUsedExports.cjs.map +1 -0
  22. package/dist/getUsedExports.js +10 -0
  23. package/dist/getUsedExports.js.map +1 -0
  24. package/dist/index.cjs +50 -0
  25. package/dist/index.cjs.map +1 -0
  26. package/dist/index.d.ts +48 -2
  27. package/dist/index.js +36 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/init.cjs +82 -0
  30. package/dist/init.cjs.map +1 -0
  31. package/dist/init.js +80 -0
  32. package/dist/init.js.map +1 -0
  33. package/dist/initContainerEntry.cjs +43 -0
  34. package/dist/initContainerEntry.cjs.map +1 -0
  35. package/dist/initContainerEntry.d.ts +7 -0
  36. package/dist/initContainerEntry.js +42 -0
  37. package/dist/initContainerEntry.js.map +1 -0
  38. package/dist/initializeSharing.cjs +61 -0
  39. package/dist/initializeSharing.cjs.map +1 -0
  40. package/dist/initializeSharing.d.ts +13 -0
  41. package/dist/initializeSharing.js +61 -0
  42. package/dist/initializeSharing.js.map +1 -0
  43. package/dist/installInitialConsumes.cjs +63 -0
  44. package/dist/installInitialConsumes.cjs.map +1 -0
  45. package/dist/installInitialConsumes.js +63 -0
  46. package/dist/installInitialConsumes.js.map +1 -0
  47. package/dist/remotes.cjs +74 -0
  48. package/dist/remotes.cjs.map +1 -0
  49. package/dist/remotes.js +73 -0
  50. package/dist/remotes.js.map +1 -0
  51. package/dist/runtime-core/dist/core.d.ts +132 -0
  52. package/dist/runtime-core/dist/global.d.ts +25 -0
  53. package/dist/runtime-core/dist/helpers.d.ts +4 -0
  54. package/dist/runtime-core/dist/index.d.ts +15 -0
  55. package/dist/runtime-core/dist/module/index.d.ts +33 -0
  56. package/dist/runtime-core/dist/plugins/snapshot/SnapshotHandler.d.ts +68 -0
  57. package/dist/runtime-core/dist/remote/index.d.ts +121 -0
  58. package/dist/runtime-core/dist/shared/index.d.ts +85 -0
  59. package/dist/runtime-core/dist/type/config.d.ts +117 -0
  60. package/dist/runtime-core/dist/type/index.d.ts +3 -0
  61. package/dist/runtime-core/dist/type/plugin.d.ts +28 -0
  62. package/dist/runtime-core/dist/type/preload.d.ts +32 -0
  63. package/dist/runtime-core/dist/types.d.ts +4 -0
  64. package/dist/runtime-core/dist/utils/env.d.ts +1 -0
  65. package/dist/runtime-core/dist/utils/hooks/asyncHook.d.ts +11 -0
  66. package/dist/runtime-core/dist/utils/hooks/asyncWaterfallHooks.d.ts +13 -0
  67. package/dist/runtime-core/dist/utils/hooks/pluginSystem.d.ts +20 -0
  68. package/dist/runtime-core/dist/utils/hooks/syncHook.d.ts +17 -0
  69. package/dist/runtime-core/dist/utils/hooks/syncWaterfallHook.d.ts +12 -0
  70. package/dist/runtime-core/dist/utils/index.d.ts +2 -0
  71. package/dist/runtime-core/dist/utils/load.d.ts +16 -0
  72. package/dist/runtime-core/dist/utils/logger.d.ts +1 -0
  73. package/dist/runtime-core/dist/utils/manifest.d.ts +2 -0
  74. package/dist/runtime-core/dist/utils/plugin.d.ts +2 -0
  75. package/dist/runtime-core/dist/utils/preload.d.ts +4 -0
  76. package/dist/runtime-core/dist/utils/share.d.ts +3 -0
  77. package/dist/runtime-core/dist/utils/tool.d.ts +1 -0
  78. package/dist/sdk/dist/types/plugins/ModuleFederationPlugin.d.ts +13 -0
  79. package/dist/types.d.ts +201 -0
  80. package/dist/updateOptions.cjs +112 -0
  81. package/dist/updateOptions.cjs.map +1 -0
  82. package/dist/updateOptions.js +110 -0
  83. package/dist/updateOptions.js.map +1 -0
  84. package/package.json +9 -9
  85. package/dist/constant.cjs.cjs +0 -6
  86. package/dist/constant.cjs.cjs.map +0 -1
  87. package/dist/constant.cjs.d.ts +0 -1
  88. package/dist/constant.esm.js +0 -4
  89. package/dist/constant.esm.js.map +0 -1
  90. package/dist/index.cjs.cjs +0 -793
  91. package/dist/index.cjs.cjs.map +0 -1
  92. package/dist/index.cjs.d.ts +0 -2
  93. package/dist/index.esm.js +0 -772
  94. package/dist/index.esm.js.map +0 -1
  95. package/dist/src/attachShareScopeMap.d.ts +0 -2
  96. package/dist/src/constant.d.ts +0 -1
  97. package/dist/src/consumes.d.ts +0 -2
  98. package/dist/src/getSharedFallbackGetter.d.ts +0 -2
  99. package/dist/src/getUsedExports.d.ts +0 -2
  100. package/dist/src/index.d.ts +0 -39
  101. package/dist/src/init.d.ts +0 -4
  102. package/dist/src/initContainerEntry.d.ts +0 -2
  103. package/dist/src/initializeSharing.d.ts +0 -2
  104. package/dist/src/installInitialConsumes.d.ts +0 -2
  105. package/dist/src/remotes.d.ts +0 -2
  106. package/dist/src/types.d.ts +0 -194
  107. package/dist/src/updateOptions.d.ts +0 -3
@@ -0,0 +1,29 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
@@ -0,0 +1,11 @@
1
+
2
+ //#region src/attachShareScopeMap.ts
3
+ function attachShareScopeMap(webpackRequire) {
4
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) return;
5
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
6
+ webpackRequire.federation.hasAttachShareScopeMap = true;
7
+ }
8
+
9
+ //#endregion
10
+ exports.attachShareScopeMap = attachShareScopeMap;
11
+ //# sourceMappingURL=attachShareScopeMap.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachShareScopeMap.cjs","names":[],"sources":["../src/attachShareScopeMap.ts"],"sourcesContent":["import { WebpackRequire } from './types';\n\nexport function attachShareScopeMap(webpackRequire: WebpackRequire) {\n if (\n !webpackRequire.S ||\n webpackRequire.federation.hasAttachShareScopeMap ||\n !webpackRequire.federation.instance ||\n !webpackRequire.federation.instance.shareScopeMap\n ) {\n return;\n }\n\n webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;\n\n webpackRequire.federation.hasAttachShareScopeMap = true;\n}\n"],"mappings":";;AAEA,SAAgB,oBAAoB,gBAAgC;AAClE,KACE,CAAC,eAAe,KAChB,eAAe,WAAW,0BAC1B,CAAC,eAAe,WAAW,YAC3B,CAAC,eAAe,WAAW,SAAS,cAEpC;AAGF,gBAAe,IAAI,eAAe,WAAW,SAAS;AAEtD,gBAAe,WAAW,yBAAyB"}
@@ -0,0 +1,7 @@
1
+ import { WebpackRequire } from "./types.js";
2
+
3
+ //#region src/attachShareScopeMap.d.ts
4
+ declare function attachShareScopeMap(webpackRequire: WebpackRequire): void;
5
+ //#endregion
6
+ export { attachShareScopeMap };
7
+ //# sourceMappingURL=attachShareScopeMap.d.ts.map
@@ -0,0 +1,10 @@
1
+ //#region src/attachShareScopeMap.ts
2
+ function attachShareScopeMap(webpackRequire) {
3
+ if (!webpackRequire.S || webpackRequire.federation.hasAttachShareScopeMap || !webpackRequire.federation.instance || !webpackRequire.federation.instance.shareScopeMap) return;
4
+ webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;
5
+ webpackRequire.federation.hasAttachShareScopeMap = true;
6
+ }
7
+
8
+ //#endregion
9
+ export { attachShareScopeMap };
10
+ //# sourceMappingURL=attachShareScopeMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attachShareScopeMap.js","names":[],"sources":["../src/attachShareScopeMap.ts"],"sourcesContent":["import { WebpackRequire } from './types';\n\nexport function attachShareScopeMap(webpackRequire: WebpackRequire) {\n if (\n !webpackRequire.S ||\n webpackRequire.federation.hasAttachShareScopeMap ||\n !webpackRequire.federation.instance ||\n !webpackRequire.federation.instance.shareScopeMap\n ) {\n return;\n }\n\n webpackRequire.S = webpackRequire.federation.instance.shareScopeMap;\n\n webpackRequire.federation.hasAttachShareScopeMap = true;\n}\n"],"mappings":";AAEA,SAAgB,oBAAoB,gBAAgC;AAClE,KACE,CAAC,eAAe,KAChB,eAAe,WAAW,0BAC1B,CAAC,eAAe,WAAW,YAC3B,CAAC,eAAe,WAAW,SAAS,cAEpC;AAGF,gBAAe,IAAI,eAAe,WAAW,SAAS;AAEtD,gBAAe,WAAW,yBAAyB"}
@@ -0,0 +1,8 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+
3
+ //#region src/constant.ts
4
+ const FEDERATION_SUPPORTED_TYPES = ["script"];
5
+
6
+ //#endregion
7
+ exports.FEDERATION_SUPPORTED_TYPES = FEDERATION_SUPPORTED_TYPES;
8
+ //# sourceMappingURL=constant.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.cjs","names":[],"sources":["../src/constant.ts"],"sourcesContent":["export const FEDERATION_SUPPORTED_TYPES = ['script'];\n"],"mappings":";;;AAAA,MAAa,6BAA6B,CAAC,SAAS"}
@@ -1 +1,5 @@
1
- export * from "./src/constant";
1
+ //#region src/constant.d.ts
2
+ declare const FEDERATION_SUPPORTED_TYPES: string[];
3
+ //#endregion
4
+ export { FEDERATION_SUPPORTED_TYPES };
5
+ //# sourceMappingURL=constant.d.ts.map
@@ -0,0 +1,6 @@
1
+ //#region src/constant.ts
2
+ const FEDERATION_SUPPORTED_TYPES = ["script"];
3
+
4
+ //#endregion
5
+ export { FEDERATION_SUPPORTED_TYPES };
6
+ //# sourceMappingURL=constant.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constant.js","names":[],"sources":["../src/constant.ts"],"sourcesContent":["export const FEDERATION_SUPPORTED_TYPES = ['script'];\n"],"mappings":";AAAA,MAAa,6BAA6B,CAAC,SAAS"}
@@ -0,0 +1,55 @@
1
+ const require_attachShareScopeMap = require('./attachShareScopeMap.cjs');
2
+ const require_updateOptions = require('./updateOptions.cjs');
3
+ const require_getUsedExports = require('./getUsedExports.cjs');
4
+
5
+ //#region src/consumes.ts
6
+ function consumes(options) {
7
+ require_updateOptions.updateConsumeOptions(options);
8
+ const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping } = options;
9
+ require_attachShareScopeMap.attachShareScopeMap(webpackRequire);
10
+ if (webpackRequire.o(chunkMapping, chunkId)) chunkMapping[chunkId].forEach((id) => {
11
+ if (webpackRequire.o(installedModules, id)) return promises.push(installedModules[id]);
12
+ const onFactory = (factory) => {
13
+ installedModules[id] = 0;
14
+ webpackRequire.m[id] = (module) => {
15
+ delete webpackRequire.c[id];
16
+ const result = factory();
17
+ const { shareInfo } = moduleToHandlerMapping[id];
18
+ if (shareInfo?.shareConfig?.layer && result && typeof result === "object") try {
19
+ if (!result.hasOwnProperty("layer") || result.layer === void 0) result.layer = shareInfo.shareConfig.layer;
20
+ } catch (e) {}
21
+ module.exports = result;
22
+ };
23
+ };
24
+ const onError = (error) => {
25
+ delete installedModules[id];
26
+ webpackRequire.m[id] = (module) => {
27
+ delete webpackRequire.c[id];
28
+ throw error;
29
+ };
30
+ };
31
+ try {
32
+ const federationInstance = webpackRequire.federation.instance;
33
+ if (!federationInstance) throw new Error("Federation instance not found!");
34
+ const { shareKey, getter, shareInfo, treeShakingGetter } = moduleToHandlerMapping[id];
35
+ const usedExports = require_getUsedExports.getUsedExports(webpackRequire, shareKey);
36
+ const customShareInfo = { ...shareInfo };
37
+ if (usedExports) customShareInfo.treeShaking = {
38
+ usedExports,
39
+ useIn: [federationInstance.options.name]
40
+ };
41
+ const promise = federationInstance.loadShare(shareKey, { customShareInfo }).then((factory) => {
42
+ if (factory === false) return treeShakingGetter?.() || getter();
43
+ return factory;
44
+ });
45
+ if (promise.then) promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
46
+ else onFactory(promise);
47
+ } catch (e) {
48
+ onError(e);
49
+ }
50
+ });
51
+ }
52
+
53
+ //#endregion
54
+ exports.consumes = consumes;
55
+ //# sourceMappingURL=consumes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumes.cjs","names":["getUsedExports"],"sources":["../src/consumes.ts"],"sourcesContent":["import { ConsumesOptions } from './types';\nimport { attachShareScopeMap } from './attachShareScopeMap';\nimport { updateConsumeOptions } from './updateOptions';\nimport { getUsedExports } from './getUsedExports';\nimport type { Shared } from '@module-federation/runtime/types';\n\nexport function consumes(options: ConsumesOptions) {\n updateConsumeOptions(options);\n const {\n chunkId,\n promises,\n installedModules,\n webpackRequire,\n chunkMapping,\n moduleToHandlerMapping,\n } = options;\n\n attachShareScopeMap(webpackRequire);\n if (webpackRequire.o(chunkMapping, chunkId)) {\n chunkMapping[chunkId].forEach((id) => {\n if (webpackRequire.o(installedModules, id)) {\n return promises.push(installedModules[id] as Promise<any>);\n }\n const onFactory = (factory: () => any) => {\n installedModules[id] = 0;\n webpackRequire.m[id] = (module) => {\n delete webpackRequire.c[id];\n const result = factory();\n // Add layer property from shareConfig if available\n const { shareInfo } = moduleToHandlerMapping[id];\n if (\n shareInfo?.shareConfig?.layer &&\n result &&\n typeof result === 'object'\n ) {\n try {\n // Only set layer if it's not already defined or if it's undefined\n if (\n !result.hasOwnProperty('layer') ||\n (result as any).layer === undefined\n ) {\n (result as any).layer = shareInfo.shareConfig.layer;\n }\n } catch (e) {\n // Ignore if layer property is read-only\n }\n }\n module.exports = result;\n };\n };\n const onError = (error: unknown) => {\n delete installedModules[id];\n webpackRequire.m[id] = (module) => {\n delete webpackRequire.c[id];\n throw error;\n };\n };\n try {\n const federationInstance = webpackRequire.federation.instance;\n if (!federationInstance) {\n throw new Error('Federation instance not found!');\n }\n const { shareKey, getter, shareInfo, treeShakingGetter } =\n moduleToHandlerMapping[id];\n const usedExports = getUsedExports(webpackRequire, shareKey);\n const customShareInfo: Partial<Shared> = { ...shareInfo };\n if (usedExports) {\n customShareInfo.treeShaking = {\n usedExports,\n useIn: [federationInstance.options.name],\n };\n }\n const promise = federationInstance\n .loadShare(shareKey, {\n customShareInfo,\n })\n .then((factory: any) => {\n if (factory === false) {\n return treeShakingGetter?.() || getter();\n }\n return factory;\n });\n\n if (promise.then) {\n promises.push(\n (installedModules[id] = promise.then(onFactory).catch(onError)),\n );\n } else {\n // @ts-ignore maintain previous logic\n onFactory(promise);\n }\n } catch (e) {\n onError(e);\n }\n });\n }\n}\n"],"mappings":";;;;;AAMA,SAAgB,SAAS,SAA0B;AACjD,4CAAqB,QAAQ;CAC7B,MAAM,EACJ,SACA,UACA,kBACA,gBACA,cACA,2BACE;AAEJ,iDAAoB,eAAe;AACnC,KAAI,eAAe,EAAE,cAAc,QAAQ,CACzC,cAAa,SAAS,SAAS,OAAO;AACpC,MAAI,eAAe,EAAE,kBAAkB,GAAG,CACxC,QAAO,SAAS,KAAK,iBAAiB,IAAoB;EAE5D,MAAM,aAAa,YAAuB;AACxC,oBAAiB,MAAM;AACvB,kBAAe,EAAE,OAAO,WAAW;AACjC,WAAO,eAAe,EAAE;IACxB,MAAM,SAAS,SAAS;IAExB,MAAM,EAAE,cAAc,uBAAuB;AAC7C,QACE,WAAW,aAAa,SACxB,UACA,OAAO,WAAW,SAElB,KAAI;AAEF,SACE,CAAC,OAAO,eAAe,QAAQ,IAC9B,OAAe,UAAU,OAE1B,CAAC,OAAe,QAAQ,UAAU,YAAY;aAEzC,GAAG;AAId,WAAO,UAAU;;;EAGrB,MAAM,WAAW,UAAmB;AAClC,UAAO,iBAAiB;AACxB,kBAAe,EAAE,OAAO,WAAW;AACjC,WAAO,eAAe,EAAE;AACxB,UAAM;;;AAGV,MAAI;GACF,MAAM,qBAAqB,eAAe,WAAW;AACrD,OAAI,CAAC,mBACH,OAAM,IAAI,MAAM,iCAAiC;GAEnD,MAAM,EAAE,UAAU,QAAQ,WAAW,sBACnC,uBAAuB;GACzB,MAAM,cAAcA,sCAAe,gBAAgB,SAAS;GAC5D,MAAM,kBAAmC,EAAE,GAAG,WAAW;AACzD,OAAI,YACF,iBAAgB,cAAc;IAC5B;IACA,OAAO,CAAC,mBAAmB,QAAQ,KAAK;IACzC;GAEH,MAAM,UAAU,mBACb,UAAU,UAAU,EACnB,iBACD,CAAC,CACD,MAAM,YAAiB;AACtB,QAAI,YAAY,MACd,QAAO,qBAAqB,IAAI,QAAQ;AAE1C,WAAO;KACP;AAEJ,OAAI,QAAQ,KACV,UAAS,KACN,iBAAiB,MAAM,QAAQ,KAAK,UAAU,CAAC,MAAM,QAAQ,CAC/D;OAGD,WAAU,QAAQ;WAEb,GAAG;AACV,WAAQ,EAAE;;GAEZ"}
@@ -0,0 +1,55 @@
1
+ import { attachShareScopeMap } from "./attachShareScopeMap.js";
2
+ import { updateConsumeOptions } from "./updateOptions.js";
3
+ import { getUsedExports } from "./getUsedExports.js";
4
+
5
+ //#region src/consumes.ts
6
+ function consumes(options) {
7
+ updateConsumeOptions(options);
8
+ const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping } = options;
9
+ attachShareScopeMap(webpackRequire);
10
+ if (webpackRequire.o(chunkMapping, chunkId)) chunkMapping[chunkId].forEach((id) => {
11
+ if (webpackRequire.o(installedModules, id)) return promises.push(installedModules[id]);
12
+ const onFactory = (factory) => {
13
+ installedModules[id] = 0;
14
+ webpackRequire.m[id] = (module) => {
15
+ delete webpackRequire.c[id];
16
+ const result = factory();
17
+ const { shareInfo } = moduleToHandlerMapping[id];
18
+ if (shareInfo?.shareConfig?.layer && result && typeof result === "object") try {
19
+ if (!result.hasOwnProperty("layer") || result.layer === void 0) result.layer = shareInfo.shareConfig.layer;
20
+ } catch (e) {}
21
+ module.exports = result;
22
+ };
23
+ };
24
+ const onError = (error) => {
25
+ delete installedModules[id];
26
+ webpackRequire.m[id] = (module) => {
27
+ delete webpackRequire.c[id];
28
+ throw error;
29
+ };
30
+ };
31
+ try {
32
+ const federationInstance = webpackRequire.federation.instance;
33
+ if (!federationInstance) throw new Error("Federation instance not found!");
34
+ const { shareKey, getter, shareInfo, treeShakingGetter } = moduleToHandlerMapping[id];
35
+ const usedExports = getUsedExports(webpackRequire, shareKey);
36
+ const customShareInfo = { ...shareInfo };
37
+ if (usedExports) customShareInfo.treeShaking = {
38
+ usedExports,
39
+ useIn: [federationInstance.options.name]
40
+ };
41
+ const promise = federationInstance.loadShare(shareKey, { customShareInfo }).then((factory) => {
42
+ if (factory === false) return treeShakingGetter?.() || getter();
43
+ return factory;
44
+ });
45
+ if (promise.then) promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
46
+ else onFactory(promise);
47
+ } catch (e) {
48
+ onError(e);
49
+ }
50
+ });
51
+ }
52
+
53
+ //#endregion
54
+ export { consumes };
55
+ //# sourceMappingURL=consumes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumes.js","names":[],"sources":["../src/consumes.ts"],"sourcesContent":["import { ConsumesOptions } from './types';\nimport { attachShareScopeMap } from './attachShareScopeMap';\nimport { updateConsumeOptions } from './updateOptions';\nimport { getUsedExports } from './getUsedExports';\nimport type { Shared } from '@module-federation/runtime/types';\n\nexport function consumes(options: ConsumesOptions) {\n updateConsumeOptions(options);\n const {\n chunkId,\n promises,\n installedModules,\n webpackRequire,\n chunkMapping,\n moduleToHandlerMapping,\n } = options;\n\n attachShareScopeMap(webpackRequire);\n if (webpackRequire.o(chunkMapping, chunkId)) {\n chunkMapping[chunkId].forEach((id) => {\n if (webpackRequire.o(installedModules, id)) {\n return promises.push(installedModules[id] as Promise<any>);\n }\n const onFactory = (factory: () => any) => {\n installedModules[id] = 0;\n webpackRequire.m[id] = (module) => {\n delete webpackRequire.c[id];\n const result = factory();\n // Add layer property from shareConfig if available\n const { shareInfo } = moduleToHandlerMapping[id];\n if (\n shareInfo?.shareConfig?.layer &&\n result &&\n typeof result === 'object'\n ) {\n try {\n // Only set layer if it's not already defined or if it's undefined\n if (\n !result.hasOwnProperty('layer') ||\n (result as any).layer === undefined\n ) {\n (result as any).layer = shareInfo.shareConfig.layer;\n }\n } catch (e) {\n // Ignore if layer property is read-only\n }\n }\n module.exports = result;\n };\n };\n const onError = (error: unknown) => {\n delete installedModules[id];\n webpackRequire.m[id] = (module) => {\n delete webpackRequire.c[id];\n throw error;\n };\n };\n try {\n const federationInstance = webpackRequire.federation.instance;\n if (!federationInstance) {\n throw new Error('Federation instance not found!');\n }\n const { shareKey, getter, shareInfo, treeShakingGetter } =\n moduleToHandlerMapping[id];\n const usedExports = getUsedExports(webpackRequire, shareKey);\n const customShareInfo: Partial<Shared> = { ...shareInfo };\n if (usedExports) {\n customShareInfo.treeShaking = {\n usedExports,\n useIn: [federationInstance.options.name],\n };\n }\n const promise = federationInstance\n .loadShare(shareKey, {\n customShareInfo,\n })\n .then((factory: any) => {\n if (factory === false) {\n return treeShakingGetter?.() || getter();\n }\n return factory;\n });\n\n if (promise.then) {\n promises.push(\n (installedModules[id] = promise.then(onFactory).catch(onError)),\n );\n } else {\n // @ts-ignore maintain previous logic\n onFactory(promise);\n }\n } catch (e) {\n onError(e);\n }\n });\n }\n}\n"],"mappings":";;;;;AAMA,SAAgB,SAAS,SAA0B;AACjD,sBAAqB,QAAQ;CAC7B,MAAM,EACJ,SACA,UACA,kBACA,gBACA,cACA,2BACE;AAEJ,qBAAoB,eAAe;AACnC,KAAI,eAAe,EAAE,cAAc,QAAQ,CACzC,cAAa,SAAS,SAAS,OAAO;AACpC,MAAI,eAAe,EAAE,kBAAkB,GAAG,CACxC,QAAO,SAAS,KAAK,iBAAiB,IAAoB;EAE5D,MAAM,aAAa,YAAuB;AACxC,oBAAiB,MAAM;AACvB,kBAAe,EAAE,OAAO,WAAW;AACjC,WAAO,eAAe,EAAE;IACxB,MAAM,SAAS,SAAS;IAExB,MAAM,EAAE,cAAc,uBAAuB;AAC7C,QACE,WAAW,aAAa,SACxB,UACA,OAAO,WAAW,SAElB,KAAI;AAEF,SACE,CAAC,OAAO,eAAe,QAAQ,IAC9B,OAAe,UAAU,OAE1B,CAAC,OAAe,QAAQ,UAAU,YAAY;aAEzC,GAAG;AAId,WAAO,UAAU;;;EAGrB,MAAM,WAAW,UAAmB;AAClC,UAAO,iBAAiB;AACxB,kBAAe,EAAE,OAAO,WAAW;AACjC,WAAO,eAAe,EAAE;AACxB,UAAM;;;AAGV,MAAI;GACF,MAAM,qBAAqB,eAAe,WAAW;AACrD,OAAI,CAAC,mBACH,OAAM,IAAI,MAAM,iCAAiC;GAEnD,MAAM,EAAE,UAAU,QAAQ,WAAW,sBACnC,uBAAuB;GACzB,MAAM,cAAc,eAAe,gBAAgB,SAAS;GAC5D,MAAM,kBAAmC,EAAE,GAAG,WAAW;AACzD,OAAI,YACF,iBAAgB,cAAc;IAC5B;IACA,OAAO,CAAC,mBAAmB,QAAQ,KAAK;IACzC;GAEH,MAAM,UAAU,mBACb,UAAU,UAAU,EACnB,iBACD,CAAC,CACD,MAAM,YAAiB;AACtB,QAAI,YAAY,MACd,QAAO,qBAAqB,IAAI,QAAQ;AAE1C,WAAO;KACP;AAEJ,OAAI,QAAQ,KACV,UAAS,KACN,iBAAiB,MAAM,QAAQ,KAAK,UAAU,CAAC,MAAM,QAAQ,CAC/D;OAGD,WAAU,QAAQ;WAEb,GAAG;AACV,WAAQ,EAAE;;GAEZ"}
@@ -0,0 +1,27 @@
1
+
2
+ //#region src/getSharedFallbackGetter.ts
3
+ const getSharedFallbackGetter = ({ shareKey, factory, version, webpackRequire, libraryType = "global" }) => {
4
+ const { runtime, instance, bundlerRuntime, sharedFallback } = webpackRequire.federation;
5
+ if (!sharedFallback) return factory;
6
+ const fallbackItems = sharedFallback[shareKey];
7
+ if (!fallbackItems) return factory;
8
+ const fallbackItem = version ? fallbackItems.find((item) => item[1] === version) : fallbackItems[0];
9
+ if (!fallbackItem) throw new Error(`No fallback item found for shareKey: ${shareKey} and version: ${version}`);
10
+ return () => runtime.getRemoteEntry({
11
+ origin: webpackRequire.federation.instance,
12
+ remoteInfo: {
13
+ name: fallbackItem[2],
14
+ entry: `${webpackRequire.p}${fallbackItem[0]}`,
15
+ type: libraryType,
16
+ entryGlobalName: fallbackItem[2],
17
+ shareScope: "default"
18
+ }
19
+ }).then((shareEntry) => {
20
+ if (!shareEntry) throw new Error(`Failed to load fallback entry for shareKey: ${shareKey} and version: ${version}`);
21
+ return shareEntry.init(webpackRequire.federation.instance, bundlerRuntime).then(() => shareEntry.get());
22
+ });
23
+ };
24
+
25
+ //#endregion
26
+ exports.getSharedFallbackGetter = getSharedFallbackGetter;
27
+ //# sourceMappingURL=getSharedFallbackGetter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSharedFallbackGetter.cjs","names":[],"sources":["../src/getSharedFallbackGetter.ts"],"sourcesContent":["import type { GetSharedFallbackGetterOptions } from './types';\n\nexport const getSharedFallbackGetter = ({\n shareKey,\n factory,\n version,\n webpackRequire,\n libraryType = 'global',\n}: GetSharedFallbackGetterOptions) => {\n const { runtime, instance, bundlerRuntime, sharedFallback } =\n webpackRequire.federation!;\n if (!sharedFallback) {\n return factory;\n }\n // { react: [ [ react/19.0.0/index.js , 19.0.0, react_global_name, var ] ] }\n const fallbackItems = sharedFallback[shareKey];\n if (!fallbackItems) {\n return factory;\n }\n const fallbackItem = version\n ? fallbackItems.find((item) => item[1] === version)\n : fallbackItems[0];\n if (!fallbackItem) {\n throw new Error(\n `No fallback item found for shareKey: ${shareKey} and version: ${version}`,\n );\n }\n return () =>\n runtime!\n .getRemoteEntry({\n origin: webpackRequire.federation.instance!,\n remoteInfo: {\n name: fallbackItem[2],\n entry: `${webpackRequire.p}${fallbackItem[0]}`,\n type: libraryType,\n entryGlobalName: fallbackItem[2],\n // current not used\n shareScope: 'default',\n },\n })\n // @ts-ignore\n .then((shareEntry) => {\n if (!shareEntry) {\n throw new Error(\n `Failed to load fallback entry for shareKey: ${shareKey} and version: ${version}`,\n );\n }\n return (\n shareEntry\n // @ts-ignore\n .init(webpackRequire.federation.instance!, bundlerRuntime)\n // @ts-ignore\n .then(() => shareEntry.get())\n );\n });\n};\n"],"mappings":";;AAEA,MAAa,2BAA2B,EACtC,UACA,SACA,SACA,gBACA,cAAc,eACsB;CACpC,MAAM,EAAE,SAAS,UAAU,gBAAgB,mBACzC,eAAe;AACjB,KAAI,CAAC,eACH,QAAO;CAGT,MAAM,gBAAgB,eAAe;AACrC,KAAI,CAAC,cACH,QAAO;CAET,MAAM,eAAe,UACjB,cAAc,MAAM,SAAS,KAAK,OAAO,QAAQ,GACjD,cAAc;AAClB,KAAI,CAAC,aACH,OAAM,IAAI,MACR,wCAAwC,SAAS,gBAAgB,UAClE;AAEH,cACE,QACG,eAAe;EACd,QAAQ,eAAe,WAAW;EAClC,YAAY;GACV,MAAM,aAAa;GACnB,OAAO,GAAG,eAAe,IAAI,aAAa;GAC1C,MAAM;GACN,iBAAiB,aAAa;GAE9B,YAAY;GACb;EACF,CAAC,CAED,MAAM,eAAe;AACpB,MAAI,CAAC,WACH,OAAM,IAAI,MACR,+CAA+C,SAAS,gBAAgB,UACzE;AAEH,SACE,WAEG,KAAK,eAAe,WAAW,UAAW,eAAe,CAEzD,WAAW,WAAW,KAAK,CAAC;GAEjC"}
@@ -0,0 +1,26 @@
1
+ //#region src/getSharedFallbackGetter.ts
2
+ const getSharedFallbackGetter = ({ shareKey, factory, version, webpackRequire, libraryType = "global" }) => {
3
+ const { runtime, instance, bundlerRuntime, sharedFallback } = webpackRequire.federation;
4
+ if (!sharedFallback) return factory;
5
+ const fallbackItems = sharedFallback[shareKey];
6
+ if (!fallbackItems) return factory;
7
+ const fallbackItem = version ? fallbackItems.find((item) => item[1] === version) : fallbackItems[0];
8
+ if (!fallbackItem) throw new Error(`No fallback item found for shareKey: ${shareKey} and version: ${version}`);
9
+ return () => runtime.getRemoteEntry({
10
+ origin: webpackRequire.federation.instance,
11
+ remoteInfo: {
12
+ name: fallbackItem[2],
13
+ entry: `${webpackRequire.p}${fallbackItem[0]}`,
14
+ type: libraryType,
15
+ entryGlobalName: fallbackItem[2],
16
+ shareScope: "default"
17
+ }
18
+ }).then((shareEntry) => {
19
+ if (!shareEntry) throw new Error(`Failed to load fallback entry for shareKey: ${shareKey} and version: ${version}`);
20
+ return shareEntry.init(webpackRequire.federation.instance, bundlerRuntime).then(() => shareEntry.get());
21
+ });
22
+ };
23
+
24
+ //#endregion
25
+ export { getSharedFallbackGetter };
26
+ //# sourceMappingURL=getSharedFallbackGetter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getSharedFallbackGetter.js","names":[],"sources":["../src/getSharedFallbackGetter.ts"],"sourcesContent":["import type { GetSharedFallbackGetterOptions } from './types';\n\nexport const getSharedFallbackGetter = ({\n shareKey,\n factory,\n version,\n webpackRequire,\n libraryType = 'global',\n}: GetSharedFallbackGetterOptions) => {\n const { runtime, instance, bundlerRuntime, sharedFallback } =\n webpackRequire.federation!;\n if (!sharedFallback) {\n return factory;\n }\n // { react: [ [ react/19.0.0/index.js , 19.0.0, react_global_name, var ] ] }\n const fallbackItems = sharedFallback[shareKey];\n if (!fallbackItems) {\n return factory;\n }\n const fallbackItem = version\n ? fallbackItems.find((item) => item[1] === version)\n : fallbackItems[0];\n if (!fallbackItem) {\n throw new Error(\n `No fallback item found for shareKey: ${shareKey} and version: ${version}`,\n );\n }\n return () =>\n runtime!\n .getRemoteEntry({\n origin: webpackRequire.federation.instance!,\n remoteInfo: {\n name: fallbackItem[2],\n entry: `${webpackRequire.p}${fallbackItem[0]}`,\n type: libraryType,\n entryGlobalName: fallbackItem[2],\n // current not used\n shareScope: 'default',\n },\n })\n // @ts-ignore\n .then((shareEntry) => {\n if (!shareEntry) {\n throw new Error(\n `Failed to load fallback entry for shareKey: ${shareKey} and version: ${version}`,\n );\n }\n return (\n shareEntry\n // @ts-ignore\n .init(webpackRequire.federation.instance!, bundlerRuntime)\n // @ts-ignore\n .then(() => shareEntry.get())\n );\n });\n};\n"],"mappings":";AAEA,MAAa,2BAA2B,EACtC,UACA,SACA,SACA,gBACA,cAAc,eACsB;CACpC,MAAM,EAAE,SAAS,UAAU,gBAAgB,mBACzC,eAAe;AACjB,KAAI,CAAC,eACH,QAAO;CAGT,MAAM,gBAAgB,eAAe;AACrC,KAAI,CAAC,cACH,QAAO;CAET,MAAM,eAAe,UACjB,cAAc,MAAM,SAAS,KAAK,OAAO,QAAQ,GACjD,cAAc;AAClB,KAAI,CAAC,aACH,OAAM,IAAI,MACR,wCAAwC,SAAS,gBAAgB,UAClE;AAEH,cACE,QACG,eAAe;EACd,QAAQ,eAAe,WAAW;EAClC,YAAY;GACV,MAAM,aAAa;GACnB,OAAO,GAAG,eAAe,IAAI,aAAa;GAC1C,MAAM;GACN,iBAAiB,aAAa;GAE9B,YAAY;GACb;EACF,CAAC,CAED,MAAM,eAAe;AACpB,MAAI,CAAC,WACH,OAAM,IAAI,MACR,+CAA+C,SAAS,gBAAgB,UACzE;AAEH,SACE,WAEG,KAAK,eAAe,WAAW,UAAW,eAAe,CAEzD,WAAW,WAAW,KAAK,CAAC;GAEjC"}
@@ -0,0 +1,11 @@
1
+
2
+ //#region src/getUsedExports.ts
3
+ function getUsedExports(webpackRequire, sharedName) {
4
+ const usedExports = webpackRequire.federation.usedExports;
5
+ if (!usedExports) return;
6
+ return usedExports[sharedName];
7
+ }
8
+
9
+ //#endregion
10
+ exports.getUsedExports = getUsedExports;
11
+ //# sourceMappingURL=getUsedExports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedExports.cjs","names":[],"sources":["../src/getUsedExports.ts"],"sourcesContent":["import type { WebpackRequire } from './types';\n\nexport function getUsedExports(\n webpackRequire: WebpackRequire,\n sharedName: string,\n) {\n const usedExports = webpackRequire.federation.usedExports;\n if (!usedExports) {\n return;\n }\n\n return usedExports[sharedName];\n}\n"],"mappings":";;AAEA,SAAgB,eACd,gBACA,YACA;CACA,MAAM,cAAc,eAAe,WAAW;AAC9C,KAAI,CAAC,YACH;AAGF,QAAO,YAAY"}
@@ -0,0 +1,10 @@
1
+ //#region src/getUsedExports.ts
2
+ function getUsedExports(webpackRequire, sharedName) {
3
+ const usedExports = webpackRequire.federation.usedExports;
4
+ if (!usedExports) return;
5
+ return usedExports[sharedName];
6
+ }
7
+
8
+ //#endregion
9
+ export { getUsedExports };
10
+ //# sourceMappingURL=getUsedExports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getUsedExports.js","names":[],"sources":["../src/getUsedExports.ts"],"sourcesContent":["import type { WebpackRequire } from './types';\n\nexport function getUsedExports(\n webpackRequire: WebpackRequire,\n sharedName: string,\n) {\n const usedExports = webpackRequire.federation.usedExports;\n if (!usedExports) {\n return;\n }\n\n return usedExports[sharedName];\n}\n"],"mappings":";AAEA,SAAgB,eACd,gBACA,YACA;CACA,MAAM,cAAc,eAAe,WAAW;AAC9C,KAAI,CAAC,YACH;AAGF,QAAO,YAAY"}
package/dist/index.cjs ADDED
@@ -0,0 +1,50 @@
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ const require_attachShareScopeMap = require('./attachShareScopeMap.cjs');
4
+ const require_remotes = require('./remotes.cjs');
5
+ const require_consumes = require('./consumes.cjs');
6
+ const require_initializeSharing = require('./initializeSharing.cjs');
7
+ const require_installInitialConsumes = require('./installInitialConsumes.cjs');
8
+ const require_initContainerEntry = require('./initContainerEntry.cjs');
9
+ const require_init = require('./init.cjs');
10
+ const require_getSharedFallbackGetter = require('./getSharedFallbackGetter.cjs');
11
+ let _module_federation_runtime = require("@module-federation/runtime");
12
+ _module_federation_runtime = require_runtime.__toESM(_module_federation_runtime);
13
+
14
+ //#region src/index.ts
15
+ const federation = {
16
+ runtime: _module_federation_runtime,
17
+ instance: void 0,
18
+ initOptions: void 0,
19
+ bundlerRuntime: {
20
+ remotes: require_remotes.remotes,
21
+ consumes: require_consumes.consumes,
22
+ I: require_initializeSharing.initializeSharing,
23
+ S: {},
24
+ installInitialConsumes: require_installInitialConsumes.installInitialConsumes,
25
+ initContainerEntry: require_initContainerEntry.initContainerEntry,
26
+ init: require_init.init,
27
+ getSharedFallbackGetter: require_getSharedFallbackGetter.getSharedFallbackGetter
28
+ },
29
+ attachShareScopeMap: require_attachShareScopeMap.attachShareScopeMap,
30
+ bundlerRuntimeOptions: {}
31
+ };
32
+ const instance = federation.instance;
33
+ const initOptions = federation.initOptions;
34
+ const bundlerRuntime = federation.bundlerRuntime;
35
+ const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;
36
+
37
+ //#endregion
38
+ exports.attachShareScopeMap = require_attachShareScopeMap.attachShareScopeMap;
39
+ exports.bundlerRuntime = bundlerRuntime;
40
+ exports.bundlerRuntimeOptions = bundlerRuntimeOptions;
41
+ exports.default = federation;
42
+ exports.initOptions = initOptions;
43
+ exports.instance = instance;
44
+ Object.defineProperty(exports, 'runtime', {
45
+ enumerable: true,
46
+ get: function () {
47
+ return _module_federation_runtime;
48
+ }
49
+ });
50
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["initializeSharing"],"sources":["../src/index.ts"],"sourcesContent":["import * as runtime from '@module-federation/runtime';\nimport { Federation } from './types';\nimport { remotes } from './remotes';\nimport { consumes } from './consumes';\nimport { initializeSharing } from './initializeSharing';\nimport { installInitialConsumes } from './installInitialConsumes';\nimport { attachShareScopeMap } from './attachShareScopeMap';\nimport { initContainerEntry } from './initContainerEntry';\nimport { init } from './init';\nimport { getSharedFallbackGetter } from './getSharedFallbackGetter';\n\nexport * from './types';\n\nconst federation: Federation = {\n runtime,\n instance: undefined,\n initOptions: undefined,\n bundlerRuntime: {\n remotes,\n consumes,\n I: initializeSharing,\n S: {},\n installInitialConsumes,\n initContainerEntry,\n init,\n getSharedFallbackGetter,\n },\n attachShareScopeMap,\n bundlerRuntimeOptions: {},\n};\n\n// Keep CJS interop stable for consumers that iterate required keys directly.\nexport { runtime, attachShareScopeMap };\nexport const instance = federation.instance;\nexport const initOptions = federation.initOptions;\nexport const bundlerRuntime = federation.bundlerRuntime;\nexport const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;\n\nexport default federation;\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAM,aAAyB;CAC7B;CACA,UAAU;CACV,aAAa;CACb,gBAAgB;EACd;EACA;EACA,GAAGA;EACH,GAAG,EAAE;EACL;EACA;EACA;EACA;EACD;CACD;CACA,uBAAuB,EAAE;CAC1B;AAID,MAAa,WAAW,WAAW;AACnC,MAAa,cAAc,WAAW;AACtC,MAAa,iBAAiB,WAAW;AACzC,MAAa,wBAAwB,WAAW"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,48 @@
1
- export * from "./src/index";
2
- export { default } from "./src/index";
1
+ import { Remote, Shared, SharedGetter, UserOptions } from "./runtime-core/dist/type/config.js";
2
+ import "./runtime-core/dist/index.js";
3
+ import "./runtime-core/dist/types.js";
4
+ import { ExternalsType } from "./sdk/dist/types/plugins/ModuleFederationPlugin.js";
5
+ import { initializeSharing } from "./initializeSharing.js";
6
+ import { attachShareScopeMap } from "./attachShareScopeMap.js";
7
+ import { initContainerEntry } from "./initContainerEntry.js";
8
+ import { ConsumesLoadingData, ConsumesOptions, CoreRemotesOptions, Federation, GetSharedFallbackGetterOptions, HandleInitialConsumesOptions, IdToExternalAndNameMapping, IdToRemoteMap, IdToRemoteMapItem, InitContainerEntryOptions, InitializeSharingData, InitializeSharingOptions, InstallInitialConsumesOptions, ModuleId, ModuleIdToRemoteDataMapping, RemoteChunkMapping, RemoteDataItem, RemoteEntryExports, RemoteInfos, RemotesLoadingData, RemotesOptions, ShareScopeMap, WebpackRequire } from "./types.js";
9
+ import * as runtime from "@module-federation/runtime";
10
+
11
+ //#region src/index.d.ts
12
+ declare const federation: Federation;
13
+ declare const instance: runtime.ModuleFederation | undefined;
14
+ declare const initOptions: (Omit<UserOptions, "remotes"> & {
15
+ remotes: Array<Remote & {
16
+ externalType: ExternalsType;
17
+ }>;
18
+ }) | undefined;
19
+ declare const bundlerRuntime: {
20
+ remotes: (options: RemotesOptions) => void;
21
+ consumes: (options: ConsumesOptions) => void;
22
+ I: typeof initializeSharing;
23
+ S: {
24
+ [scope: string]: {
25
+ [pkgName: string]: {
26
+ [sharedVersion: string]: Shared;
27
+ };
28
+ };
29
+ };
30
+ installInitialConsumes: (options: InstallInitialConsumesOptions) => any;
31
+ initContainerEntry: typeof initContainerEntry;
32
+ init: ({
33
+ webpackRequire,
34
+ libraryType
35
+ }: {
36
+ webpackRequire: WebpackRequire;
37
+ libraryType: string;
38
+ }) => void;
39
+ getSharedFallbackGetter: (options: GetSharedFallbackGetterOptions) => SharedGetter;
40
+ } | undefined;
41
+ declare const bundlerRuntimeOptions: {
42
+ remotes?: Exclude<RemotesOptions, "chunkId" | "promises"> & {
43
+ remoteInfos?: RemoteInfos;
44
+ };
45
+ };
46
+ //#endregion
47
+ export { ConsumesLoadingData, ConsumesOptions, CoreRemotesOptions, Federation, GetSharedFallbackGetterOptions, HandleInitialConsumesOptions, IdToExternalAndNameMapping, IdToRemoteMap, IdToRemoteMapItem, InitContainerEntryOptions, InitializeSharingData, InitializeSharingOptions, InstallInitialConsumesOptions, ModuleId, ModuleIdToRemoteDataMapping, RemoteChunkMapping, RemoteDataItem, RemoteEntryExports, RemoteInfos, RemotesLoadingData, RemotesOptions, ShareScopeMap, WebpackRequire, attachShareScopeMap, bundlerRuntime, bundlerRuntimeOptions, federation as default, initOptions, instance, runtime };
48
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,36 @@
1
+ import { attachShareScopeMap } from "./attachShareScopeMap.js";
2
+ import { remotes } from "./remotes.js";
3
+ import { consumes } from "./consumes.js";
4
+ import { initializeSharing } from "./initializeSharing.js";
5
+ import { installInitialConsumes } from "./installInitialConsumes.js";
6
+ import { initContainerEntry } from "./initContainerEntry.js";
7
+ import { init } from "./init.js";
8
+ import { getSharedFallbackGetter } from "./getSharedFallbackGetter.js";
9
+ import * as runtime from "@module-federation/runtime";
10
+
11
+ //#region src/index.ts
12
+ const federation = {
13
+ runtime,
14
+ instance: void 0,
15
+ initOptions: void 0,
16
+ bundlerRuntime: {
17
+ remotes,
18
+ consumes,
19
+ I: initializeSharing,
20
+ S: {},
21
+ installInitialConsumes,
22
+ initContainerEntry,
23
+ init,
24
+ getSharedFallbackGetter
25
+ },
26
+ attachShareScopeMap,
27
+ bundlerRuntimeOptions: {}
28
+ };
29
+ const instance = federation.instance;
30
+ const initOptions = federation.initOptions;
31
+ const bundlerRuntime = federation.bundlerRuntime;
32
+ const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;
33
+
34
+ //#endregion
35
+ export { attachShareScopeMap, bundlerRuntime, bundlerRuntimeOptions, federation as default, initOptions, instance, runtime };
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import * as runtime from '@module-federation/runtime';\nimport { Federation } from './types';\nimport { remotes } from './remotes';\nimport { consumes } from './consumes';\nimport { initializeSharing } from './initializeSharing';\nimport { installInitialConsumes } from './installInitialConsumes';\nimport { attachShareScopeMap } from './attachShareScopeMap';\nimport { initContainerEntry } from './initContainerEntry';\nimport { init } from './init';\nimport { getSharedFallbackGetter } from './getSharedFallbackGetter';\n\nexport * from './types';\n\nconst federation: Federation = {\n runtime,\n instance: undefined,\n initOptions: undefined,\n bundlerRuntime: {\n remotes,\n consumes,\n I: initializeSharing,\n S: {},\n installInitialConsumes,\n initContainerEntry,\n init,\n getSharedFallbackGetter,\n },\n attachShareScopeMap,\n bundlerRuntimeOptions: {},\n};\n\n// Keep CJS interop stable for consumers that iterate required keys directly.\nexport { runtime, attachShareScopeMap };\nexport const instance = federation.instance;\nexport const initOptions = federation.initOptions;\nexport const bundlerRuntime = federation.bundlerRuntime;\nexport const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;\n\nexport default federation;\n"],"mappings":";;;;;;;;;;;AAaA,MAAM,aAAyB;CAC7B;CACA,UAAU;CACV,aAAa;CACb,gBAAgB;EACd;EACA;EACA,GAAG;EACH,GAAG,EAAE;EACL;EACA;EACA;EACA;EACD;CACD;CACA,uBAAuB,EAAE;CAC1B;AAID,MAAa,WAAW,WAAW;AACnC,MAAa,cAAc,WAAW;AACtC,MAAa,iBAAiB,WAAW;AACzC,MAAa,wBAAwB,WAAW"}
package/dist/init.cjs ADDED
@@ -0,0 +1,82 @@
1
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
2
+ let _module_federation_runtime = require("@module-federation/runtime");
3
+ let _module_federation_runtime_helpers = require("@module-federation/runtime/helpers");
4
+ _module_federation_runtime_helpers = require_runtime.__toESM(_module_federation_runtime_helpers);
5
+
6
+ //#region src/init.ts
7
+ function init({ webpackRequire }) {
8
+ const { initOptions, runtime, sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
9
+ if (!initOptions) throw new Error("initOptions is required!");
10
+ const treeShakingSharePlugin = function() {
11
+ return {
12
+ name: "tree-shake-plugin",
13
+ beforeInit(args) {
14
+ const { userOptions, origin, options: registeredOptions } = args;
15
+ const version = userOptions.version || registeredOptions.version;
16
+ if (!sharedFallback) return args;
17
+ const currentShared = userOptions.shared || {};
18
+ const shared = [];
19
+ Object.keys(currentShared).forEach((sharedName) => {
20
+ (Array.isArray(currentShared[sharedName]) ? currentShared[sharedName] : [currentShared[sharedName]]).forEach((sharedArg) => {
21
+ shared.push([sharedName, sharedArg]);
22
+ if ("get" in sharedArg) {
23
+ sharedArg.treeShaking ||= {};
24
+ sharedArg.treeShaking.get = sharedArg.get;
25
+ sharedArg.get = bundlerRuntime.getSharedFallbackGetter({
26
+ shareKey: sharedName,
27
+ factory: sharedArg.get,
28
+ webpackRequire,
29
+ libraryType,
30
+ version: sharedArg.version
31
+ });
32
+ }
33
+ });
34
+ });
35
+ const hostGlobalSnapshot = _module_federation_runtime_helpers.default.global.getGlobalSnapshotInfoByModuleInfo({
36
+ name: origin.name,
37
+ version
38
+ });
39
+ if (!hostGlobalSnapshot || !("shared" in hostGlobalSnapshot)) return args;
40
+ Object.keys(registeredOptions.shared || {}).forEach((pkgName) => {
41
+ registeredOptions.shared[pkgName].forEach((sharedArg) => {
42
+ shared.push([pkgName, sharedArg]);
43
+ });
44
+ });
45
+ const patchShared = (pkgName, shared) => {
46
+ const shareSnapshot = hostGlobalSnapshot.shared.find((item) => item.sharedName === pkgName);
47
+ if (!shareSnapshot) return;
48
+ const { treeShaking } = shared;
49
+ if (!treeShaking) return;
50
+ const { secondarySharedTreeShakingName, secondarySharedTreeShakingEntry, treeShakingStatus } = shareSnapshot;
51
+ if (treeShaking.status === treeShakingStatus) return;
52
+ treeShaking.status = treeShakingStatus;
53
+ if (secondarySharedTreeShakingEntry && libraryType && secondarySharedTreeShakingName) treeShaking.get = async () => {
54
+ const shareEntry = await (0, _module_federation_runtime.getRemoteEntry)({
55
+ origin,
56
+ remoteInfo: {
57
+ name: secondarySharedTreeShakingName,
58
+ entry: secondarySharedTreeShakingEntry,
59
+ type: libraryType,
60
+ entryGlobalName: secondarySharedTreeShakingName,
61
+ shareScope: "default"
62
+ }
63
+ });
64
+ await shareEntry.init(origin, __webpack_require__.federation.bundlerRuntime);
65
+ return shareEntry.get();
66
+ };
67
+ };
68
+ shared.forEach(([pkgName, sharedArg]) => {
69
+ patchShared(pkgName, sharedArg);
70
+ });
71
+ return args;
72
+ }
73
+ };
74
+ };
75
+ initOptions.plugins ||= [];
76
+ initOptions.plugins.push(treeShakingSharePlugin());
77
+ return runtime.init(initOptions);
78
+ }
79
+
80
+ //#endregion
81
+ exports.init = init;
82
+ //# sourceMappingURL=init.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.cjs","names":["helpers"],"sources":["../src/init.ts"],"sourcesContent":["import type { WebpackRequire } from './types';\nimport {\n getRemoteEntry,\n type ModuleFederationRuntimePlugin,\n} from '@module-federation/runtime';\nimport { ShareArgs } from '@module-federation/runtime/types';\nimport helpers from '@module-federation/runtime/helpers';\n\nexport function init({ webpackRequire }: { webpackRequire: WebpackRequire }) {\n const { initOptions, runtime, sharedFallback, bundlerRuntime, libraryType } =\n webpackRequire.federation;\n\n if (!initOptions) {\n throw new Error('initOptions is required!');\n }\n\n const treeShakingSharePlugin: () => ModuleFederationRuntimePlugin =\n function () {\n return {\n name: 'tree-shake-plugin',\n beforeInit(args) {\n const { userOptions, origin, options: registeredOptions } = args;\n const version = userOptions.version || registeredOptions.version;\n if (!sharedFallback) {\n return args;\n }\n\n const currentShared = userOptions.shared || {};\n const shared: Array<[pkgName: string, ShareArgs]> = [];\n\n Object.keys(currentShared).forEach((sharedName) => {\n const sharedArgs = Array.isArray(currentShared[sharedName])\n ? currentShared[sharedName]\n : [currentShared[sharedName]];\n sharedArgs.forEach((sharedArg) => {\n shared.push([sharedName, sharedArg]);\n if ('get' in sharedArg) {\n sharedArg.treeShaking ||= {};\n sharedArg.treeShaking.get = sharedArg.get;\n sharedArg.get = bundlerRuntime!.getSharedFallbackGetter({\n shareKey: sharedName,\n factory: sharedArg.get,\n webpackRequire,\n libraryType,\n version: sharedArg.version,\n });\n }\n });\n });\n\n // read snapshot to override re-shake getter\n const hostGlobalSnapshot =\n helpers.global.getGlobalSnapshotInfoByModuleInfo({\n name: origin.name,\n version: version,\n });\n if (!hostGlobalSnapshot || !('shared' in hostGlobalSnapshot)) {\n return args;\n }\n\n Object.keys(registeredOptions.shared || {}).forEach((pkgName) => {\n const sharedInfo = registeredOptions.shared[pkgName];\n sharedInfo.forEach((sharedArg) => {\n shared.push([pkgName, sharedArg]);\n });\n });\n\n const patchShared = (pkgName: string, shared: ShareArgs) => {\n const shareSnapshot = hostGlobalSnapshot.shared.find(\n (item) => item.sharedName === pkgName,\n );\n if (!shareSnapshot) {\n return;\n }\n const { treeShaking } = shared;\n if (!treeShaking) {\n return;\n }\n const {\n secondarySharedTreeShakingName,\n secondarySharedTreeShakingEntry,\n treeShakingStatus,\n } = shareSnapshot;\n if (treeShaking.status === treeShakingStatus) {\n return;\n }\n treeShaking.status = treeShakingStatus;\n if (\n secondarySharedTreeShakingEntry &&\n libraryType &&\n secondarySharedTreeShakingName\n ) {\n treeShaking.get = async () => {\n const shareEntry = await getRemoteEntry({\n origin,\n remoteInfo: {\n name: secondarySharedTreeShakingName,\n entry: secondarySharedTreeShakingEntry,\n type: libraryType,\n entryGlobalName: secondarySharedTreeShakingName,\n // current not used\n shareScope: 'default',\n },\n });\n // TODO: add errorLoad hook ?\n // @ts-ignore\n await shareEntry.init(\n origin,\n // @ts-ignore\n __webpack_require__.federation.bundlerRuntime,\n );\n // @ts-ignore\n const getter = shareEntry.get();\n return getter;\n };\n }\n };\n shared.forEach(([pkgName, sharedArg]) => {\n patchShared(pkgName, sharedArg);\n });\n\n return args;\n },\n };\n };\n\n initOptions.plugins ||= [];\n initOptions.plugins.push(treeShakingSharePlugin());\n return runtime!.init(initOptions);\n}\n"],"mappings":";;;;;;AAQA,SAAgB,KAAK,EAAE,kBAAsD;CAC3E,MAAM,EAAE,aAAa,SAAS,gBAAgB,gBAAgB,gBAC5D,eAAe;AAEjB,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,2BAA2B;CAG7C,MAAM,yBACJ,WAAY;AACV,SAAO;GACL,MAAM;GACN,WAAW,MAAM;IACf,MAAM,EAAE,aAAa,QAAQ,SAAS,sBAAsB;IAC5D,MAAM,UAAU,YAAY,WAAW,kBAAkB;AACzD,QAAI,CAAC,eACH,QAAO;IAGT,MAAM,gBAAgB,YAAY,UAAU,EAAE;IAC9C,MAAM,SAA8C,EAAE;AAEtD,WAAO,KAAK,cAAc,CAAC,SAAS,eAAe;AAIjD,MAHmB,MAAM,QAAQ,cAAc,YAAY,GACvD,cAAc,cACd,CAAC,cAAc,YAAY,EACpB,SAAS,cAAc;AAChC,aAAO,KAAK,CAAC,YAAY,UAAU,CAAC;AACpC,UAAI,SAAS,WAAW;AACtB,iBAAU,gBAAgB,EAAE;AAC5B,iBAAU,YAAY,MAAM,UAAU;AACtC,iBAAU,MAAM,eAAgB,wBAAwB;QACtD,UAAU;QACV,SAAS,UAAU;QACnB;QACA;QACA,SAAS,UAAU;QACpB,CAAC;;OAEJ;MACF;IAGF,MAAM,qBACJA,2CAAQ,OAAO,kCAAkC;KAC/C,MAAM,OAAO;KACJ;KACV,CAAC;AACJ,QAAI,CAAC,sBAAsB,EAAE,YAAY,oBACvC,QAAO;AAGT,WAAO,KAAK,kBAAkB,UAAU,EAAE,CAAC,CAAC,SAAS,YAAY;AAE/D,KADmB,kBAAkB,OAAO,SACjC,SAAS,cAAc;AAChC,aAAO,KAAK,CAAC,SAAS,UAAU,CAAC;OACjC;MACF;IAEF,MAAM,eAAe,SAAiB,WAAsB;KAC1D,MAAM,gBAAgB,mBAAmB,OAAO,MAC7C,SAAS,KAAK,eAAe,QAC/B;AACD,SAAI,CAAC,cACH;KAEF,MAAM,EAAE,gBAAgB;AACxB,SAAI,CAAC,YACH;KAEF,MAAM,EACJ,gCACA,iCACA,sBACE;AACJ,SAAI,YAAY,WAAW,kBACzB;AAEF,iBAAY,SAAS;AACrB,SACE,mCACA,eACA,+BAEA,aAAY,MAAM,YAAY;MAC5B,MAAM,aAAa,qDAAqB;OACtC;OACA,YAAY;QACV,MAAM;QACN,OAAO;QACP,MAAM;QACN,iBAAiB;QAEjB,YAAY;QACb;OACF,CAAC;AAGF,YAAM,WAAW,KACf,QAEA,oBAAoB,WAAW,eAChC;AAGD,aADe,WAAW,KAAK;;;AAKrC,WAAO,SAAS,CAAC,SAAS,eAAe;AACvC,iBAAY,SAAS,UAAU;MAC/B;AAEF,WAAO;;GAEV;;AAGL,aAAY,YAAY,EAAE;AAC1B,aAAY,QAAQ,KAAK,wBAAwB,CAAC;AAClD,QAAO,QAAS,KAAK,YAAY"}