/** * Where a module's built web site lives on this host. * * ONE application of the `site/dist` convention. It is deliberately not applied * inside the providers: `public_web` is framework-provided, but `private_web` * and `external_web` are implemented by modules (`caddy-internal`, * `generic-cpanel-hosting-provider`), and three copies of one convention is how * the copies drift. * * Core is also the only party that CAN resolve it in the case that matters. * When the `public_web` provider converges a rebuilt host, no consumer is * running to be asked where its bytes are (design D10). So the path has to come * from the module id, and `modules.source_path` is what core already holds. */ import { join } from 'node:path'; import { MODULE_STATE_WEB_ROOT, MODULE_WEB_ROOT } from '@celilo/capabilities'; import { eq } from 'drizzle-orm'; import type { DbClient } from '../db/client'; import { modules } from '../db/schema'; /** * Absolute path to `/site/dist`, or undefined when no such module * is installed. * * Does NOT check that the directory exists. Resolving a path and deciding * whether it is usable are different jobs, and the second one belongs where the * error can name the caller (Rule 10.1). `createPublicWeb`'s `requireWebRoot` * does the existence check and says what to ship. */ export function resolveModuleWebRoot(moduleId: string, db: DbClient): string | undefined { const module = db.select().from(modules).where(eq(modules.id, moduleId)).get(); if (!module) return undefined; return join(module.sourcePath, MODULE_WEB_ROOT); } /** * Absolute path to `/state/site` — the state web overlay * (celilo#1265) — or undefined when no such module is installed. * * Beside `resolveModuleWebRoot` for the same reason that function lives here: * ONE application of the convention, by the one party that can resolve it for * a module that is not running. Does NOT check that the directory exists — a * module with no generated site content has no overlay, and deciding what an * absent directory means belongs to the caller (see `requireWebRoot`). */ export function resolveModuleStateWebRoot(moduleId: string, db: DbClient): string | undefined { const module = db.select().from(modules).where(eq(modules.id, moduleId)).get(); if (!module) return undefined; return join(module.sourcePath, MODULE_STATE_WEB_ROOT); }