mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 08:32:56 +00:00
110 lines
4.5 KiB
JavaScript
110 lines
4.5 KiB
JavaScript
//#region src/updateOptions.ts
|
|
function updateConsumeOptions(options) {
|
|
const { webpackRequire, moduleToHandlerMapping } = options;
|
|
const { consumesLoadingData, initializeSharingData } = webpackRequire;
|
|
const { sharedFallback, bundlerRuntime, libraryType } = webpackRequire.federation;
|
|
if (consumesLoadingData && !consumesLoadingData._updated) {
|
|
const { moduleIdToConsumeDataMapping: updatedModuleIdToConsumeDataMapping = {}, initialConsumes: updatedInitialConsumes = [], chunkMapping: updatedChunkMapping = {} } = consumesLoadingData;
|
|
Object.entries(updatedModuleIdToConsumeDataMapping).forEach(([id, data]) => {
|
|
if (!moduleToHandlerMapping[id]) moduleToHandlerMapping[id] = {
|
|
getter: sharedFallback ? bundlerRuntime?.getSharedFallbackGetter({
|
|
shareKey: data.shareKey,
|
|
factory: data.fallback,
|
|
webpackRequire,
|
|
libraryType
|
|
}) : data.fallback,
|
|
treeShakingGetter: sharedFallback ? data.fallback : void 0,
|
|
shareInfo: {
|
|
shareConfig: {
|
|
requiredVersion: data.requiredVersion,
|
|
strictVersion: data.strictVersion,
|
|
singleton: data.singleton,
|
|
eager: data.eager,
|
|
layer: data.layer
|
|
},
|
|
scope: Array.isArray(data.shareScope) ? data.shareScope : [data.shareScope || "default"],
|
|
treeShaking: sharedFallback ? {
|
|
get: data.fallback,
|
|
mode: data.treeShakingMode
|
|
} : void 0
|
|
},
|
|
shareKey: data.shareKey
|
|
};
|
|
});
|
|
if ("initialConsumes" in options) {
|
|
const { initialConsumes = [] } = options;
|
|
updatedInitialConsumes.forEach((id) => {
|
|
if (!initialConsumes.includes(id)) initialConsumes.push(id);
|
|
});
|
|
}
|
|
if ("chunkMapping" in options) {
|
|
const { chunkMapping = {} } = options;
|
|
Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
if (!chunkMapping[id]) chunkMapping[id] = [];
|
|
chunkModules.forEach((moduleId) => {
|
|
if (!chunkMapping[id].includes(moduleId)) chunkMapping[id].push(moduleId);
|
|
});
|
|
});
|
|
}
|
|
consumesLoadingData._updated = 1;
|
|
}
|
|
if (initializeSharingData && !initializeSharingData._updated) {
|
|
const { federation } = webpackRequire;
|
|
if (!federation.instance || !initializeSharingData.scopeToSharingDataMapping) return;
|
|
const shared = {};
|
|
for (let [scope, stages] of Object.entries(initializeSharingData.scopeToSharingDataMapping)) for (let stage of stages) if (typeof stage === "object" && stage !== null) {
|
|
const { name, version, factory, eager, singleton, requiredVersion, strictVersion } = stage;
|
|
const shareConfig = { requiredVersion: `^${version}` };
|
|
const isValidValue = function(val) {
|
|
return typeof val !== "undefined";
|
|
};
|
|
if (isValidValue(singleton)) shareConfig.singleton = singleton;
|
|
if (isValidValue(requiredVersion)) shareConfig.requiredVersion = requiredVersion;
|
|
if (isValidValue(eager)) shareConfig.eager = eager;
|
|
if (isValidValue(strictVersion)) shareConfig.strictVersion = strictVersion;
|
|
const options = {
|
|
version,
|
|
scope: [scope],
|
|
shareConfig,
|
|
get: factory
|
|
};
|
|
if (shared[name]) shared[name].push(options);
|
|
else shared[name] = [options];
|
|
}
|
|
federation.instance.registerShared(shared);
|
|
initializeSharingData._updated = 1;
|
|
}
|
|
}
|
|
function updateRemoteOptions(options) {
|
|
const { webpackRequire, idToExternalAndNameMapping = {}, idToRemoteMap = {}, chunkMapping = {} } = options;
|
|
const { remotesLoadingData } = webpackRequire;
|
|
const remoteInfos = webpackRequire.federation?.bundlerRuntimeOptions?.remotes?.remoteInfos;
|
|
if (!remotesLoadingData || remotesLoadingData._updated || !remoteInfos) return;
|
|
const { chunkMapping: updatedChunkMapping, moduleIdToRemoteDataMapping } = remotesLoadingData;
|
|
if (!updatedChunkMapping || !moduleIdToRemoteDataMapping) return;
|
|
for (let [moduleId, data] of Object.entries(moduleIdToRemoteDataMapping)) {
|
|
if (!idToExternalAndNameMapping[moduleId]) idToExternalAndNameMapping[moduleId] = [
|
|
data.shareScope,
|
|
data.name,
|
|
data.externalModuleId
|
|
];
|
|
if (!idToRemoteMap[moduleId] && remoteInfos[data.remoteName]) {
|
|
const items = remoteInfos[data.remoteName];
|
|
idToRemoteMap[moduleId] ||= [];
|
|
items.forEach((item) => {
|
|
if (!idToRemoteMap[moduleId].includes(item)) idToRemoteMap[moduleId].push(item);
|
|
});
|
|
}
|
|
}
|
|
if (chunkMapping) Object.entries(updatedChunkMapping).forEach(([id, chunkModules]) => {
|
|
if (!chunkMapping[id]) chunkMapping[id] = [];
|
|
chunkModules.forEach((moduleId) => {
|
|
if (!chunkMapping[id].includes(moduleId)) chunkMapping[id].push(moduleId);
|
|
});
|
|
});
|
|
remotesLoadingData._updated = 1;
|
|
}
|
|
|
|
//#endregion
|
|
export { updateConsumeOptions, updateRemoteOptions };
|
|
//# sourceMappingURL=updateOptions.js.map
|