mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 01:22:49 +00:00
61 lines
2.6 KiB
JavaScript
61 lines
2.6 KiB
JavaScript
import { attachShareScopeMap } from "./attachShareScopeMap.js";
|
|
import { updateConsumeOptions } from "./updateOptions.js";
|
|
import { getUsedExports } from "./getUsedExports.js";
|
|
import { RUNTIME_012 } from "./error-codes/dist/error-codes.js";
|
|
import { getShortErrorMsg } from "./error-codes/dist/getShortErrorMsg.js";
|
|
|
|
//#region src/consumes.ts
|
|
function consumes(options) {
|
|
updateConsumeOptions(options);
|
|
const { chunkId, promises, installedModules, webpackRequire, chunkMapping, moduleToHandlerMapping } = options;
|
|
attachShareScopeMap(webpackRequire);
|
|
if (webpackRequire.o(chunkMapping, chunkId)) chunkMapping[chunkId].forEach((id) => {
|
|
if (webpackRequire.o(installedModules, id)) return promises.push(installedModules[id]);
|
|
const onFactory = (factory) => {
|
|
installedModules[id] = 0;
|
|
webpackRequire.m[id] = (module) => {
|
|
delete webpackRequire.c[id];
|
|
const result = factory();
|
|
const { shareInfo } = moduleToHandlerMapping[id];
|
|
if (shareInfo?.shareConfig?.layer && result && typeof result === "object") try {
|
|
if (!result.hasOwnProperty("layer") || result.layer === void 0) result.layer = shareInfo.shareConfig.layer;
|
|
} catch (e) {}
|
|
module.exports = result;
|
|
};
|
|
};
|
|
const onError = (error) => {
|
|
delete installedModules[id];
|
|
webpackRequire.m[id] = (module) => {
|
|
delete webpackRequire.c[id];
|
|
throw error;
|
|
};
|
|
};
|
|
try {
|
|
const federationInstance = webpackRequire.federation.instance;
|
|
if (!federationInstance) throw new Error("Federation instance not found!");
|
|
const { shareKey, getter, shareInfo, treeShakingGetter } = moduleToHandlerMapping[id];
|
|
const usedExports = getUsedExports(webpackRequire, shareKey);
|
|
const customShareInfo = { ...shareInfo };
|
|
if (Array.isArray(customShareInfo.scope) && Array.isArray(customShareInfo.scope[0])) customShareInfo.scope = customShareInfo.scope[0];
|
|
if (usedExports) customShareInfo.treeShaking = {
|
|
usedExports,
|
|
useIn: [federationInstance.options.name]
|
|
};
|
|
const promise = federationInstance.loadShare(shareKey, { customShareInfo }).then((factory) => {
|
|
if (factory === false) {
|
|
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 }));
|
|
return treeShakingGetter?.() || getter();
|
|
}
|
|
return factory;
|
|
});
|
|
if (promise.then) promises.push(installedModules[id] = promise.then(onFactory).catch(onError));
|
|
else onFactory(promise);
|
|
} catch (e) {
|
|
onError(e);
|
|
}
|
|
});
|
|
}
|
|
|
|
//#endregion
|
|
export { consumes };
|
|
//# sourceMappingURL=consumes.js.map
|