@esmx/core
Version:
A high-performance microfrontend framework supporting Vue, React, Preact, Solid, and Svelte with SSR and Module Federation capabilities.
38 lines (37 loc) • 1.21 kB
JavaScript
import { pathWithoutIndex } from "./path-without-index.mjs";
export function getImportMap({
manifests,
getFile,
getScope
}) {
const imports = {};
const scopes = {};
Object.values(manifests).forEach((manifest) => {
const scopeImports = {};
Object.entries(manifest.exports).forEach(([key, exportItem]) => {
if (typeof exportItem === "string") {
throw new Error(
`Detected incompatible legacy manifest format in ${manifest.name}. Please upgrade your ESMX dependencies first, then rebuild and redeploy your service.`
);
}
const file = getFile(manifest.name, exportItem.file);
imports[exportItem.identifier] = file;
if (!exportItem.rewrite) {
scopeImports[exportItem.name] = file;
}
});
if (Object.keys(scopeImports).length || Object.keys(imports).length) {
scopes[getScope(manifest.name)] = scopeImports;
}
});
pathWithoutIndex(imports);
Object.values(manifests).forEach((manifest) => {
Object.entries(manifest.imports).forEach(([name, identifier]) => {
scopes[getScope(manifest.name)][name] = imports[identifier] ?? identifier;
});
});
return {
imports,
scopes
};
}