@bleedingdev/mf-webpack-bundler-runtime 2.9.1

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +21 -0
  3. package/dist/LICENSE +21 -0
  4. package/dist/_virtual/_rolldown/runtime.cjs +29 -0
  5. package/dist/attachShareScopeMap.cjs +11 -0
  6. package/dist/attachShareScopeMap.cjs.map +1 -0
  7. package/dist/attachShareScopeMap.d.ts +7 -0
  8. package/dist/attachShareScopeMap.js +10 -0
  9. package/dist/attachShareScopeMap.js.map +1 -0
  10. package/dist/bundler.cjs +18 -0
  11. package/dist/bundler.d.ts +4 -0
  12. package/dist/bundler.js +4 -0
  13. package/dist/constant.cjs +8 -0
  14. package/dist/constant.cjs.map +1 -0
  15. package/dist/constant.d.ts +5 -0
  16. package/dist/constant.js +6 -0
  17. package/dist/constant.js.map +1 -0
  18. package/dist/consumes.cjs +68 -0
  19. package/dist/consumes.cjs.map +1 -0
  20. package/dist/consumes.js +68 -0
  21. package/dist/consumes.js.map +1 -0
  22. package/dist/error-codes/dist/error-codes.cjs +7 -0
  23. package/dist/error-codes/dist/error-codes.cjs.map +1 -0
  24. package/dist/error-codes/dist/error-codes.js +6 -0
  25. package/dist/error-codes/dist/error-codes.js.map +1 -0
  26. package/dist/error-codes/dist/getShortErrorMsg.cjs +16 -0
  27. package/dist/error-codes/dist/getShortErrorMsg.cjs.map +1 -0
  28. package/dist/error-codes/dist/getShortErrorMsg.js +15 -0
  29. package/dist/error-codes/dist/getShortErrorMsg.js.map +1 -0
  30. package/dist/getSharedFallbackGetter.cjs +27 -0
  31. package/dist/getSharedFallbackGetter.cjs.map +1 -0
  32. package/dist/getSharedFallbackGetter.js +26 -0
  33. package/dist/getSharedFallbackGetter.js.map +1 -0
  34. package/dist/getUsedExports.cjs +11 -0
  35. package/dist/getUsedExports.cjs.map +1 -0
  36. package/dist/getUsedExports.js +10 -0
  37. package/dist/getUsedExports.js.map +1 -0
  38. package/dist/index.cjs +52 -0
  39. package/dist/index.cjs.map +1 -0
  40. package/dist/index.d.ts +24 -0
  41. package/dist/index.js +38 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/init.cjs +85 -0
  44. package/dist/init.cjs.map +1 -0
  45. package/dist/init.js +83 -0
  46. package/dist/init.js.map +1 -0
  47. package/dist/initContainerEntry.cjs +42 -0
  48. package/dist/initContainerEntry.cjs.map +1 -0
  49. package/dist/initContainerEntry.d.ts +7 -0
  50. package/dist/initContainerEntry.js +41 -0
  51. package/dist/initContainerEntry.js.map +1 -0
  52. package/dist/initializeSharing.cjs +61 -0
  53. package/dist/initializeSharing.cjs.map +1 -0
  54. package/dist/initializeSharing.d.ts +13 -0
  55. package/dist/initializeSharing.js +61 -0
  56. package/dist/initializeSharing.js.map +1 -0
  57. package/dist/installInitialConsumes.cjs +75 -0
  58. package/dist/installInitialConsumes.cjs.map +1 -0
  59. package/dist/installInitialConsumes.js +75 -0
  60. package/dist/installInitialConsumes.js.map +1 -0
  61. package/dist/remotes.cjs +74 -0
  62. package/dist/remotes.cjs.map +1 -0
  63. package/dist/remotes.js +73 -0
  64. package/dist/remotes.js.map +1 -0
  65. package/dist/sdk/dist/types/plugins/ModuleFederationPlugin.d.ts +11 -0
  66. package/dist/types.d.ts +201 -0
  67. package/dist/updateOptions.cjs +112 -0
  68. package/dist/updateOptions.cjs.map +1 -0
  69. package/dist/updateOptions.js +110 -0
  70. package/dist/updateOptions.js.map +1 -0
  71. package/package.json +78 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # `@module-federation/webpack-bundler-runtime`
