opencode/packages/console/app/script/check-server-bundle.ts
David Hill 229476779a chore(console): add the media CDN plumbing, the server-bundle guard and the site docs
Heavy media (about 148 MB) is not committed. src/lib/media.ts holds the one CDN base URL and the media
file types, script/upload-media.ts uploads the files (not run), media-manifest.txt lists them and MEDIA.md is
the plan; .gitignore keeps them out of git. script/check-server-bundle.ts fails the build when three.js reaches
the Worker's server bundle (wired into the build in the next commit). Also
the site's AGENTS.md, DESIGN.md and README.md, and the translator agent.
2026-11-05 15:33:13 -06:00

30 lines
1.4 KiB
TypeScript

// Fails the build when three.js (or any WebGL module) reaches the Worker's server bundle. Its module
// start-up creates an AbortController, which Cloudflare Workers forbid during global start-up, so
// every page would answer 500. Run after `vite build`; browser-only modules must be loaded with
// `import.meta.env.SSR ? undefined : () => import(...)` (see test/server-bundle.test.ts).
import path from "node:path"
import { Glob } from "bun"
const root = path.resolve(import.meta.dir, "..", ".output", "server")
// Declarations only three.js's own code contains (the client manifest still names its asset files,
// so file names are not evidence).
const markers = ["class WebGLRenderer", "class PMREMGenerator", "class BufferGeometry", "class Object3D"]
const files = await Array.fromAsync(new Glob("**/*.{mjs,js}").scan({ cwd: root }))
if (!files.length) {
console.error(`check-server-bundle: no server output in ${root}; run vite build first`)
process.exit(1)
}
const found = (
await Promise.all(
files.map(async (file) => {
const text = await Bun.file(path.join(root, file)).text()
return markers.filter((marker) => text.includes(marker)).map((marker) => `${file}: ${marker}`)
}),
)
).flat()
if (found.length) {
console.error("check-server-bundle: three.js/WebGL code is in the server bundle:\n " + found.join("\n "))
process.exit(1)
}
console.log(`check-server-bundle: ${files.length} server files, no three.js/WebGL code`)