mirror of
https://github.com/Tria-plc/emaui.git
synced 2026-08-27 08:32:56 +00:00
101 lines
3.1 KiB
JavaScript
101 lines
3.1 KiB
JavaScript
import { styleText } from "node:util";
|
|
import { getManifestFileName } from "@module-federation/sdk";
|
|
import { isDev } from "./utils.mjs";
|
|
import logger from "./logger.mjs";
|
|
|
|
;// CONCATENATED MODULE: external "node:util"
|
|
|
|
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
|
|
;// CONCATENATED MODULE: external "./utils.mjs"
|
|
|
|
;// CONCATENATED MODULE: external "./logger.mjs"
|
|
|
|
;// CONCATENATED MODULE: ./src/ManifestManager.ts
|
|
|
|
|
|
|
|
|
|
class ManifestManager {
|
|
init(options) {
|
|
this._options = options;
|
|
}
|
|
get fileName() {
|
|
return getManifestFileName(this._options.manifest).manifestFileName;
|
|
}
|
|
updateManifest(options) {
|
|
const manifest = this.generateManifest(options);
|
|
return manifest;
|
|
}
|
|
generateManifest(options) {
|
|
const { publicPath, stats, compiler } = options;
|
|
// Initialize manifest with required properties from stats
|
|
const { id, name, metaData } = stats;
|
|
if (metaData.buildInfo) {
|
|
'target' in metaData.buildInfo && delete metaData.buildInfo.target;
|
|
'plugins' in metaData.buildInfo && delete metaData.buildInfo.plugins;
|
|
}
|
|
const manifest = {
|
|
id,
|
|
name,
|
|
metaData,
|
|
shared: [],
|
|
remotes: [],
|
|
exposes: []
|
|
};
|
|
manifest.exposes = stats.exposes.reduce((sum, cur)=>{
|
|
const expose = {
|
|
id: cur.id,
|
|
name: cur.name,
|
|
assets: cur.assets,
|
|
path: cur.path
|
|
};
|
|
sum.push(expose);
|
|
return sum;
|
|
}, []);
|
|
manifest.shared = stats.shared.reduce((sum, cur)=>{
|
|
const shared = {
|
|
id: cur.id,
|
|
name: cur.name,
|
|
version: cur.version,
|
|
singleton: cur.singleton,
|
|
requiredVersion: cur.requiredVersion,
|
|
hash: cur.hash,
|
|
assets: cur.assets,
|
|
fallback: cur.fallback,
|
|
fallbackName: cur.fallbackName,
|
|
fallbackType: cur.fallbackType
|
|
};
|
|
sum.push(shared);
|
|
return sum;
|
|
}, []);
|
|
manifest.remotes = stats.remotes.reduce((sum, cur)=>{
|
|
// @ts-ignore version/entry will be added as follow
|
|
const remote = {
|
|
federationContainerName: cur.federationContainerName,
|
|
moduleName: cur.moduleName,
|
|
alias: cur.alias
|
|
};
|
|
if ('entry' in cur) {
|
|
// @ts-ignore
|
|
remote.entry = cur.entry;
|
|
} else if ('version' in cur) {
|
|
// @ts-ignore
|
|
remote.entry = cur.version;
|
|
}
|
|
sum.push(remote);
|
|
return sum;
|
|
}, []);
|
|
if (isDev() && (process.env['MF_SSR_PRJ'] ? compiler.options.target !== 'async-node' : true)) {
|
|
logger.info(`Manifest Link: ${styleText('cyan', `${publicPath === 'auto' ? '{auto}/' : publicPath}${this.fileName}`)} `);
|
|
}
|
|
return manifest;
|
|
}
|
|
constructor(){
|
|
this._options = {};
|
|
}
|
|
}
|
|
|
|
|
|
export { ManifestManager };
|