2
+
3
+ - Extract the build runtime and combine it with the internal runtime
4
+ - Used with webpack/rspack
5
+
6
+ ## Usage
7
+
8
+ The package needs to be used with webpack/rspack bundler. It will export federation object which includes runtime, instance, bundlerRuntime, initOptions, attachShareScopeMap, bundlerRuntimeOptions.
9
+
10
+ After referencing, mount it to the corresponding bundler runtime, and then use the corresponding api/instance.
11
+
12
+ - example
13
+
14
+ ```ts
15
+ import federation from '@module-federation/webpack-bundler-runtime';
16
+
17
+ __webpack_require__.federation = federation;
18
+
19
+ __webpack_require__.f.remotes = __webpack_require__.federation.remotes(options);
20
+ __webpack_require__.f.consumes = __webpack_require__.federation.remotes(options);
21
+ ```
package/dist/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present zhanghang(2heal1)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -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,18 @@
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_index = require('./index.cjs');
5
+ let _module_federation_runtime = require("@module-federation/runtime");
6
+
7
+ exports.attachShareScopeMap = require_attachShareScopeMap.attachShareScopeMap;
8
+ exports.bundlerRuntime = require_index.bundlerRuntime;
9
+ exports.bundlerRuntimeOptions = require_index.bundlerRuntimeOptions;
10
+ exports.default = require_index.default;
11
+ exports.initOptions = require_index.initOptions;
12
+ exports.instance = require_index.instance;
13
+ Object.defineProperty(exports, 'runtime', {
14
+ enumerable: true,
15
+ get: function () {
16
+ return _module_federation_runtime;
17
+ }
18
+ });
@@ -0,0 +1,4 @@
1
+ import { attachShareScopeMap } from "./attachShareScopeMap.js";
2
+ 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";
3
+ import federation, { bundlerRuntime, bundlerRuntimeOptions, initOptions, instance, runtime } from "./index.js";
4
+ 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 };
@@ -0,0 +1,4 @@
1
+ import { attachShareScopeMap } from "./attachShareScopeMap.js";
2
+ import federation, { bundlerRuntime, bundlerRuntimeOptions, initOptions, instance, runtime } from "./index.js";
3
+
4
+ export { attachShareScopeMap, bundlerRuntime, bundlerRuntimeOptions, federation as default, initOptions, instance, runtime };
@@ -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"}
@@ -0,0 +1,5 @@
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,68 @@
1
+ const require_attachShareScopeMap = require('./attachShareScopeMap.cjs');
2
+ const require_updateOptions = require('./updateOptions.cjs');
3
+ const require_getUsedExports = require('./getUsedExports.cjs');
4
+ const require_error_codes = require('./error-codes/dist/error-codes.cjs');
5
+ const require_getShortErrorMsg = require('./error-codes/dist/getShortErrorMsg.cjs');
6
+
7
+ //#region src/consumes.ts
8
+ function consumes(options) {
9
+ require_updateOptions.updateConsumeOptions(options);
10
+ const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping } = options;
11
+ require_attachShareScopeMap.attachShareScopeMap(webpackRequire);
12
+ if (webpackRequire.o(chunkMapping, chunkId)) chunkMapping[chunkId].forEach((id) => {
13
+ if (webpackRequire.o(installedModules, id)) return promises.push(installedModules[id]);
14
+ const onFactory = (factory) => {
15
+ installedModules[id] = 0;
16
+ webpackRequire.m[id] = (module) => {
17
+ delete webpackRequire.c[id];
18
+ const result = factory();
19
+ const { shareInfo } = moduleToHandlerMapping[id];
20
+ if (shareInfo?.shareConfig?.layer && result && typeof result === "object") try {
21
+ if (!result.hasOwnProperty("layer") || result.layer === void 0) result.layer = shareInfo.shareConfig.layer;
22
+ } catch (e) {}
23
+ module.exports = result;
24
+ };
25
+ };
26
+ const onError = (error) => {
27
+ delete installedModules[id];
28
+ webpackRequire.m[id] = (module) => {
29
+ delete webpackRequire.c[id];
30
+ throw error;
31
+ };
32
+ };
33
+ try {
34
+ const federationInstance = webpackRequire.federation.instance;
35
+ if (!federationInstance) throw new Error("Federation instance not found!");
36
+ const { shareKey, getter, shareInfo, treeShakingGetter } = moduleToHandlerMapping[id];
37
+ const usedExports = require_getUsedExports.getUsedExports(webpackRequire, shareKey);
38
+ const customShareInfo = { ...shareInfo };
39
+ if (Array.isArray(customShareInfo.scope) && Array.isArray(customShareInfo.scope[0])) customShareInfo.scope = customShareInfo.scope[0];
40
+ if (usedExports) customShareInfo.treeShaking = {
41
+ usedExports,
42
+ useIn: [federationInstance.options.name]
43
+ };
44
+ const promise = federationInstance.loadShare(shareKey, {
45
+ customShareInfo,
46
+ context: {
47
+ trigger: "build",
48
+ moduleId: id,
49
+ chunkId
50
+ }
51
+ }).then((factory) => {
52
+ if (factory === false) {
53
+ if (typeof getter !== "function") throw new Error(require_getShortErrorMsg.getShortErrorMsg(require_error_codes.RUNTIME_012, { [require_error_codes.RUNTIME_012]: "The getter for the shared module is not a function. This may be caused by setting \"shared.import: false\" without the host providing the corresponding lib." }, { shareKey }));
54
+ return treeShakingGetter?.() || getter();
55
+ }
56
+ return factory;
57
+ });
58
+ if (promise.then) promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
59
+ else onFactory(promise);
60
+ } catch (e) {
61
+ onError(e);
62
+ }
63
+ });
64
+ }
65
+
66
+ //#endregion
67
+ exports.consumes = consumes;
68
+ //# sourceMappingURL=consumes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consumes.cjs","names":["getUsedExports","getShortErrorMsg","RUNTIME_012"],"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';\nimport { getShortErrorMsg, RUNTIME_012 } from '@module-federation/error-codes';\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 // compatibility for rspack, which will wrap scope with array, but webpack will not\n // https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js#L95\n if (\n Array.isArray(customShareInfo.scope) &&\n Array.isArray(customShareInfo.scope[0])\n ) {\n customShareInfo.scope = customShareInfo.scope[0];\n }\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 context: {\n trigger: 'build',\n moduleId: id,\n chunkId,\n },\n })\n .then((factory: any) => {\n if (factory === false) {\n if (typeof getter !== 'function') {\n throw new Error(\n getShortErrorMsg(\n RUNTIME_012,\n {\n [RUNTIME_012]:\n 'The getter for the shared module is not a function. This may be caused by setting \"shared.import: false\" without the host providing the corresponding lib.',\n },\n { shareKey },\n ),\n );\n }\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":";;;;;;;AAOA,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;AAGzD,OACE,MAAM,QAAQ,gBAAgB,MAAM,IACpC,MAAM,QAAQ,gBAAgB,MAAM,GAAG,CAEvC,iBAAgB,QAAQ,gBAAgB,MAAM;AAEhD,OAAI,YACF,iBAAgB,cAAc;IAC5B;IACA,OAAO,CAAC,mBAAmB,QAAQ,KAAK;IACzC;GAEH,MAAM,UAAU,mBACb,UAAU,UAAU;IACnB;IACA,SAAS;KACP,SAAS;KACT,UAAU;KACV;KACD;IACF,CAAC,CACD,MAAM,YAAiB;AACtB,QAAI,YAAY,OAAO;AACrB,SAAI,OAAO,WAAW,WACpB,OAAM,IAAI,MACRC,0CACEC,iCACA,GACGA,kCACC,gKACH,EACD,EAAE,UAAU,CACb,CACF;AAEH,YAAO,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,68 @@
1
+ import { attachShareScopeMap } from "./attachShareScopeMap.js";
2
+ import { updateConsumeOptions } from "./updateOptions.js";
3
+ import { getUsedExports } from "./getUsedExports.js";
4
+ import { RUNTIME_012 } from "./error-codes/dist/error-codes.js";
5
+ import { getShortErrorMsg } from "./error-codes/dist/getShortErrorMsg.js";
6
+
7
+ //#region src/consumes.ts
8
+ function consumes(options) {
9
+ updateConsumeOptions(options);
10
+ const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping } = options;
11
+ attachShareScopeMap(webpackRequire);
12
+ if (webpackRequire.o(chunkMapping, chunkId)) chunkMapping[chunkId].forEach((id) => {
13
+ if (webpackRequire.o(installedModules, id)) return promises.push(installedModules[id]);
14
+ const onFactory = (factory) => {
15
+ installedModules[id] = 0;
16
+ webpackRequire.m[id] = (module) => {
17
+ delete webpackRequire.c[id];
18
+ const result = factory();
19
+ const { shareInfo } = moduleToHandlerMapping[id];
20
+ if (shareInfo?.shareConfig?.layer && result && typeof result === "object") try {
21
+ if (!result.hasOwnProperty("layer") || result.layer === void 0) result.layer = shareInfo.shareConfig.layer;
22
+ } catch (e) {}
23
+ module.exports = result;
24
+ };
25
+ };
26
+ const onError = (error) => {
27
+ delete installedModules[id];
28
+ webpackRequire.m[id] = (module) => {
29
+ delete webpackRequire.c[id];
30
+ throw error;
31
+ };
32
+ };
33
+ try {
34
+ const federationInstance = webpackRequire.federation.instance;
35
+ if (!federationInstance) throw new Error("Federation instance not found!");
36
+ const { shareKey, getter, shareInfo, treeShakingGetter } = moduleToHandlerMapping[id];
37
+ const usedExports = getUsedExports(webpackRequire, shareKey);
38
+ const customShareInfo = { ...shareInfo };
39
+ if (Array.isArray(customShareInfo.scope) && Array.isArray(customShareInfo.scope[0])) customShareInfo.scope = customShareInfo.scope[0];
40
+ if (usedExports) customShareInfo.treeShaking = {
41
+ usedExports,
42
+ useIn: [federationInstance.options.name]
43
+ };
44
+ const promise = federationInstance.loadShare(shareKey, {
45
+ customShareInfo,
46
+ context: {
47
+ trigger: "build",
48
+ moduleId: id,
49
+ chunkId
50
+ }
51
+ }).then((factory) => {
52
+ if (factory === false) {
53
+ if (typeof getter !== "function") throw new Error(getShortErrorMsg(RUNTIME_012, { [RUNTIME_012]: "The getter for the shared module is not a function. This may be caused by setting \"shared.import: false\" without the host providing the corresponding lib." }, { shareKey }));
54
+ return treeShakingGetter?.() || getter();
55
+ }
56
+ return factory;
57
+ });
58
+ if (promise.then) promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
59
+ else onFactory(promise);
60
+ } catch (e) {
61
+ onError(e);
62
+ }
63
+ });
64
+ }
65
+
66
+ //#endregion
67
+ export { consumes };
68
+ //# 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';\nimport { getShortErrorMsg, RUNTIME_012 } from '@module-federation/error-codes';\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 // compatibility for rspack, which will wrap scope with array, but webpack will not\n // https://github.com/web-infra-dev/rspack/blob/main/packages/rspack/src/runtime/moduleFederationDefaultRuntime.js#L95\n if (\n Array.isArray(customShareInfo.scope) &&\n Array.isArray(customShareInfo.scope[0])\n ) {\n customShareInfo.scope = customShareInfo.scope[0];\n }\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 context: {\n trigger: 'build',\n moduleId: id,\n chunkId,\n },\n })\n .then((factory: any) => {\n if (factory === false) {\n if (typeof getter !== 'function') {\n throw new Error(\n getShortErrorMsg(\n RUNTIME_012,\n {\n [RUNTIME_012]:\n 'The getter for the shared module is not a function. This may be caused by setting \"shared.import: false\" without the host providing the corresponding lib.',\n },\n { shareKey },\n ),\n );\n }\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":";;;;;;;AAOA,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;AAGzD,OACE,MAAM,QAAQ,gBAAgB,MAAM,IACpC,MAAM,QAAQ,gBAAgB,MAAM,GAAG,CAEvC,iBAAgB,QAAQ,gBAAgB,MAAM;AAEhD,OAAI,YACF,iBAAgB,cAAc;IAC5B;IACA,OAAO,CAAC,mBAAmB,QAAQ,KAAK;IACzC;GAEH,MAAM,UAAU,mBACb,UAAU,UAAU;IACnB;IACA,SAAS;KACP,SAAS;KACT,UAAU;KACV;KACD;IACF,CAAC,CACD,MAAM,YAAiB;AACtB,QAAI,YAAY,OAAO;AACrB,SAAI,OAAO,WAAW,WACpB,OAAM,IAAI,MACR,iBACE,aACA,GACG,cACC,gKACH,EACD,EAAE,UAAU,CACb,CACF;AAEH,YAAO,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,7 @@
1
+
2
+ //#region ../error-codes/dist/error-codes.mjs
3
+ const RUNTIME_012 = "RUNTIME-012";
4
+
5
+ //#endregion
6
+ exports.RUNTIME_012 = RUNTIME_012;
7
+ //# sourceMappingURL=error-codes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-codes.cjs","names":[],"sources":["../../../../error-codes/dist/error-codes.mjs"],"sourcesContent":["//#region src/error-codes.ts\nconst RUNTIME_001 = \"RUNTIME-001\";\nconst RUNTIME_002 = \"RUNTIME-002\";\nconst RUNTIME_003 = \"RUNTIME-003\";\nconst RUNTIME_004 = \"RUNTIME-004\";\nconst RUNTIME_005 = \"RUNTIME-005\";\nconst RUNTIME_006 = \"RUNTIME-006\";\nconst RUNTIME_007 = \"RUNTIME-007\";\nconst RUNTIME_008 = \"RUNTIME-008\";\nconst RUNTIME_009 = \"RUNTIME-009\";\nconst RUNTIME_010 = \"RUNTIME-010\";\nconst RUNTIME_011 = \"RUNTIME-011\";\nconst RUNTIME_012 = \"RUNTIME-012\";\nconst RUNTIME_013 = \"RUNTIME-013\";\nconst RUNTIME_014 = \"RUNTIME-014\";\nconst RUNTIME_015 = \"RUNTIME-015\";\nconst TYPE_001 = \"TYPE-001\";\nconst BUILD_001 = \"BUILD-001\";\nconst BUILD_002 = \"BUILD-002\";\n\n//#endregion\nexport { BUILD_001, BUILD_002, RUNTIME_001, RUNTIME_002, RUNTIME_003, RUNTIME_004, RUNTIME_005, RUNTIME_006, RUNTIME_007, RUNTIME_008, RUNTIME_009, RUNTIME_010, RUNTIME_011, RUNTIME_012, RUNTIME_013, RUNTIME_014, RUNTIME_015, TYPE_001 };\n//# sourceMappingURL=error-codes.mjs.map"],"mappings":";;AAYA,MAAM,cAAc"}
@@ -0,0 +1,6 @@
1
+ //#region ../error-codes/dist/error-codes.mjs
2
+ const RUNTIME_012 = "RUNTIME-012";
3
+
4
+ //#endregion
5
+ export { RUNTIME_012 };
6
+ //# sourceMappingURL=error-codes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error-codes.js","names":[],"sources":["../../../../error-codes/dist/error-codes.mjs"],"sourcesContent":["//#region src/error-codes.ts\nconst RUNTIME_001 = \"RUNTIME-001\";\nconst RUNTIME_002 = \"RUNTIME-002\";\nconst RUNTIME_003 = \"RUNTIME-003\";\nconst RUNTIME_004 = \"RUNTIME-004\";\nconst RUNTIME_005 = \"RUNTIME-005\";\nconst RUNTIME_006 = \"RUNTIME-006\";\nconst RUNTIME_007 = \"RUNTIME-007\";\nconst RUNTIME_008 = \"RUNTIME-008\";\nconst RUNTIME_009 = \"RUNTIME-009\";\nconst RUNTIME_010 = \"RUNTIME-010\";\nconst RUNTIME_011 = \"RUNTIME-011\";\nconst RUNTIME_012 = \"RUNTIME-012\";\nconst RUNTIME_013 = \"RUNTIME-013\";\nconst RUNTIME_014 = \"RUNTIME-014\";\nconst RUNTIME_015 = \"RUNTIME-015\";\nconst TYPE_001 = \"TYPE-001\";\nconst BUILD_001 = \"BUILD-001\";\nconst BUILD_002 = \"BUILD-002\";\n\n//#endregion\nexport { BUILD_001, BUILD_002, RUNTIME_001, RUNTIME_002, RUNTIME_003, RUNTIME_004, RUNTIME_005, RUNTIME_006, RUNTIME_007, RUNTIME_008, RUNTIME_009, RUNTIME_010, RUNTIME_011, RUNTIME_012, RUNTIME_013, RUNTIME_014, RUNTIME_015, TYPE_001 };\n//# sourceMappingURL=error-codes.mjs.map"],"mappings":";AAYA,MAAM,cAAc"}
@@ -0,0 +1,16 @@
1
+
2
+ //#region ../error-codes/dist/getShortErrorMsg.mjs
3
+ const getDocsUrl = (errorCode) => {
4
+ return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
5
+ };
6
+ const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
7
+ const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
8
+ args && msg.push(`args: ${JSON.stringify(args)}`);
9
+ msg.push(getDocsUrl(errorCode));
10
+ originalErrorMsg && msg.push(`Original Error Message:\n ${originalErrorMsg}`);
11
+ return msg.join("\n");
12
+ };
13
+
14
+ //#endregion
15
+ exports.getShortErrorMsg = getShortErrorMsg;
16
+ //# sourceMappingURL=getShortErrorMsg.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getShortErrorMsg.cjs","names":[],"sources":["../../../../error-codes/dist/getShortErrorMsg.mjs"],"sourcesContent":["//#region src/getShortErrorMsg.ts\nconst getDocsUrl = (errorCode) => {\n\treturn `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split(\"-\")[0].toLowerCase()}#${errorCode.toLowerCase()}`;\n};\nconst getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {\n\tconst msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];\n\targs && msg.push(`args: ${JSON.stringify(args)}`);\n\tmsg.push(getDocsUrl(errorCode));\n\toriginalErrorMsg && msg.push(`Original Error Message:\\n ${originalErrorMsg}`);\n\treturn msg.join(\"\\n\");\n};\n\n//#endregion\nexport { getShortErrorMsg };\n//# sourceMappingURL=getShortErrorMsg.mjs.map"],"mappings":";;AACA,MAAM,cAAc,cAAc;AACjC,QAAO,yFAAyF,UAAU,MAAM,IAAI,CAAC,GAAG,aAAa,CAAC,GAAG,UAAU,aAAa;;AAEjK,MAAM,oBAAoB,WAAW,cAAc,MAAM,qBAAqB;CAC7E,MAAM,MAAM,CAAC,GAAG,CAAC,aAAa,WAAW,CAAC,IAAI,YAAY;AAC1D,SAAQ,IAAI,KAAK,SAAS,KAAK,UAAU,KAAK,GAAG;AACjD,KAAI,KAAK,WAAW,UAAU,CAAC;AAC/B,qBAAoB,IAAI,KAAK,6BAA6B,mBAAmB;AAC7E,QAAO,IAAI,KAAK,KAAK"}
@@ -0,0 +1,15 @@
1
+ //#region ../error-codes/dist/getShortErrorMsg.mjs
2
+ const getDocsUrl = (errorCode) => {
3
+ return `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split("-")[0].toLowerCase()}#${errorCode.toLowerCase()}`;
4
+ };
5
+ const getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {
6
+ const msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];
7
+ args && msg.push(`args: ${JSON.stringify(args)}`);
8
+ msg.push(getDocsUrl(errorCode));
9
+ originalErrorMsg && msg.push(`Original Error Message:\n ${originalErrorMsg}`);
10
+ return msg.join("\n");
11
+ };
12
+
13
+ //#endregion
14
+ export { getShortErrorMsg };
15
+ //# sourceMappingURL=getShortErrorMsg.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getShortErrorMsg.js","names":[],"sources":["../../../../error-codes/dist/getShortErrorMsg.mjs"],"sourcesContent":["//#region src/getShortErrorMsg.ts\nconst getDocsUrl = (errorCode) => {\n\treturn `View the docs to see how to solve: https://module-federation.io/guide/troubleshooting/${errorCode.split(\"-\")[0].toLowerCase()}#${errorCode.toLowerCase()}`;\n};\nconst getShortErrorMsg = (errorCode, errorDescMap, args, originalErrorMsg) => {\n\tconst msg = [`${[errorDescMap[errorCode]]} #${errorCode}`];\n\targs && msg.push(`args: ${JSON.stringify(args)}`);\n\tmsg.push(getDocsUrl(errorCode));\n\toriginalErrorMsg && msg.push(`Original Error Message:\\n ${originalErrorMsg}`);\n\treturn msg.join(\"\\n\");\n};\n\n//#endregion\nexport { getShortErrorMsg };\n//# sourceMappingURL=getShortErrorMsg.mjs.map"],"mappings":";AACA,MAAM,cAAc,cAAc;AACjC,QAAO,yFAAyF,UAAU,MAAM,IAAI,CAAC,GAAG,aAAa,CAAC,GAAG,UAAU,aAAa;;AAEjK,MAAM,oBAAoB,WAAW,cAAc,MAAM,qBAAqB;CAC7E,MAAM,MAAM,CAAC,GAAG,CAAC,aAAa,WAAW,CAAC,IAAI,YAAY;AAC1D,SAAQ,IAAI,KAAK,SAAS,KAAK,UAAU,KAAK,GAAG;AACjD,KAAI,KAAK,WAAW,UAAU,CAAC;AAC/B,qBAAoB,IAAI,KAAK,6BAA6B,mBAAmB;AAC7E,QAAO,IAAI,KAAK,KAAK"}
@@ -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,52 @@
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 USE_REMOTE = typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" ? !FEDERATION_OPTIMIZE_NO_REMOTE : true;
16
+ const USE_SHARED = typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
17
+ const bundlerRuntime = {
18
+ remotes: USE_REMOTE ? require_remotes.remotes : void 0,
19
+ consumes: USE_SHARED ? require_consumes.consumes : void 0,
20
+ I: USE_SHARED ? require_initializeSharing.initializeSharing : void 0,
21
+ S: {},
22
+ installInitialConsumes: USE_SHARED ? require_installInitialConsumes.installInitialConsumes : void 0,
23
+ initContainerEntry: (typeof FEDERATION_HAS_EXPOSES === "boolean" ? FEDERATION_HAS_EXPOSES : true) ? require_initContainerEntry.initContainerEntry : void 0,
24
+ init: require_init.init,
25
+ getSharedFallbackGetter: USE_SHARED ? require_getSharedFallbackGetter.getSharedFallbackGetter : void 0
26
+ };
27
+ const federation = {
28
+ runtime: _module_federation_runtime,
29
+ instance: void 0,
30
+ initOptions: void 0,
31
+ bundlerRuntime,
32
+ attachShareScopeMap: require_attachShareScopeMap.attachShareScopeMap,
33
+ bundlerRuntimeOptions: {}
34
+ };
35
+ const instance = federation.instance;
36
+ const initOptions = federation.initOptions;
37
+ const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;
38
+
39
+ //#endregion
40
+ exports.attachShareScopeMap = require_attachShareScopeMap.attachShareScopeMap;
41
+ exports.bundlerRuntime = bundlerRuntime;
42
+ exports.bundlerRuntimeOptions = bundlerRuntimeOptions;
43
+ exports.default = federation;
44
+ exports.initOptions = initOptions;
45
+ exports.instance = instance;
46
+ Object.defineProperty(exports, 'runtime', {
47
+ enumerable: true,
48
+ get: function () {
49
+ return _module_federation_runtime;
50
+ }
51
+ });
52
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["remotes","consumes","initializeSharing","installInitialConsumes","initContainerEntry","getSharedFallbackGetter"],"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\ndeclare const FEDERATION_OPTIMIZE_NO_REMOTE: boolean;\ndeclare const FEDERATION_OPTIMIZE_NO_SHARED: boolean;\ndeclare const FEDERATION_HAS_EXPOSES: boolean;\n\nexport * from './types';\n\nconst USE_REMOTE =\n typeof FEDERATION_OPTIMIZE_NO_REMOTE === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_REMOTE\n : true;\nconst USE_SHARED =\n typeof FEDERATION_OPTIMIZE_NO_SHARED === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SHARED\n : true;\nconst USE_EXPOSES =\n typeof FEDERATION_HAS_EXPOSES === 'boolean' ? FEDERATION_HAS_EXPOSES : true;\n\nconst bundlerRuntime = {\n remotes: USE_REMOTE ? remotes : undefined,\n consumes: USE_SHARED ? consumes : undefined,\n I: USE_SHARED ? initializeSharing : undefined,\n S: {},\n installInitialConsumes: USE_SHARED ? installInitialConsumes : undefined,\n initContainerEntry: USE_EXPOSES ? initContainerEntry : undefined,\n init,\n getSharedFallbackGetter: USE_SHARED ? getSharedFallbackGetter : undefined,\n} as NonNullable<Federation['bundlerRuntime']>;\n\nconst federation: Federation = {\n runtime,\n instance: undefined,\n initOptions: undefined,\n bundlerRuntime,\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 { bundlerRuntime };\nexport const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;\n\nexport default federation;\n"],"mappings":";;;;;;;;;;;;;;AAiBA,MAAM,aACJ,OAAO,kCAAkC,YACrC,CAAC,gCACD;AACN,MAAM,aACJ,OAAO,kCAAkC,YACrC,CAAC,gCACD;AAIN,MAAM,iBAAiB;CACrB,SAAS,aAAaA,0BAAU;CAChC,UAAU,aAAaC,4BAAW;CAClC,GAAG,aAAaC,8CAAoB;CACpC,GAAG,EAAE;CACL,wBAAwB,aAAaC,wDAAyB;CAC9D,qBARA,OAAO,2BAA2B,YAAY,yBAAyB,QAQrCC,gDAAqB;CACvD;CACA,yBAAyB,aAAaC,0DAA0B;CACjE;AAED,MAAM,aAAyB;CAC7B;CACA,UAAU;CACV,aAAa;CACb;CACA;CACA,uBAAuB,EAAE;CAC1B;AAID,MAAa,WAAW,WAAW;AACnC,MAAa,cAAc,WAAW;AAEtC,MAAa,wBAAwB,WAAW"}