UNPKG

everything-dev

Version:

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

76 lines (74 loc) • 3.21 kB
const require_domain = require('../domain.cjs'); const require_fs = require('../fs.cjs'); let effect = require("effect"); //#region src/services/scaffold/upgrade-audit/checks/config.ts const parseJson = (source) => effect.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 (!require_domain.KNOWN_APP_SLOT_KEYS.includes(key)) findings.push(new require_domain.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 (!require_domain.KNOWN_PLUGIN_KEYS.includes(key)) findings.push(new require_domain.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.Effect.gen(function* () { if (!(yield* require_fs.fileExists(projectDir, "bos.config.json"))) return [new require_domain.Finding({ check: "config", path: "bos.config.json", severity: "blocker", message: "bos.config.json not found" })]; const config = yield* require_fs.readText(projectDir, "bos.config.json").pipe(effect.Effect.flatMap(parseJson)); const findings = []; for (const key of Object.keys(config)) if (!require_domain.KNOWN_CONFIG_KEYS.includes(key)) findings.push(new require_domain.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 require_domain.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 require_domain.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 require_domain.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 exports.checkConfig = checkConfig; //# sourceMappingURL=config.cjs.map