diff --git a/api/static-site.ts b/api/static-site.ts index de38434..d89af2d 100644 --- a/api/static-site.ts +++ b/api/static-site.ts @@ -65,12 +65,24 @@ const readRow = async () => (await db.select().from(fofosAdminSettings).limit(1) export const distPath = (root: string): string => join(root, 'website', 'dist'); -const run = async (argv: string[], timeoutMs = 60_000, env?: Record) => { +const run = async ( + argv: string[], + timeoutMs = 60_000, + options: { env?: Record; cwd?: string } = {}, +) => { + /* + `cwd` matters and its absence was silent. + + `bun run build:site` resolves the script from the package.json in the CURRENT directory. Without a + cwd it ran in the platform's own, which has no such script, and the error — "Script not found" — + reads like the site is missing one rather than like it was asked in the wrong place. + */ const proc = Bun.spawn(argv, { stdout: 'pipe', stderr: 'pipe', stdin: 'ignore', - ...(env ? { env: { ...process.env, ...env } } : {}), + ...(options.cwd ? { cwd: options.cwd } : {}), + ...(options.env ? { env: { ...process.env, ...options.env } } : {}), }); const timer = setTimeout(() => proc.kill(), timeoutMs); try { @@ -137,10 +149,9 @@ export async function buildSite(secrets: { const url = new URL(raw); url.pathname = `/${databases.production.name}`; - const result = await run( - ['bun', 'run', 'build:site'], - 15 * 60 * 1000, - { + const result = await run(['bun', 'run', 'build:site'], 15 * 60 * 1000, { + cwd: websiteDir, + env: { NODE_ENV: 'production', FOFOS_ENV: 'production', POSTGRES_URL: url.toString(), @@ -154,7 +165,7 @@ export async function buildSite(secrets: { PUBLIC_URL: process.env.FOFOS_PUBLIC_URL ?? 'http://127.0.0.1', API_URL: process.env.FOFOS_PUBLIC_URL ?? 'http://127.0.0.1', }, - ); + }); return { ok: result.ok, output: `$ bun run build:site (FOFOS_ENV=production)\n${result.output}` }; }