@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.
- package/LICENSE +21 -0
- package/README.md +21 -0
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.cjs +29 -0
- package/dist/attachShareScopeMap.cjs +11 -0
- package/dist/attachShareScopeMap.cjs.map +1 -0
- package/dist/attachShareScopeMap.d.ts +7 -0
- package/dist/attachShareScopeMap.js +10 -0
- package/dist/attachShareScopeMap.js.map +1 -0
- package/dist/bundler.cjs +18 -0
- package/dist/bundler.d.ts +4 -0
- package/dist/bundler.js +4 -0
- package/dist/constant.cjs +8 -0
- package/dist/constant.cjs.map +1 -0
- package/dist/constant.d.ts +5 -0
- package/dist/constant.js +6 -0
- package/dist/constant.js.map +1 -0
- package/dist/consumes.cjs +68 -0
- package/dist/consumes.cjs.map +1 -0
- package/dist/consumes.js +68 -0
- package/dist/consumes.js.map +1 -0
- package/dist/error-codes/dist/error-codes.cjs +7 -0
- package/dist/error-codes/dist/error-codes.cjs.map +1 -0
- package/dist/error-codes/dist/error-codes.js +6 -0
- package/dist/error-codes/dist/error-codes.js.map +1 -0
- package/dist/error-codes/dist/getShortErrorMsg.cjs +16 -0
- package/dist/error-codes/dist/getShortErrorMsg.cjs.map +1 -0
- package/dist/error-codes/dist/getShortErrorMsg.js +15 -0
- package/dist/error-codes/dist/getShortErrorMsg.js.map +1 -0
- package/dist/getSharedFallbackGetter.cjs +27 -0
- package/dist/getSharedFallbackGetter.cjs.map +1 -0
- package/dist/getSharedFallbackGetter.js +26 -0
- package/dist/getSharedFallbackGetter.js.map +1 -0
- package/dist/getUsedExports.cjs +11 -0
- package/dist/getUsedExports.cjs.map +1 -0
- package/dist/getUsedExports.js +10 -0
- package/dist/getUsedExports.js.map +1 -0
- package/dist/index.cjs +52 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +38 -0
- package/dist/index.js.map +1 -0
- package/dist/init.cjs +85 -0
- package/dist/init.cjs.map +1 -0
- package/dist/init.js +83 -0
- package/dist/init.js.map +1 -0
- package/dist/initContainerEntry.cjs +42 -0
- package/dist/initContainerEntry.cjs.map +1 -0
- package/dist/initContainerEntry.d.ts +7 -0
- package/dist/initContainerEntry.js +41 -0
- package/dist/initContainerEntry.js.map +1 -0
- package/dist/initializeSharing.cjs +61 -0
- package/dist/initializeSharing.cjs.map +1 -0
- package/dist/initializeSharing.d.ts +13 -0
- package/dist/initializeSharing.js +61 -0
- package/dist/initializeSharing.js.map +1 -0
- package/dist/installInitialConsumes.cjs +75 -0
- package/dist/installInitialConsumes.cjs.map +1 -0
- package/dist/installInitialConsumes.js +75 -0
- package/dist/installInitialConsumes.js.map +1 -0
- package/dist/remotes.cjs +74 -0
- package/dist/remotes.cjs.map +1 -0
- package/dist/remotes.js +73 -0
- package/dist/remotes.js.map +1 -0
- package/dist/sdk/dist/types/plugins/ModuleFederationPlugin.d.ts +11 -0
- package/dist/types.d.ts +201 -0
- package/dist/updateOptions.cjs +112 -0
- package/dist/updateOptions.cjs.map +1 -0
- package/dist/updateOptions.js +110 -0
- package/dist/updateOptions.js.map +1 -0
- package/package.json +78 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ExternalsType } from "./sdk/dist/types/plugins/ModuleFederationPlugin.js";
|
|
2
|
+
import { attachShareScopeMap } from "./attachShareScopeMap.js";
|
|
3
|
+
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";
|
|
4
|
+
import * as _module_federation_runtime_core0 from "@module-federation/runtime-core";
|
|
5
|
+
import * as _module_federation_runtime_core_types0 from "@module-federation/runtime-core/types";
|
|
6
|
+
import * as runtime from "@module-federation/runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/index.d.ts
|
|
9
|
+
declare const bundlerRuntime: NonNullable<Federation["bundlerRuntime"]>;
|
|
10
|
+
declare const federation: Federation;
|
|
11
|
+
declare const instance: runtime.ModuleFederation | undefined;
|
|
12
|
+
declare const initOptions: (Omit<_module_federation_runtime_core0.UserOptions, "remotes"> & {
|
|
13
|
+
remotes: Array<_module_federation_runtime_core_types0.Remote & {
|
|
14
|
+
externalType: ExternalsType;
|
|
15
|
+
}>;
|
|
16
|
+
}) | undefined;
|
|
17
|
+
declare const bundlerRuntimeOptions: {
|
|
18
|
+
remotes?: Exclude<RemotesOptions, "chunkId" | "promises"> & {
|
|
19
|
+
remoteInfos?: RemoteInfos;
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
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 };
|
|
24
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
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 USE_REMOTE = typeof FEDERATION_OPTIMIZE_NO_REMOTE === "boolean" ? !FEDERATION_OPTIMIZE_NO_REMOTE : true;
|
|
13
|
+
const USE_SHARED = typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
|
|
14
|
+
const bundlerRuntime = {
|
|
15
|
+
remotes: USE_REMOTE ? remotes : void 0,
|
|
16
|
+
consumes: USE_SHARED ? consumes : void 0,
|
|
17
|
+
I: USE_SHARED ? initializeSharing : void 0,
|
|
18
|
+
S: {},
|
|
19
|
+
installInitialConsumes: USE_SHARED ? installInitialConsumes : void 0,
|
|
20
|
+
initContainerEntry: (typeof FEDERATION_HAS_EXPOSES === "boolean" ? FEDERATION_HAS_EXPOSES : true) ? initContainerEntry : void 0,
|
|
21
|
+
init,
|
|
22
|
+
getSharedFallbackGetter: USE_SHARED ? getSharedFallbackGetter : void 0
|
|
23
|
+
};
|
|
24
|
+
const federation = {
|
|
25
|
+
runtime,
|
|
26
|
+
instance: void 0,
|
|
27
|
+
initOptions: void 0,
|
|
28
|
+
bundlerRuntime,
|
|
29
|
+
attachShareScopeMap,
|
|
30
|
+
bundlerRuntimeOptions: {}
|
|
31
|
+
};
|
|
32
|
+
const instance = federation.instance;
|
|
33
|
+
const initOptions = federation.initOptions;
|
|
34
|
+
const bundlerRuntimeOptions = federation.bundlerRuntimeOptions;
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { attachShareScopeMap, bundlerRuntime, bundlerRuntimeOptions, federation as default, initOptions, instance, runtime };
|
|
38
|
+
//# 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\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,aAAa,UAAU;CAChC,UAAU,aAAa,WAAW;CAClC,GAAG,aAAa,oBAAoB;CACpC,GAAG,EAAE;CACL,wBAAwB,aAAa,yBAAyB;CAC9D,qBARA,OAAO,2BAA2B,YAAY,yBAAyB,QAQrC,qBAAqB;CACvD;CACA,yBAAyB,aAAa,0BAA0B;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"}
|
package/dist/init.cjs
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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
|
+
const USE_SHARED = typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
|
|
8
|
+
function init({ webpackRequire }) {
|
|
9
|
+
const { initOptions, runtime, sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
10
|
+
if (!initOptions) throw new Error("initOptions is required!");
|
|
11
|
+
if (USE_SHARED) {
|
|
12
|
+
const treeShakingSharePlugin = function() {
|
|
13
|
+
return {
|
|
14
|
+
name: "tree-shake-plugin",
|
|
15
|
+
beforeInit(args) {
|
|
16
|
+
const { userOptions, origin, options: registeredOptions } = args;
|
|
17
|
+
const version = userOptions.version || registeredOptions.version;
|
|
18
|
+
if (!sharedFallback) return args;
|
|
19
|
+
const currentShared = userOptions.shared || {};
|
|
20
|
+
const shared = [];
|
|
21
|
+
Object.keys(currentShared).forEach((sharedName) => {
|
|
22
|
+
(Array.isArray(currentShared[sharedName]) ? currentShared[sharedName] : [currentShared[sharedName]]).forEach((sharedArg) => {
|
|
23
|
+
shared.push([sharedName, sharedArg]);
|
|
24
|
+
if ("get" in sharedArg) {
|
|
25
|
+
sharedArg.treeShaking ||= {};
|
|
26
|
+
sharedArg.treeShaking.get = sharedArg.get;
|
|
27
|
+
sharedArg.get = bundlerRuntime.getSharedFallbackGetter({
|
|
28
|
+
shareKey: sharedName,
|
|
29
|
+
factory: sharedArg.get,
|
|
30
|
+
webpackRequire,
|
|
31
|
+
libraryType,
|
|
32
|
+
version: sharedArg.version
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
const hostGlobalSnapshot = _module_federation_runtime_helpers.default.global.getGlobalSnapshotInfoByModuleInfo({
|
|
38
|
+
name: origin.name,
|
|
39
|
+
version
|
|
40
|
+
});
|
|
41
|
+
if (!hostGlobalSnapshot || !("shared" in hostGlobalSnapshot)) return args;
|
|
42
|
+
Object.keys(registeredOptions.shared || {}).forEach((pkgName) => {
|
|
43
|
+
registeredOptions.shared[pkgName].forEach((sharedArg) => {
|
|
44
|
+
shared.push([pkgName, sharedArg]);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
const patchShared = (pkgName, shared) => {
|
|
48
|
+
const shareSnapshot = hostGlobalSnapshot.shared.find((item) => item.sharedName === pkgName);
|
|
49
|
+
if (!shareSnapshot) return;
|
|
50
|
+
const { treeShaking } = shared;
|
|
51
|
+
if (!treeShaking) return;
|
|
52
|
+
const { secondarySharedTreeShakingName, secondarySharedTreeShakingEntry, treeShakingStatus } = shareSnapshot;
|
|
53
|
+
if (treeShaking.status === treeShakingStatus) return;
|
|
54
|
+
treeShaking.status = treeShakingStatus;
|
|
55
|
+
if (secondarySharedTreeShakingEntry && libraryType && secondarySharedTreeShakingName) treeShaking.get = async () => {
|
|
56
|
+
const shareEntry = await (0, _module_federation_runtime.getRemoteEntry)({
|
|
57
|
+
origin,
|
|
58
|
+
remoteInfo: {
|
|
59
|
+
name: secondarySharedTreeShakingName,
|
|
60
|
+
entry: secondarySharedTreeShakingEntry,
|
|
61
|
+
type: libraryType,
|
|
62
|
+
entryGlobalName: secondarySharedTreeShakingName,
|
|
63
|
+
shareScope: "default"
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
await shareEntry.init(origin, __webpack_require__.federation.bundlerRuntime);
|
|
67
|
+
return shareEntry.get();
|
|
68
|
+
};
|
|
69
|
+
};
|
|
70
|
+
shared.forEach(([pkgName, sharedArg]) => {
|
|
71
|
+
patchShared(pkgName, sharedArg);
|
|
72
|
+
});
|
|
73
|
+
return args;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
initOptions.plugins ||= [];
|
|
78
|
+
initOptions.plugins.push(treeShakingSharePlugin());
|
|
79
|
+
}
|
|
80
|
+
return runtime.init(initOptions);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
exports.init = init;
|
|
85
|
+
//# 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\ndeclare const FEDERATION_OPTIMIZE_NO_SHARED: boolean;\n\nconst USE_SHARED =\n typeof FEDERATION_OPTIMIZE_NO_SHARED === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SHARED\n : true;\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 if (USE_SHARED) {\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 }\n return runtime!.init(initOptions);\n}\n"],"mappings":";;;;;;AAUA,MAAM,aACJ,OAAO,kCAAkC,YACrC,CAAC,gCACD;AAEN,SAAgB,KAAK,EAAE,kBAAsD;CAC3E,MAAM,EAAE,aAAa,SAAS,gBAAgB,gBAAgB,gBAC5D,eAAe;AAEjB,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,2BAA2B;AAG7C,KAAI,YAAY;EACd,MAAM,yBACJ,WAAY;AACV,UAAO;IACL,MAAM;IACN,WAAW,MAAM;KACf,MAAM,EAAE,aAAa,QAAQ,SAAS,sBAAsB;KAC5D,MAAM,UAAU,YAAY,WAAW,kBAAkB;AACzD,SAAI,CAAC,eACH,QAAO;KAGT,MAAM,gBAAgB,YAAY,UAAU,EAAE;KAC9C,MAAM,SAA8C,EAAE;AAEtD,YAAO,KAAK,cAAc,CAAC,SAAS,eAAe;AAIjD,OAHmB,MAAM,QAAQ,cAAc,YAAY,GACvD,cAAc,cACd,CAAC,cAAc,YAAY,EACpB,SAAS,cAAc;AAChC,cAAO,KAAK,CAAC,YAAY,UAAU,CAAC;AACpC,WAAI,SAAS,WAAW;AACtB,kBAAU,gBAAgB,EAAE;AAC5B,kBAAU,YAAY,MAAM,UAAU;AACtC,kBAAU,MAAM,eAAgB,wBAAwB;SACtD,UAAU;SACV,SAAS,UAAU;SACnB;SACA;SACA,SAAS,UAAU;SACpB,CAAC;;QAEJ;OACF;KAGF,MAAM,qBACJA,2CAAQ,OAAO,kCAAkC;MAC/C,MAAM,OAAO;MACJ;MACV,CAAC;AACJ,SAAI,CAAC,sBAAsB,EAAE,YAAY,oBACvC,QAAO;AAGT,YAAO,KAAK,kBAAkB,UAAU,EAAE,CAAC,CAAC,SAAS,YAAY;AAE/D,MADmB,kBAAkB,OAAO,SACjC,SAAS,cAAc;AAChC,cAAO,KAAK,CAAC,SAAS,UAAU,CAAC;QACjC;OACF;KAEF,MAAM,eAAe,SAAiB,WAAsB;MAC1D,MAAM,gBAAgB,mBAAmB,OAAO,MAC7C,SAAS,KAAK,eAAe,QAC/B;AACD,UAAI,CAAC,cACH;MAEF,MAAM,EAAE,gBAAgB;AACxB,UAAI,CAAC,YACH;MAEF,MAAM,EACJ,gCACA,iCACA,sBACE;AACJ,UAAI,YAAY,WAAW,kBACzB;AAEF,kBAAY,SAAS;AACrB,UACE,mCACA,eACA,+BAEA,aAAY,MAAM,YAAY;OAC5B,MAAM,aAAa,qDAAqB;QACtC;QACA,YAAY;SACV,MAAM;SACN,OAAO;SACP,MAAM;SACN,iBAAiB;SAEjB,YAAY;SACb;QACF,CAAC;AAGF,aAAM,WAAW,KACf,QAEA,oBAAoB,WAAW,eAChC;AAGD,cADe,WAAW,KAAK;;;AAKrC,YAAO,SAAS,CAAC,SAAS,eAAe;AACvC,kBAAY,SAAS,UAAU;OAC/B;AAEF,YAAO;;IAEV;;AAGL,cAAY,YAAY,EAAE;AAC1B,cAAY,QAAQ,KAAK,wBAAwB,CAAC;;AAEpD,QAAO,QAAS,KAAK,YAAY"}
|
package/dist/init.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { getRemoteEntry } from "@module-federation/runtime";
|
|
2
|
+
import helpers from "@module-federation/runtime/helpers";
|
|
3
|
+
|
|
4
|
+
//#region src/init.ts
|
|
5
|
+
const USE_SHARED = typeof FEDERATION_OPTIMIZE_NO_SHARED === "boolean" ? !FEDERATION_OPTIMIZE_NO_SHARED : true;
|
|
6
|
+
function init({ webpackRequire }) {
|
|
7
|
+
const { initOptions, runtime, sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
8
|
+
if (!initOptions) throw new Error("initOptions is required!");
|
|
9
|
+
if (USE_SHARED) {
|
|
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 = helpers.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 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
|
+
}
|
|
78
|
+
return runtime.init(initOptions);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
export { init };
|
|
83
|
+
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.js","names":[],"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\ndeclare const FEDERATION_OPTIMIZE_NO_SHARED: boolean;\n\nconst USE_SHARED =\n typeof FEDERATION_OPTIMIZE_NO_SHARED === 'boolean'\n ? !FEDERATION_OPTIMIZE_NO_SHARED\n : true;\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 if (USE_SHARED) {\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 }\n return runtime!.init(initOptions);\n}\n"],"mappings":";;;;AAUA,MAAM,aACJ,OAAO,kCAAkC,YACrC,CAAC,gCACD;AAEN,SAAgB,KAAK,EAAE,kBAAsD;CAC3E,MAAM,EAAE,aAAa,SAAS,gBAAgB,gBAAgB,gBAC5D,eAAe;AAEjB,KAAI,CAAC,YACH,OAAM,IAAI,MAAM,2BAA2B;AAG7C,KAAI,YAAY;EACd,MAAM,yBACJ,WAAY;AACV,UAAO;IACL,MAAM;IACN,WAAW,MAAM;KACf,MAAM,EAAE,aAAa,QAAQ,SAAS,sBAAsB;KAC5D,MAAM,UAAU,YAAY,WAAW,kBAAkB;AACzD,SAAI,CAAC,eACH,QAAO;KAGT,MAAM,gBAAgB,YAAY,UAAU,EAAE;KAC9C,MAAM,SAA8C,EAAE;AAEtD,YAAO,KAAK,cAAc,CAAC,SAAS,eAAe;AAIjD,OAHmB,MAAM,QAAQ,cAAc,YAAY,GACvD,cAAc,cACd,CAAC,cAAc,YAAY,EACpB,SAAS,cAAc;AAChC,cAAO,KAAK,CAAC,YAAY,UAAU,CAAC;AACpC,WAAI,SAAS,WAAW;AACtB,kBAAU,gBAAgB,EAAE;AAC5B,kBAAU,YAAY,MAAM,UAAU;AACtC,kBAAU,MAAM,eAAgB,wBAAwB;SACtD,UAAU;SACV,SAAS,UAAU;SACnB;SACA;SACA,SAAS,UAAU;SACpB,CAAC;;QAEJ;OACF;KAGF,MAAM,qBACJ,QAAQ,OAAO,kCAAkC;MAC/C,MAAM,OAAO;MACJ;MACV,CAAC;AACJ,SAAI,CAAC,sBAAsB,EAAE,YAAY,oBACvC,QAAO;AAGT,YAAO,KAAK,kBAAkB,UAAU,EAAE,CAAC,CAAC,SAAS,YAAY;AAE/D,MADmB,kBAAkB,OAAO,SACjC,SAAS,cAAc;AAChC,cAAO,KAAK,CAAC,SAAS,UAAU,CAAC;QACjC;OACF;KAEF,MAAM,eAAe,SAAiB,WAAsB;MAC1D,MAAM,gBAAgB,mBAAmB,OAAO,MAC7C,SAAS,KAAK,eAAe,QAC/B;AACD,UAAI,CAAC,cACH;MAEF,MAAM,EAAE,gBAAgB;AACxB,UAAI,CAAC,YACH;MAEF,MAAM,EACJ,gCACA,iCACA,sBACE;AACJ,UAAI,YAAY,WAAW,kBACzB;AAEF,kBAAY,SAAS;AACrB,UACE,mCACA,eACA,+BAEA,aAAY,MAAM,YAAY;OAC5B,MAAM,aAAa,MAAM,eAAe;QACtC;QACA,YAAY;SACV,MAAM;SACN,OAAO;SACP,MAAM;SACN,iBAAiB;SAEjB,YAAY;SACb;QACF,CAAC;AAGF,aAAM,WAAW,KACf,QAEA,oBAAoB,WAAW,eAChC;AAGD,cADe,WAAW,KAAK;;;AAKrC,YAAO,SAAS,CAAC,SAAS,eAAe;AACvC,kBAAY,SAAS,UAAU;OAC/B;AAEF,YAAO;;IAEV;;AAGL,cAAY,YAAY,EAAE;AAC1B,cAAY,QAAQ,KAAK,wBAAwB,CAAC;;AAEpD,QAAO,QAAS,KAAK,YAAY"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
|
|
2
|
+
//#region src/initContainerEntry.ts
|
|
3
|
+
function initContainerEntry(options) {
|
|
4
|
+
const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions } = options;
|
|
5
|
+
if (!webpackRequire.S) return;
|
|
6
|
+
if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
|
|
7
|
+
const federationInstance = webpackRequire.federation.instance;
|
|
8
|
+
federationInstance.initOptions({
|
|
9
|
+
name: webpackRequire.federation.initOptions.name,
|
|
10
|
+
remotes: [],
|
|
11
|
+
...remoteEntryInitOptions
|
|
12
|
+
});
|
|
13
|
+
const hostShareScopeKeys = remoteEntryInitOptions?.shareScopeKeys;
|
|
14
|
+
const hostShareScopeMap = remoteEntryInitOptions?.shareScopeMap;
|
|
15
|
+
if (!shareScopeKey || typeof shareScopeKey === "string") {
|
|
16
|
+
const key = shareScopeKey || "default";
|
|
17
|
+
if (Array.isArray(hostShareScopeKeys)) hostShareScopeKeys.forEach((hostKey) => {
|
|
18
|
+
if (!hostShareScopeMap[hostKey]) hostShareScopeMap[hostKey] = {};
|
|
19
|
+
const sc = hostShareScopeMap[hostKey];
|
|
20
|
+
federationInstance.initShareScopeMap(hostKey, sc, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
21
|
+
});
|
|
22
|
+
else federationInstance.initShareScopeMap(key, shareScope, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
23
|
+
} else shareScopeKey.forEach((key) => {
|
|
24
|
+
if (!hostShareScopeKeys || !hostShareScopeMap) {
|
|
25
|
+
federationInstance.initShareScopeMap(key, shareScope, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (!hostShareScopeMap[key]) hostShareScopeMap[key] = {};
|
|
29
|
+
const sc = hostShareScopeMap[key];
|
|
30
|
+
federationInstance.initShareScopeMap(key, sc, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
31
|
+
});
|
|
32
|
+
if (webpackRequire.federation.attachShareScopeMap) webpackRequire.federation.attachShareScopeMap(webpackRequire);
|
|
33
|
+
if (!Array.isArray(shareScopeKey)) return webpackRequire.I(shareScopeKey || "default", initScope);
|
|
34
|
+
if (Boolean(webpackRequire.federation.initOptions.shared)) return webpackRequire.I(shareScopeKey, initScope);
|
|
35
|
+
return Promise.all(shareScopeKey.map((key) => {
|
|
36
|
+
return webpackRequire.I(key, initScope);
|
|
37
|
+
})).then(() => true);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//#endregion
|
|
41
|
+
exports.initContainerEntry = initContainerEntry;
|
|
42
|
+
//# sourceMappingURL=initContainerEntry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initContainerEntry.cjs","names":[],"sources":["../src/initContainerEntry.ts"],"sourcesContent":["import { InitContainerEntryOptions, WebpackRequire } from './types';\n\nexport function initContainerEntry(\n options: InitContainerEntryOptions,\n): WebpackRequire['I'] | void {\n const {\n webpackRequire,\n shareScope,\n initScope,\n shareScopeKey,\n remoteEntryInitOptions,\n } = options;\n if (!webpackRequire.S) return;\n if (\n !webpackRequire.federation ||\n !webpackRequire.federation.instance ||\n !webpackRequire.federation.initOptions\n )\n return;\n\n const federationInstance = webpackRequire.federation.instance;\n\n federationInstance.initOptions({\n name: webpackRequire.federation.initOptions.name,\n remotes: [],\n ...remoteEntryInitOptions,\n });\n\n const hostShareScopeKeys = remoteEntryInitOptions?.shareScopeKeys;\n const hostShareScopeMap = remoteEntryInitOptions?.shareScopeMap;\n\n // host: 'default' remote: 'default' remote['default'] = hostShareScopeMap['default']\n // host: ['default', 'scope1'] remote: 'default' remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scop1']\n // host: 'default' remote: ['default','scope1'] remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scope1'] = {}\n // host: ['scope1','default'] remote: ['scope1','scope2'] => remote['scope1'] = hostShareScopeMap['scope1']; remote['scope2'] = hostShareScopeMap['scope2'] = {};\n if (!shareScopeKey || typeof shareScopeKey === 'string') {\n const key = shareScopeKey || 'default';\n if (Array.isArray(hostShareScopeKeys)) {\n // const sc = hostShareScopeMap![key];\n // if (!sc) {\n // throw new Error('shareScopeKey is not exist in hostShareScopeMap');\n // }\n // federationInstance.initShareScopeMap(key, sc, {\n // hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n // });\n\n hostShareScopeKeys.forEach((hostKey) => {\n if (!hostShareScopeMap![hostKey]) {\n hostShareScopeMap![hostKey] = {};\n }\n const sc = hostShareScopeMap![hostKey];\n federationInstance.initShareScopeMap(hostKey, sc, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n });\n } else {\n federationInstance.initShareScopeMap(key, shareScope, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n }\n } else {\n shareScopeKey.forEach((key) => {\n if (!hostShareScopeKeys || !hostShareScopeMap) {\n federationInstance.initShareScopeMap(key, shareScope, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n return;\n }\n\n if (!hostShareScopeMap[key]) {\n hostShareScopeMap[key] = {};\n }\n const sc = hostShareScopeMap[key];\n federationInstance.initShareScopeMap(key, sc, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n });\n }\n\n if (webpackRequire.federation.attachShareScopeMap) {\n webpackRequire.federation.attachShareScopeMap(webpackRequire);\n }\n\n if (!Array.isArray(shareScopeKey)) {\n // @ts-ignore\n return webpackRequire.I(shareScopeKey || 'default', initScope);\n }\n\n var proxyInitializeSharing = Boolean(\n webpackRequire.federation.initOptions.shared,\n );\n\n if (proxyInitializeSharing) {\n // @ts-ignore\n return webpackRequire.I(shareScopeKey, initScope);\n }\n // @ts-ignore\n return Promise.all(\n shareScopeKey.map((key) => {\n // @ts-ignore\n return webpackRequire.I(key, initScope);\n }),\n ).then(() => true);\n}\n"],"mappings":";;AAEA,SAAgB,mBACd,SAC4B;CAC5B,MAAM,EACJ,gBACA,YACA,WACA,eACA,2BACE;AACJ,KAAI,CAAC,eAAe,EAAG;AACvB,KACE,CAAC,eAAe,cAChB,CAAC,eAAe,WAAW,YAC3B,CAAC,eAAe,WAAW,YAE3B;CAEF,MAAM,qBAAqB,eAAe,WAAW;AAErD,oBAAmB,YAAY;EAC7B,MAAM,eAAe,WAAW,YAAY;EAC5C,SAAS,EAAE;EACX,GAAG;EACJ,CAAC;CAEF,MAAM,qBAAqB,wBAAwB;CACnD,MAAM,oBAAoB,wBAAwB;AAMlD,KAAI,CAAC,iBAAiB,OAAO,kBAAkB,UAAU;EACvD,MAAM,MAAM,iBAAiB;AAC7B,MAAI,MAAM,QAAQ,mBAAmB,CASnC,oBAAmB,SAAS,YAAY;AACtC,OAAI,CAAC,kBAAmB,SACtB,mBAAmB,WAAW,EAAE;GAElC,MAAM,KAAK,kBAAmB;AAC9B,sBAAmB,kBAAkB,SAAS,IAAI,EAChD,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;IACF;MAEF,oBAAmB,kBAAkB,KAAK,YAAY,EACpD,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;OAGJ,eAAc,SAAS,QAAQ;AAC7B,MAAI,CAAC,sBAAsB,CAAC,mBAAmB;AAC7C,sBAAmB,kBAAkB,KAAK,YAAY,EACpD,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;AACF;;AAGF,MAAI,CAAC,kBAAkB,KACrB,mBAAkB,OAAO,EAAE;EAE7B,MAAM,KAAK,kBAAkB;AAC7B,qBAAmB,kBAAkB,KAAK,IAAI,EAC5C,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;GACF;AAGJ,KAAI,eAAe,WAAW,oBAC5B,gBAAe,WAAW,oBAAoB,eAAe;AAG/D,KAAI,CAAC,MAAM,QAAQ,cAAc,CAE/B,QAAO,eAAe,EAAE,iBAAiB,WAAW,UAAU;AAOhE,KAJ6B,QAC3B,eAAe,WAAW,YAAY,OACvC,CAIC,QAAO,eAAe,EAAE,eAAe,UAAU;AAGnD,QAAO,QAAQ,IACb,cAAc,KAAK,QAAQ;AAEzB,SAAO,eAAe,EAAE,KAAK,UAAU;GACvC,CACH,CAAC,WAAW,KAAK"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { InitContainerEntryOptions, WebpackRequire } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/initContainerEntry.d.ts
|
|
4
|
+
declare function initContainerEntry(options: InitContainerEntryOptions): WebpackRequire['I'] | void;
|
|
5
|
+
//#endregion
|
|
6
|
+
export { initContainerEntry };
|
|
7
|
+
//# sourceMappingURL=initContainerEntry.d.ts.map
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//#region src/initContainerEntry.ts
|
|
2
|
+
function initContainerEntry(options) {
|
|
3
|
+
const { webpackRequire, shareScope, initScope, shareScopeKey, remoteEntryInitOptions } = options;
|
|
4
|
+
if (!webpackRequire.S) return;
|
|
5
|
+
if (!webpackRequire.federation || !webpackRequire.federation.instance || !webpackRequire.federation.initOptions) return;
|
|
6
|
+
const federationInstance = webpackRequire.federation.instance;
|
|
7
|
+
federationInstance.initOptions({
|
|
8
|
+
name: webpackRequire.federation.initOptions.name,
|
|
9
|
+
remotes: [],
|
|
10
|
+
...remoteEntryInitOptions
|
|
11
|
+
});
|
|
12
|
+
const hostShareScopeKeys = remoteEntryInitOptions?.shareScopeKeys;
|
|
13
|
+
const hostShareScopeMap = remoteEntryInitOptions?.shareScopeMap;
|
|
14
|
+
if (!shareScopeKey || typeof shareScopeKey === "string") {
|
|
15
|
+
const key = shareScopeKey || "default";
|
|
16
|
+
if (Array.isArray(hostShareScopeKeys)) hostShareScopeKeys.forEach((hostKey) => {
|
|
17
|
+
if (!hostShareScopeMap[hostKey]) hostShareScopeMap[hostKey] = {};
|
|
18
|
+
const sc = hostShareScopeMap[hostKey];
|
|
19
|
+
federationInstance.initShareScopeMap(hostKey, sc, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
20
|
+
});
|
|
21
|
+
else federationInstance.initShareScopeMap(key, shareScope, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
22
|
+
} else shareScopeKey.forEach((key) => {
|
|
23
|
+
if (!hostShareScopeKeys || !hostShareScopeMap) {
|
|
24
|
+
federationInstance.initShareScopeMap(key, shareScope, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!hostShareScopeMap[key]) hostShareScopeMap[key] = {};
|
|
28
|
+
const sc = hostShareScopeMap[key];
|
|
29
|
+
federationInstance.initShareScopeMap(key, sc, { hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {} });
|
|
30
|
+
});
|
|
31
|
+
if (webpackRequire.federation.attachShareScopeMap) webpackRequire.federation.attachShareScopeMap(webpackRequire);
|
|
32
|
+
if (!Array.isArray(shareScopeKey)) return webpackRequire.I(shareScopeKey || "default", initScope);
|
|
33
|
+
if (Boolean(webpackRequire.federation.initOptions.shared)) return webpackRequire.I(shareScopeKey, initScope);
|
|
34
|
+
return Promise.all(shareScopeKey.map((key) => {
|
|
35
|
+
return webpackRequire.I(key, initScope);
|
|
36
|
+
})).then(() => true);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { initContainerEntry };
|
|
41
|
+
//# sourceMappingURL=initContainerEntry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initContainerEntry.js","names":[],"sources":["../src/initContainerEntry.ts"],"sourcesContent":["import { InitContainerEntryOptions, WebpackRequire } from './types';\n\nexport function initContainerEntry(\n options: InitContainerEntryOptions,\n): WebpackRequire['I'] | void {\n const {\n webpackRequire,\n shareScope,\n initScope,\n shareScopeKey,\n remoteEntryInitOptions,\n } = options;\n if (!webpackRequire.S) return;\n if (\n !webpackRequire.federation ||\n !webpackRequire.federation.instance ||\n !webpackRequire.federation.initOptions\n )\n return;\n\n const federationInstance = webpackRequire.federation.instance;\n\n federationInstance.initOptions({\n name: webpackRequire.federation.initOptions.name,\n remotes: [],\n ...remoteEntryInitOptions,\n });\n\n const hostShareScopeKeys = remoteEntryInitOptions?.shareScopeKeys;\n const hostShareScopeMap = remoteEntryInitOptions?.shareScopeMap;\n\n // host: 'default' remote: 'default' remote['default'] = hostShareScopeMap['default']\n // host: ['default', 'scope1'] remote: 'default' remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scop1']\n // host: 'default' remote: ['default','scope1'] remote['default'] = hostShareScopeMap['default']; remote['scope1'] = hostShareScopeMap['scope1'] = {}\n // host: ['scope1','default'] remote: ['scope1','scope2'] => remote['scope1'] = hostShareScopeMap['scope1']; remote['scope2'] = hostShareScopeMap['scope2'] = {};\n if (!shareScopeKey || typeof shareScopeKey === 'string') {\n const key = shareScopeKey || 'default';\n if (Array.isArray(hostShareScopeKeys)) {\n // const sc = hostShareScopeMap![key];\n // if (!sc) {\n // throw new Error('shareScopeKey is not exist in hostShareScopeMap');\n // }\n // federationInstance.initShareScopeMap(key, sc, {\n // hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n // });\n\n hostShareScopeKeys.forEach((hostKey) => {\n if (!hostShareScopeMap![hostKey]) {\n hostShareScopeMap![hostKey] = {};\n }\n const sc = hostShareScopeMap![hostKey];\n federationInstance.initShareScopeMap(hostKey, sc, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n });\n } else {\n federationInstance.initShareScopeMap(key, shareScope, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n }\n } else {\n shareScopeKey.forEach((key) => {\n if (!hostShareScopeKeys || !hostShareScopeMap) {\n federationInstance.initShareScopeMap(key, shareScope, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n return;\n }\n\n if (!hostShareScopeMap[key]) {\n hostShareScopeMap[key] = {};\n }\n const sc = hostShareScopeMap[key];\n federationInstance.initShareScopeMap(key, sc, {\n hostShareScopeMap: remoteEntryInitOptions?.shareScopeMap || {},\n });\n });\n }\n\n if (webpackRequire.federation.attachShareScopeMap) {\n webpackRequire.federation.attachShareScopeMap(webpackRequire);\n }\n\n if (!Array.isArray(shareScopeKey)) {\n // @ts-ignore\n return webpackRequire.I(shareScopeKey || 'default', initScope);\n }\n\n var proxyInitializeSharing = Boolean(\n webpackRequire.federation.initOptions.shared,\n );\n\n if (proxyInitializeSharing) {\n // @ts-ignore\n return webpackRequire.I(shareScopeKey, initScope);\n }\n // @ts-ignore\n return Promise.all(\n shareScopeKey.map((key) => {\n // @ts-ignore\n return webpackRequire.I(key, initScope);\n }),\n ).then(() => true);\n}\n"],"mappings":";AAEA,SAAgB,mBACd,SAC4B;CAC5B,MAAM,EACJ,gBACA,YACA,WACA,eACA,2BACE;AACJ,KAAI,CAAC,eAAe,EAAG;AACvB,KACE,CAAC,eAAe,cAChB,CAAC,eAAe,WAAW,YAC3B,CAAC,eAAe,WAAW,YAE3B;CAEF,MAAM,qBAAqB,eAAe,WAAW;AAErD,oBAAmB,YAAY;EAC7B,MAAM,eAAe,WAAW,YAAY;EAC5C,SAAS,EAAE;EACX,GAAG;EACJ,CAAC;CAEF,MAAM,qBAAqB,wBAAwB;CACnD,MAAM,oBAAoB,wBAAwB;AAMlD,KAAI,CAAC,iBAAiB,OAAO,kBAAkB,UAAU;EACvD,MAAM,MAAM,iBAAiB;AAC7B,MAAI,MAAM,QAAQ,mBAAmB,CASnC,oBAAmB,SAAS,YAAY;AACtC,OAAI,CAAC,kBAAmB,SACtB,mBAAmB,WAAW,EAAE;GAElC,MAAM,KAAK,kBAAmB;AAC9B,sBAAmB,kBAAkB,SAAS,IAAI,EAChD,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;IACF;MAEF,oBAAmB,kBAAkB,KAAK,YAAY,EACpD,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;OAGJ,eAAc,SAAS,QAAQ;AAC7B,MAAI,CAAC,sBAAsB,CAAC,mBAAmB;AAC7C,sBAAmB,kBAAkB,KAAK,YAAY,EACpD,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;AACF;;AAGF,MAAI,CAAC,kBAAkB,KACrB,mBAAkB,OAAO,EAAE;EAE7B,MAAM,KAAK,kBAAkB;AAC7B,qBAAmB,kBAAkB,KAAK,IAAI,EAC5C,mBAAmB,wBAAwB,iBAAiB,EAAE,EAC/D,CAAC;GACF;AAGJ,KAAI,eAAe,WAAW,oBAC5B,gBAAe,WAAW,oBAAoB,eAAe;AAG/D,KAAI,CAAC,MAAM,QAAQ,cAAc,CAE/B,QAAO,eAAe,EAAE,iBAAiB,WAAW,UAAU;AAOhE,KAJ6B,QAC3B,eAAe,WAAW,YAAY,OACvC,CAIC,QAAO,eAAe,EAAE,eAAe,UAAU;AAGnD,QAAO,QAAQ,IACb,cAAc,KAAK,QAAQ;AAEzB,SAAO,eAAe,EAAE,KAAK,UAAU;GACvC,CACH,CAAC,WAAW,KAAK"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
const require_attachShareScopeMap = require('./attachShareScopeMap.cjs');
|
|
2
|
+
const require_constant = require('./constant.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/initializeSharing.ts
|
|
5
|
+
function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope }) {
|
|
6
|
+
const shareScopeKeys = Array.isArray(shareScopeName) ? shareScopeName : [shareScopeName];
|
|
7
|
+
var initializeSharingPromises = [];
|
|
8
|
+
var _initializeSharing = function(shareScopeKey) {
|
|
9
|
+
if (!initScope) initScope = [];
|
|
10
|
+
const mfInstance = webpackRequire.federation.instance;
|
|
11
|
+
var initToken = initTokens[shareScopeKey];
|
|
12
|
+
if (!initToken) initToken = initTokens[shareScopeKey] = { from: mfInstance.name };
|
|
13
|
+
if (initScope.indexOf(initToken) >= 0) return;
|
|
14
|
+
initScope.push(initToken);
|
|
15
|
+
const promise = initPromises[shareScopeKey];
|
|
16
|
+
if (promise) return promise;
|
|
17
|
+
var warn = (msg) => typeof console !== "undefined" && console.warn && console.warn(msg);
|
|
18
|
+
var initExternal = (id) => {
|
|
19
|
+
var handleError = (err) => warn("Initialization of sharing external failed: " + err);
|
|
20
|
+
try {
|
|
21
|
+
var module = webpackRequire(id);
|
|
22
|
+
if (!module) return;
|
|
23
|
+
var initFn = (module) => module && module.init && module.init(webpackRequire.S[shareScopeKey], initScope, {
|
|
24
|
+
shareScopeMap: webpackRequire.S || {},
|
|
25
|
+
shareScopeKeys: shareScopeName
|
|
26
|
+
});
|
|
27
|
+
if (module.then) return promises.push(module.then(initFn, handleError));
|
|
28
|
+
var initResult = initFn(module);
|
|
29
|
+
if (initResult && typeof initResult !== "boolean" && initResult.then) return promises.push(initResult["catch"](handleError));
|
|
30
|
+
} catch (err) {
|
|
31
|
+
handleError(err);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const promises = mfInstance.initializeSharing(shareScopeKey, {
|
|
35
|
+
strategy: mfInstance.options.shareStrategy,
|
|
36
|
+
initScope,
|
|
37
|
+
from: "build"
|
|
38
|
+
});
|
|
39
|
+
require_attachShareScopeMap.attachShareScopeMap(webpackRequire);
|
|
40
|
+
const bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
|
|
41
|
+
if (bundlerRuntimeRemotesOptions) Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId) => {
|
|
42
|
+
const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
|
|
43
|
+
const externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
|
|
44
|
+
if (info.length > 1) initExternal(externalModuleId);
|
|
45
|
+
else if (info.length === 1) {
|
|
46
|
+
const remoteInfo = info[0];
|
|
47
|
+
if (!require_constant.FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) initExternal(externalModuleId);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!promises.length) return initPromises[shareScopeKey] = true;
|
|
51
|
+
return initPromises[shareScopeKey] = Promise.all(promises).then(() => initPromises[shareScopeKey] = true);
|
|
52
|
+
};
|
|
53
|
+
shareScopeKeys.forEach((key) => {
|
|
54
|
+
initializeSharingPromises.push(_initializeSharing(key));
|
|
55
|
+
});
|
|
56
|
+
return Promise.all(initializeSharingPromises).then(() => true);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.initializeSharing = initializeSharing;
|
|
61
|
+
//# sourceMappingURL=initializeSharing.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeSharing.cjs","names":["FEDERATION_SUPPORTED_TYPES"],"sources":["../src/initializeSharing.ts"],"sourcesContent":["import { FEDERATION_SUPPORTED_TYPES } from './constant';\nimport { attachShareScopeMap } from './attachShareScopeMap';\nimport { RemoteEntryExports, InitializeSharingOptions } from './types';\n\nexport function initializeSharing({\n shareScopeName,\n webpackRequire,\n initPromises,\n initTokens,\n initScope,\n}: InitializeSharingOptions): Promise<boolean> | boolean | void {\n const shareScopeKeys = Array.isArray(shareScopeName)\n ? shareScopeName\n : [shareScopeName];\n var initializeSharingPromises: Array<Promise<boolean> | boolean | void> = [];\n var _initializeSharing = function (shareScopeKey: string) {\n if (!initScope) initScope = [];\n const mfInstance = webpackRequire.federation.instance!;\n\n // handling circular init calls\n var initToken = initTokens[shareScopeKey];\n if (!initToken)\n initToken = initTokens[shareScopeKey] = { from: mfInstance.name };\n if (initScope.indexOf(initToken) >= 0) return;\n initScope.push(initToken);\n\n const promise = initPromises[shareScopeKey];\n if (promise) return promise;\n var warn = (msg: string) =>\n typeof console !== 'undefined' && console.warn && console.warn(msg);\n\n var initExternal = (id: string | number) => {\n var handleError = (err: any) =>\n warn('Initialization of sharing external failed: ' + err);\n try {\n var module = webpackRequire(id);\n if (!module) return;\n var initFn = (module: RemoteEntryExports) =>\n module &&\n module.init &&\n // @ts-ignore compat legacy mf shared behavior\n module.init(webpackRequire.S![shareScopeKey], initScope, {\n shareScopeMap: webpackRequire.S || {},\n shareScopeKeys: shareScopeName,\n });\n if (module.then) return promises.push(module.then(initFn, handleError));\n var initResult = initFn(module);\n // @ts-ignore\n if (initResult && typeof initResult !== 'boolean' && initResult.then)\n // @ts-ignore\n return promises.push(initResult['catch'](handleError));\n } catch (err) {\n handleError(err);\n }\n };\n const promises = mfInstance.initializeSharing(shareScopeKey, {\n strategy: mfInstance.options.shareStrategy,\n initScope,\n from: 'build',\n });\n attachShareScopeMap(webpackRequire);\n\n const bundlerRuntimeRemotesOptions =\n webpackRequire.federation.bundlerRuntimeOptions.remotes;\n if (bundlerRuntimeRemotesOptions) {\n Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(\n (moduleId) => {\n const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];\n const externalModuleId =\n bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[\n moduleId\n ][2];\n if (info.length > 1) {\n initExternal(externalModuleId);\n } else if (info.length === 1) {\n const remoteInfo = info[0];\n if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {\n initExternal(externalModuleId);\n }\n }\n },\n );\n }\n\n if (!promises.length) {\n return (initPromises[shareScopeKey] = true);\n }\n\n return (initPromises[shareScopeKey] = Promise.all(promises).then(\n () => (initPromises[shareScopeKey] = true),\n ));\n };\n\n shareScopeKeys.forEach((key) => {\n initializeSharingPromises.push(_initializeSharing(key));\n });\n return Promise.all(initializeSharingPromises).then(() => true);\n}\n"],"mappings":";;;;AAIA,SAAgB,kBAAkB,EAChC,gBACA,gBACA,cACA,YACA,aAC8D;CAC9D,MAAM,iBAAiB,MAAM,QAAQ,eAAe,GAChD,iBACA,CAAC,eAAe;CACpB,IAAI,4BAAsE,EAAE;CAC5E,IAAI,qBAAqB,SAAU,eAAuB;AACxD,MAAI,CAAC,UAAW,aAAY,EAAE;EAC9B,MAAM,aAAa,eAAe,WAAW;EAG7C,IAAI,YAAY,WAAW;AAC3B,MAAI,CAAC,UACH,aAAY,WAAW,iBAAiB,EAAE,MAAM,WAAW,MAAM;AACnE,MAAI,UAAU,QAAQ,UAAU,IAAI,EAAG;AACvC,YAAU,KAAK,UAAU;EAEzB,MAAM,UAAU,aAAa;AAC7B,MAAI,QAAS,QAAO;EACpB,IAAI,QAAQ,QACV,OAAO,YAAY,eAAe,QAAQ,QAAQ,QAAQ,KAAK,IAAI;EAErE,IAAI,gBAAgB,OAAwB;GAC1C,IAAI,eAAe,QACjB,KAAK,gDAAgD,IAAI;AAC3D,OAAI;IACF,IAAI,SAAS,eAAe,GAAG;AAC/B,QAAI,CAAC,OAAQ;IACb,IAAI,UAAU,WACZ,UACA,OAAO,QAEP,OAAO,KAAK,eAAe,EAAG,gBAAgB,WAAW;KACvD,eAAe,eAAe,KAAK,EAAE;KACrC,gBAAgB;KACjB,CAAC;AACJ,QAAI,OAAO,KAAM,QAAO,SAAS,KAAK,OAAO,KAAK,QAAQ,YAAY,CAAC;IACvE,IAAI,aAAa,OAAO,OAAO;AAE/B,QAAI,cAAc,OAAO,eAAe,aAAa,WAAW,KAE9D,QAAO,SAAS,KAAK,WAAW,SAAS,YAAY,CAAC;YACjD,KAAK;AACZ,gBAAY,IAAI;;;EAGpB,MAAM,WAAW,WAAW,kBAAkB,eAAe;GAC3D,UAAU,WAAW,QAAQ;GAC7B;GACA,MAAM;GACP,CAAC;AACF,kDAAoB,eAAe;EAEnC,MAAM,+BACJ,eAAe,WAAW,sBAAsB;AAClD,MAAI,6BACF,QAAO,KAAK,6BAA6B,cAAc,CAAC,SACrD,aAAa;GACZ,MAAM,OAAO,6BAA6B,cAAc;GACxD,MAAM,mBACJ,6BAA6B,2BAC3B,UACA;AACJ,OAAI,KAAK,SAAS,EAChB,cAAa,iBAAiB;YACrB,KAAK,WAAW,GAAG;IAC5B,MAAM,aAAa,KAAK;AACxB,QAAI,CAACA,4CAA2B,SAAS,WAAW,aAAa,CAC/D,cAAa,iBAAiB;;IAIrC;AAGH,MAAI,CAAC,SAAS,OACZ,QAAQ,aAAa,iBAAiB;AAGxC,SAAQ,aAAa,iBAAiB,QAAQ,IAAI,SAAS,CAAC,WACnD,aAAa,iBAAiB,KACtC;;AAGH,gBAAe,SAAS,QAAQ;AAC9B,4BAA0B,KAAK,mBAAmB,IAAI,CAAC;GACvD;AACF,QAAO,QAAQ,IAAI,0BAA0B,CAAC,WAAW,KAAK"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { InitializeSharingOptions } from "./types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/initializeSharing.d.ts
|
|
4
|
+
declare function initializeSharing({
|
|
5
|
+
shareScopeName,
|
|
6
|
+
webpackRequire,
|
|
7
|
+
initPromises,
|
|
8
|
+
initTokens,
|
|
9
|
+
initScope
|
|
10
|
+
}: InitializeSharingOptions): Promise<boolean> | boolean | void;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { initializeSharing };
|
|
13
|
+
//# sourceMappingURL=initializeSharing.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { attachShareScopeMap } from "./attachShareScopeMap.js";
|
|
2
|
+
import { FEDERATION_SUPPORTED_TYPES } from "./constant.js";
|
|
3
|
+
|
|
4
|
+
//#region src/initializeSharing.ts
|
|
5
|
+
function initializeSharing({ shareScopeName, webpackRequire, initPromises, initTokens, initScope }) {
|
|
6
|
+
const shareScopeKeys = Array.isArray(shareScopeName) ? shareScopeName : [shareScopeName];
|
|
7
|
+
var initializeSharingPromises = [];
|
|
8
|
+
var _initializeSharing = function(shareScopeKey) {
|
|
9
|
+
if (!initScope) initScope = [];
|
|
10
|
+
const mfInstance = webpackRequire.federation.instance;
|
|
11
|
+
var initToken = initTokens[shareScopeKey];
|
|
12
|
+
if (!initToken) initToken = initTokens[shareScopeKey] = { from: mfInstance.name };
|
|
13
|
+
if (initScope.indexOf(initToken) >= 0) return;
|
|
14
|
+
initScope.push(initToken);
|
|
15
|
+
const promise = initPromises[shareScopeKey];
|
|
16
|
+
if (promise) return promise;
|
|
17
|
+
var warn = (msg) => typeof console !== "undefined" && console.warn && console.warn(msg);
|
|
18
|
+
var initExternal = (id) => {
|
|
19
|
+
var handleError = (err) => warn("Initialization of sharing external failed: " + err);
|
|
20
|
+
try {
|
|
21
|
+
var module = webpackRequire(id);
|
|
22
|
+
if (!module) return;
|
|
23
|
+
var initFn = (module) => module && module.init && module.init(webpackRequire.S[shareScopeKey], initScope, {
|
|
24
|
+
shareScopeMap: webpackRequire.S || {},
|
|
25
|
+
shareScopeKeys: shareScopeName
|
|
26
|
+
});
|
|
27
|
+
if (module.then) return promises.push(module.then(initFn, handleError));
|
|
28
|
+
var initResult = initFn(module);
|
|
29
|
+
if (initResult && typeof initResult !== "boolean" && initResult.then) return promises.push(initResult["catch"](handleError));
|
|
30
|
+
} catch (err) {
|
|
31
|
+
handleError(err);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const promises = mfInstance.initializeSharing(shareScopeKey, {
|
|
35
|
+
strategy: mfInstance.options.shareStrategy,
|
|
36
|
+
initScope,
|
|
37
|
+
from: "build"
|
|
38
|
+
});
|
|
39
|
+
attachShareScopeMap(webpackRequire);
|
|
40
|
+
const bundlerRuntimeRemotesOptions = webpackRequire.federation.bundlerRuntimeOptions.remotes;
|
|
41
|
+
if (bundlerRuntimeRemotesOptions) Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach((moduleId) => {
|
|
42
|
+
const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];
|
|
43
|
+
const externalModuleId = bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[moduleId][2];
|
|
44
|
+
if (info.length > 1) initExternal(externalModuleId);
|
|
45
|
+
else if (info.length === 1) {
|
|
46
|
+
const remoteInfo = info[0];
|
|
47
|
+
if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) initExternal(externalModuleId);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!promises.length) return initPromises[shareScopeKey] = true;
|
|
51
|
+
return initPromises[shareScopeKey] = Promise.all(promises).then(() => initPromises[shareScopeKey] = true);
|
|
52
|
+
};
|
|
53
|
+
shareScopeKeys.forEach((key) => {
|
|
54
|
+
initializeSharingPromises.push(_initializeSharing(key));
|
|
55
|
+
});
|
|
56
|
+
return Promise.all(initializeSharingPromises).then(() => true);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
export { initializeSharing };
|
|
61
|
+
//# sourceMappingURL=initializeSharing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeSharing.js","names":[],"sources":["../src/initializeSharing.ts"],"sourcesContent":["import { FEDERATION_SUPPORTED_TYPES } from './constant';\nimport { attachShareScopeMap } from './attachShareScopeMap';\nimport { RemoteEntryExports, InitializeSharingOptions } from './types';\n\nexport function initializeSharing({\n shareScopeName,\n webpackRequire,\n initPromises,\n initTokens,\n initScope,\n}: InitializeSharingOptions): Promise<boolean> | boolean | void {\n const shareScopeKeys = Array.isArray(shareScopeName)\n ? shareScopeName\n : [shareScopeName];\n var initializeSharingPromises: Array<Promise<boolean> | boolean | void> = [];\n var _initializeSharing = function (shareScopeKey: string) {\n if (!initScope) initScope = [];\n const mfInstance = webpackRequire.federation.instance!;\n\n // handling circular init calls\n var initToken = initTokens[shareScopeKey];\n if (!initToken)\n initToken = initTokens[shareScopeKey] = { from: mfInstance.name };\n if (initScope.indexOf(initToken) >= 0) return;\n initScope.push(initToken);\n\n const promise = initPromises[shareScopeKey];\n if (promise) return promise;\n var warn = (msg: string) =>\n typeof console !== 'undefined' && console.warn && console.warn(msg);\n\n var initExternal = (id: string | number) => {\n var handleError = (err: any) =>\n warn('Initialization of sharing external failed: ' + err);\n try {\n var module = webpackRequire(id);\n if (!module) return;\n var initFn = (module: RemoteEntryExports) =>\n module &&\n module.init &&\n // @ts-ignore compat legacy mf shared behavior\n module.init(webpackRequire.S![shareScopeKey], initScope, {\n shareScopeMap: webpackRequire.S || {},\n shareScopeKeys: shareScopeName,\n });\n if (module.then) return promises.push(module.then(initFn, handleError));\n var initResult = initFn(module);\n // @ts-ignore\n if (initResult && typeof initResult !== 'boolean' && initResult.then)\n // @ts-ignore\n return promises.push(initResult['catch'](handleError));\n } catch (err) {\n handleError(err);\n }\n };\n const promises = mfInstance.initializeSharing(shareScopeKey, {\n strategy: mfInstance.options.shareStrategy,\n initScope,\n from: 'build',\n });\n attachShareScopeMap(webpackRequire);\n\n const bundlerRuntimeRemotesOptions =\n webpackRequire.federation.bundlerRuntimeOptions.remotes;\n if (bundlerRuntimeRemotesOptions) {\n Object.keys(bundlerRuntimeRemotesOptions.idToRemoteMap).forEach(\n (moduleId) => {\n const info = bundlerRuntimeRemotesOptions.idToRemoteMap[moduleId];\n const externalModuleId =\n bundlerRuntimeRemotesOptions.idToExternalAndNameMapping[\n moduleId\n ][2];\n if (info.length > 1) {\n initExternal(externalModuleId);\n } else if (info.length === 1) {\n const remoteInfo = info[0];\n if (!FEDERATION_SUPPORTED_TYPES.includes(remoteInfo.externalType)) {\n initExternal(externalModuleId);\n }\n }\n },\n );\n }\n\n if (!promises.length) {\n return (initPromises[shareScopeKey] = true);\n }\n\n return (initPromises[shareScopeKey] = Promise.all(promises).then(\n () => (initPromises[shareScopeKey] = true),\n ));\n };\n\n shareScopeKeys.forEach((key) => {\n initializeSharingPromises.push(_initializeSharing(key));\n });\n return Promise.all(initializeSharingPromises).then(() => true);\n}\n"],"mappings":";;;;AAIA,SAAgB,kBAAkB,EAChC,gBACA,gBACA,cACA,YACA,aAC8D;CAC9D,MAAM,iBAAiB,MAAM,QAAQ,eAAe,GAChD,iBACA,CAAC,eAAe;CACpB,IAAI,4BAAsE,EAAE;CAC5E,IAAI,qBAAqB,SAAU,eAAuB;AACxD,MAAI,CAAC,UAAW,aAAY,EAAE;EAC9B,MAAM,aAAa,eAAe,WAAW;EAG7C,IAAI,YAAY,WAAW;AAC3B,MAAI,CAAC,UACH,aAAY,WAAW,iBAAiB,EAAE,MAAM,WAAW,MAAM;AACnE,MAAI,UAAU,QAAQ,UAAU,IAAI,EAAG;AACvC,YAAU,KAAK,UAAU;EAEzB,MAAM,UAAU,aAAa;AAC7B,MAAI,QAAS,QAAO;EACpB,IAAI,QAAQ,QACV,OAAO,YAAY,eAAe,QAAQ,QAAQ,QAAQ,KAAK,IAAI;EAErE,IAAI,gBAAgB,OAAwB;GAC1C,IAAI,eAAe,QACjB,KAAK,gDAAgD,IAAI;AAC3D,OAAI;IACF,IAAI,SAAS,eAAe,GAAG;AAC/B,QAAI,CAAC,OAAQ;IACb,IAAI,UAAU,WACZ,UACA,OAAO,QAEP,OAAO,KAAK,eAAe,EAAG,gBAAgB,WAAW;KACvD,eAAe,eAAe,KAAK,EAAE;KACrC,gBAAgB;KACjB,CAAC;AACJ,QAAI,OAAO,KAAM,QAAO,SAAS,KAAK,OAAO,KAAK,QAAQ,YAAY,CAAC;IACvE,IAAI,aAAa,OAAO,OAAO;AAE/B,QAAI,cAAc,OAAO,eAAe,aAAa,WAAW,KAE9D,QAAO,SAAS,KAAK,WAAW,SAAS,YAAY,CAAC;YACjD,KAAK;AACZ,gBAAY,IAAI;;;EAGpB,MAAM,WAAW,WAAW,kBAAkB,eAAe;GAC3D,UAAU,WAAW,QAAQ;GAC7B;GACA,MAAM;GACP,CAAC;AACF,sBAAoB,eAAe;EAEnC,MAAM,+BACJ,eAAe,WAAW,sBAAsB;AAClD,MAAI,6BACF,QAAO,KAAK,6BAA6B,cAAc,CAAC,SACrD,aAAa;GACZ,MAAM,OAAO,6BAA6B,cAAc;GACxD,MAAM,mBACJ,6BAA6B,2BAC3B,UACA;AACJ,OAAI,KAAK,SAAS,EAChB,cAAa,iBAAiB;YACrB,KAAK,WAAW,GAAG;IAC5B,MAAM,aAAa,KAAK;AACxB,QAAI,CAAC,2BAA2B,SAAS,WAAW,aAAa,CAC/D,cAAa,iBAAiB;;IAIrC;AAGH,MAAI,CAAC,SAAS,OACZ,QAAQ,aAAa,iBAAiB;AAGxC,SAAQ,aAAa,iBAAiB,QAAQ,IAAI,SAAS,CAAC,WACnD,aAAa,iBAAiB,KACtC;;AAGH,gBAAe,SAAS,QAAQ;AAC9B,4BAA0B,KAAK,mBAAmB,IAAI,CAAC;GACvD;AACF,QAAO,QAAQ,IAAI,0BAA0B,CAAC,WAAW,KAAK"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const require_updateOptions = require('./updateOptions.cjs');
|
|
2
|
+
const require_getUsedExports = require('./getUsedExports.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/installInitialConsumes.ts
|
|
5
|
+
function handleInitialConsumes(options) {
|
|
6
|
+
const { moduleId, moduleToHandlerMapping, webpackRequire, asyncLoad } = options;
|
|
7
|
+
const federationInstance = webpackRequire.federation.instance;
|
|
8
|
+
if (!federationInstance) throw new Error("Federation instance not found!");
|
|
9
|
+
const { shareKey, shareInfo } = moduleToHandlerMapping[moduleId];
|
|
10
|
+
try {
|
|
11
|
+
const usedExports = require_getUsedExports.getUsedExports(webpackRequire, shareKey);
|
|
12
|
+
const customShareInfo = { ...shareInfo };
|
|
13
|
+
if (usedExports) customShareInfo.treeShaking = {
|
|
14
|
+
usedExports,
|
|
15
|
+
useIn: [federationInstance.options.name]
|
|
16
|
+
};
|
|
17
|
+
if (asyncLoad) return federationInstance.loadShare(shareKey, {
|
|
18
|
+
customShareInfo,
|
|
19
|
+
context: {
|
|
20
|
+
trigger: "build",
|
|
21
|
+
moduleId
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
return federationInstance.loadShareSync(shareKey, {
|
|
25
|
+
customShareInfo,
|
|
26
|
+
context: {
|
|
27
|
+
trigger: "build",
|
|
28
|
+
moduleId
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error("loadShareSync failed! The function should not be called unless you set \"eager:true\". If you do not set it, and encounter this issue, you can check whether an async boundary is implemented.");
|
|
33
|
+
console.error("The original error message is as follows: ");
|
|
34
|
+
throw err;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function installInitialConsumes(options) {
|
|
38
|
+
require_updateOptions.updateConsumeOptions(options);
|
|
39
|
+
const { moduleToHandlerMapping, webpackRequire, installedModules, initialConsumes, asyncLoad } = options;
|
|
40
|
+
const factoryIdSets = [];
|
|
41
|
+
initialConsumes.forEach((id) => {
|
|
42
|
+
const factoryGetter = () => handleInitialConsumes({
|
|
43
|
+
moduleId: id,
|
|
44
|
+
moduleToHandlerMapping,
|
|
45
|
+
webpackRequire,
|
|
46
|
+
asyncLoad
|
|
47
|
+
});
|
|
48
|
+
factoryIdSets.push([id, factoryGetter]);
|
|
49
|
+
});
|
|
50
|
+
const setModule = (id, factoryGetter) => {
|
|
51
|
+
webpackRequire.m[id] = (module) => {
|
|
52
|
+
installedModules[id] = 0;
|
|
53
|
+
delete webpackRequire.c[id];
|
|
54
|
+
const factory = factoryGetter();
|
|
55
|
+
if (typeof factory !== "function") throw new Error(`Shared module is not available for eager consumption: ${id}`);
|
|
56
|
+
const result = factory();
|
|
57
|
+
const { shareInfo } = moduleToHandlerMapping[id];
|
|
58
|
+
if (shareInfo?.shareConfig?.layer && result && typeof result === "object") try {
|
|
59
|
+
if (!result.hasOwnProperty("layer") || result.layer === void 0) result.layer = shareInfo.shareConfig.layer;
|
|
60
|
+
} catch (e) {}
|
|
61
|
+
module.exports = result;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
if (asyncLoad) return Promise.all(factoryIdSets.map(async ([id, factoryGetter]) => {
|
|
65
|
+
const result = await factoryGetter();
|
|
66
|
+
setModule(id, () => result);
|
|
67
|
+
}));
|
|
68
|
+
factoryIdSets.forEach(([id, factoryGetter]) => {
|
|
69
|
+
setModule(id, factoryGetter);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
//#endregion
|
|
74
|
+
exports.installInitialConsumes = installInitialConsumes;
|
|
75
|
+
//# sourceMappingURL=installInitialConsumes.cjs.map
|