UNPKG

vanilla-native-federation

Version:

A lightweight **runtime micro frontend orchestrator** that loads micro frontends built with native federation into any web page. It can cache dependencies across page reloads, making it perfect for traditional server-rendered hosts (PHP, Java, Rails, etc.

68 lines (66 loc) 2.86 kB
// src/lib/native-federation.error.ts var NFError = class extends Error { constructor(message, cause) { super(message, cause); this.name = "NFError"; } }; // src/lib/2.app/flows/audit/externals-audit.ts function createExternalsAudit(config, ports) { return (remoteEntry) => { let success = true; remoteEntry.shared.filter((external) => !external.singleton).forEach((external) => { const isValid2 = checkIfExternalCouldBeSingleton(external, remoteEntry); if (!isValid2) success = false; }); const isValid = warnForScopedSingletons(remoteEntry); if (!isValid) success = false; if (!success && config.strict.strictExternalCompatibility) { config.log.error(3, `[${remoteEntry.name}] Not all externals are compatible.`); return Promise.reject(new NFError(`Failed externals audit`)); } return Promise.resolve(); }; function checkIfExternalCouldBeSingleton(targetExternal, remoteEntry) { for (const shareScope of ports.sharedExternalsRepo.getScopes()) { const sharedExternal = ports.sharedExternalsRepo.getFromScope(shareScope)[targetExternal.packageName]; if (!sharedExternal) continue; for (const version of sharedExternal.versions) { if (version.action !== "share") return true; if (ports.versionCheck.isCompatible(version.tag, targetExternal.requiredVersion)) { const msg = `[${remoteEntry.name}][scoped][${shareScope}][${targetExternal.packageName}] External is compatible with shared range '${version.remotes[0].requiredVersion}'. Should be 'singleton: true'`; config.log.warn(3, msg); return false; } } } return true; } function warnForScopedSingletons(remoteEntry) { let success = true; for (const shareScope of ports.sharedExternalsRepo.getScopes()) { for (const [packageName, external] of Object.entries( ports.sharedExternalsRepo.getFromScope(shareScope) )) { for (const version of external.versions) { if (version.action !== "scope") continue; if (version.remotes.some((remote) => remote.name === remoteEntry.name)) { const sharedVersion = external.versions.find((v) => v.action === "share"); const isOlder = sharedVersion && ports.versionCheck.compare(version.tag, sharedVersion.tag) === -1; let msg = `[${remoteEntry.name}][shared][${shareScope}][${packageName}@${version.tag}] External is ${isOlder ? "older" : "newer"} than shared compatible range '${sharedVersion?.remotes[0].requiredVersion}'.`; if (isOlder) { success = false; msg += " Should be 'singleton: false'"; } config.log.warn(3, msg); } } } } return success; } } export { createExternalsAudit }; //# sourceMappingURL=audit.mjs.map