everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
38 lines (36 loc) • 1.89 kB
JavaScript
import { walkRemotes } from "../remotes.mjs";
import { remoteDigests } from "../registry/fingerprint.mjs";
//#region src/services/deploy/changed-slots.ts
/** Surfaces the running host adopts without a process restart. */
function isHotRemote(remote) {
return remote === "app.ui" || /^plugins\.[^.]+\.ui$/.test(remote);
}
function isUiOnlyDiff(diff) {
return !diff.configChanged && diff.changedRemotes.length > 0 && diff.changedRemotes.every(isHotRemote);
}
/** Key-sorted JSON so two serializations of the same document compare equal. */
function canonical(value) {
if (Array.isArray(value)) return `[${value.map(canonical).join(",")}]`;
if (value && typeof value === "object") return `{${Object.entries(value).filter(([, v]) => v !== void 0).map(([k, v]) => `${JSON.stringify(k)}:${canonical(v)}`).sort().join(",")}}`;
return JSON.stringify(value) ?? "null";
}
/** Deep clone with every remote's `digest` pin removed — the volatile
* coordinates the hot/cold classification excludes from the body compare. */
function withoutRemoteDigests(config) {
const clone = JSON.parse(JSON.stringify(config ?? {}));
walkRemotes(clone, ({ entry }) => {
if (entry && typeof entry === "object" && !Array.isArray(entry)) delete entry.digest;
});
return clone;
}
function classifyPublishedDiff(previous, next) {
const previousRemotes = previous ? remoteDigests(previous) : {};
const nextRemotes = remoteDigests(next);
return {
changedRemotes: Object.keys(previousRemotes).concat(Object.keys(nextRemotes)).filter((remote, index, all) => all.indexOf(remote) === index).filter((remote) => previousRemotes[remote] !== nextRemotes[remote]).sort(),
configChanged: previous ? canonical(withoutRemoteDigests(previous)) !== canonical(withoutRemoteDigests(next)) : true
};
}
//#endregion
export { classifyPublishedDiff, isHotRemote, isUiOnlyDiff };
//# sourceMappingURL=changed-slots.mjs.map