mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-29 18:48:12 +00:00
88 lines
4.2 KiB
JavaScript
88 lines
4.2 KiB
JavaScript
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
|
|
const require_runtime = require('../../_virtual/_rolldown/runtime.js');
|
|
const require_lib_container_runtime_utils = require('./runtime/utils.js');
|
|
let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
|
|
//#region src/lib/container/RemoteRuntimeModule.ts
|
|
const extractUrlAndGlobal = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/extractUrlAndGlobal"));
|
|
const { Template, RuntimeModule, RuntimeGlobals } = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
var RemoteRuntimeModule = class extends RuntimeModule {
|
|
constructor() {
|
|
super("remotes loading");
|
|
}
|
|
/**
|
|
* @returns {string | null} runtime code
|
|
*/
|
|
generate() {
|
|
const { compilation, chunkGraph } = this;
|
|
const { runtimeTemplate, moduleGraph } = compilation;
|
|
const chunkToRemotesMapping = {};
|
|
const idToExternalAndNameMapping = {};
|
|
const idToRemoteMap = {};
|
|
const moduleIdToRemoteDataMapping = {};
|
|
const allChunks = [...Array.from(this.chunk?.getAllReferencedChunks() || [])];
|
|
for (const chunk of allChunks) {
|
|
if (chunk.id === null || chunk.id === void 0) continue;
|
|
const modules = chunkGraph?.getChunkModulesIterableBySourceType(chunk, "remote");
|
|
if (!modules) continue;
|
|
const remotes = chunkToRemotesMapping[chunk.id] = [];
|
|
for (const m of modules) {
|
|
const module = m;
|
|
const name = module.internalRequest;
|
|
const id = chunkGraph ? chunkGraph.getModuleId(module) : void 0;
|
|
const { shareScope } = module;
|
|
const dep = module.dependencies[0];
|
|
const externalModule = moduleGraph.getModule(dep);
|
|
const externalModuleId = chunkGraph && externalModule ? chunkGraph.getModuleId(externalModule) : void 0;
|
|
if (id !== void 0 && id !== null) {
|
|
remotes.push(id);
|
|
idToExternalAndNameMapping[id] = [
|
|
shareScope,
|
|
name,
|
|
externalModuleId === null || externalModuleId === void 0 ? void 0 : externalModuleId
|
|
];
|
|
const remoteModules = [];
|
|
if ("requests" in externalModule && externalModule.requests) externalModule.dependencies.forEach((dependency) => {
|
|
const remoteModule = moduleGraph.getModule(dependency);
|
|
if (remoteModule) remoteModules.push(remoteModule);
|
|
});
|
|
else remoteModules.push(externalModule);
|
|
idToRemoteMap[id] = [];
|
|
remoteModules.forEach((remoteModule) => {
|
|
let remoteName = "";
|
|
try {
|
|
const [_url, name] = extractUrlAndGlobal(remoteModule.request);
|
|
remoteName = name;
|
|
} catch (err) {}
|
|
const externalModuleId = chunkGraph && remoteModule && chunkGraph.getModuleId(remoteModule);
|
|
idToRemoteMap[id].push({
|
|
externalType: remoteModule.externalType,
|
|
name: remoteModule.externalType === "script" ? remoteName : ""
|
|
});
|
|
if (externalModuleId !== null && externalModuleId !== void 0) moduleIdToRemoteDataMapping[id] = {
|
|
shareScope,
|
|
name,
|
|
externalModuleId,
|
|
remoteName
|
|
};
|
|
});
|
|
}
|
|
}
|
|
}
|
|
const federationGlobal = require_lib_container_runtime_utils.getFederationGlobalScope(RuntimeGlobals || {});
|
|
return Template.asString([
|
|
`var chunkMapping = ${JSON.stringify(chunkToRemotesMapping, null, " ")};`,
|
|
`var idToExternalAndNameMapping = ${JSON.stringify(idToExternalAndNameMapping, null, " ")};`,
|
|
`var idToRemoteMap = ${JSON.stringify(idToRemoteMap, null, " ")};`,
|
|
`${federationGlobal}.bundlerRuntimeOptions.remotes.chunkMapping = chunkMapping;`,
|
|
`${federationGlobal}.bundlerRuntimeOptions.remotes.idToExternalAndNameMapping = idToExternalAndNameMapping;`,
|
|
`${federationGlobal}.bundlerRuntimeOptions.remotes.idToRemoteMap = idToRemoteMap;`,
|
|
`${RuntimeGlobals.require}.remotesLoadingData.moduleIdToRemoteDataMapping = ${JSON.stringify(moduleIdToRemoteDataMapping, null, " ")};`,
|
|
`${RuntimeGlobals.ensureChunkHandlers}.remotes = ${runtimeTemplate.basicFunction("chunkId, promises", [`${federationGlobal}.bundlerRuntime.remotes({idToRemoteMap,chunkMapping, idToExternalAndNameMapping, chunkId, promises, webpackRequire:${RuntimeGlobals.require}});`])}`
|
|
]);
|
|
}
|
|
};
|
|
|
|
//#endregion
|
|
exports.default = RemoteRuntimeModule;
|
|
//# sourceMappingURL=RemoteRuntimeModule.js.map
|