import type { ModuleFederationRuntimePlugin } from "@module-federation/runtime/types"; /** * Foward Module Federation lifecycle events to a provided logging function * from workbench. * * @public */ export function log( onDebug: (message: string, context?: Record) => void, ): ModuleFederationRuntimePlugin { const logEvent = (eventName: string, args: unknown) => { // `origin` logs the whole instance, which is noisy const { origin: _origin, ...data } = typeof args === "object" && args !== null ? (args as Record) : { args }; onDebug(`[Lifecycle] ${eventName}`, data); }; return { name: "sanity-logger", beforeInit(args) { logEvent("beforeInit", args); return args; }, beforeRegisterRemote(args) { logEvent("beforeRegisterRemote", args); return args; }, beforePreloadRemote(args) { logEvent("beforePreloadRemote", args); }, beforeRequest(args) { logEvent("beforeRequest", args); return args; }, afterResolve(args) { logEvent("afterResolve", args); return args; }, onLoad(args) { logEvent("onLoad", args); return args; }, loadShare(args) { logEvent("loadShare", args); }, beforeLoadShare(args) { logEvent("beforeLoadShare", args); return args; }, }; }