refactor: simplify plugin runtime singletons

This commit is contained in:
Peter Steinberger
2026-03-22 17:57:57 +00:00
parent 9428b38452
commit f095bbd7b0
4 changed files with 26 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
import { resolveGlobalSingleton } from "../shared/global-singleton.js";
import { createEmptyPluginRegistry } from "./registry-empty.js";
import type { PluginRegistry } from "./registry.js";
@@ -11,21 +12,13 @@ type RegistryState = {
version: number;
};
const state: RegistryState = (() => {
const globalState = globalThis as typeof globalThis & {
[REGISTRY_STATE]?: RegistryState;
};
if (!globalState[REGISTRY_STATE]) {
globalState[REGISTRY_STATE] = {
registry: createEmptyPluginRegistry(),
httpRouteRegistry: null,
httpRouteRegistryPinned: false,
key: null,
version: 0,
};
}
return globalState[REGISTRY_STATE];
})();
const state = resolveGlobalSingleton<RegistryState>(REGISTRY_STATE, () => ({
registry: createEmptyPluginRegistry(),
httpRouteRegistry: null,
httpRouteRegistryPinned: false,
key: null,
version: 0,
}));
export function setActivePluginRegistry(registry: PluginRegistry, cacheKey?: string) {
state.registry = registry;