UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

76 lines (74 loc) • 3.06 kB
import { Finding, KNOWN_APP_SLOT_KEYS, KNOWN_CONFIG_KEYS, KNOWN_PLUGIN_KEYS } from "../domain.mjs"; import { fileExists, readText } from "../fs.mjs"; import { Effect } from "effect"; //#region src/services/scaffold/upgrade-audit/checks/config.ts const parseJson = (source) => Effect.try({ try: () => JSON.parse(source), catch: (error) => /* @__PURE__ */ new Error(`bos.config.json is not valid JSON: ${String(error)}`) }); const checkAppSlot = (slotPath, slot) => { if (slot === null || typeof slot !== "object" || Array.isArray(slot)) return []; const findings = []; for (const key of Object.keys(slot)) if (!KNOWN_APP_SLOT_KEYS.includes(key)) findings.push(new Finding({ check: "config", path: slotPath, severity: "warn", message: `unknown app slot key "${key}" — not mappable to the v2 surface` })); return findings; }; const checkPlugins = (plugins) => { if (plugins === null || typeof plugins !== "object" || Array.isArray(plugins)) return []; const findings = []; for (const [name, entry] of Object.entries(plugins)) { if (typeof entry !== "object" || entry === null) continue; for (const key of Object.keys(entry)) if (!KNOWN_PLUGIN_KEYS.includes(key)) findings.push(new Finding({ check: "config", path: `plugins.${name}`, severity: "warn", message: `unknown plugin key "${key}" — not mappable to the v2 surface` })); } return findings; }; const checkConfig = (projectDir) => Effect.gen(function* () { if (!(yield* fileExists(projectDir, "bos.config.json"))) return [new Finding({ check: "config", path: "bos.config.json", severity: "blocker", message: "bos.config.json not found" })]; const config = yield* readText(projectDir, "bos.config.json").pipe(Effect.flatMap(parseJson)); const findings = []; for (const key of Object.keys(config)) if (!KNOWN_CONFIG_KEYS.includes(key)) findings.push(new Finding({ check: "config", path: "bos.config.json", severity: "warn", message: `unknown top-level key "${key}" — not mappable to the v2 surface` })); if (typeof config.extends !== "string" || !config.extends.startsWith("bos://")) findings.push(new Finding({ check: "config", path: "bos.config.json", severity: "blocker", message: "\"extends\" must be a bos:// ref — child apps upgrade through the extends chain" })); if (typeof config.account !== "string" || config.account.length === 0) findings.push(new Finding({ check: "config", path: "bos.config.json", severity: "blocker", message: "\"account\" is required" })); if (typeof config.domain !== "string" || config.domain.length === 0) findings.push(new Finding({ check: "config", path: "bos.config.json", severity: "blocker", message: "\"domain\" is required" })); const app = config.app; if (app !== null && typeof app === "object" && !Array.isArray(app)) for (const [slot, value] of Object.entries(app)) findings.push(...checkAppSlot(`app.${slot}`, value)); findings.push(...checkPlugins(config.plugins)); return findings; }); //#endregion export { checkConfig }; //# sourceMappingURL=config.mjs.map