opencode/packages/console/app/script/check-client-bundle.ts
David Hill 0bc3bea56c feat(console): add the new site shell, i18n, text files and SEO plumbing
Dependencies and build for dev's toolchain (released solid-start, nitro 3.0.260903-beta, @typescript/native,
no nitro patch), the textjs package, link preview cards (script/og.ts, with the source frames it crops) and
the server-bundle guard in the build.
Middleware (redirects for /go, /zen, /black, /enterprise, /pricing, /models, /teams, /download, /products,
plus dev's iOS pairing, server-action sanitizing and /auth, /workspace), robots.txt, humans.txt, security.txt,
llms.txt (ours), sitemaps with the V2 docs at /v2/sitemap.xml, Markdown twins, link preview cards, the site
header (our nav including Enterprise), footer, settings, search, voice, i18n in 18 locales with RTL, and the
404 arcade. Docs stay on dev's proxy: docsBase is /v2/docs. consoleMarketingEnabled is kept for dev's test.
Zen is renamed OpenCode Models in our copy. Middleware sends heavy media to the CDN (src/lib/media.ts).
Vite keeps one environments block. The mono font is OpenTUI Mono (Anomaly's, SIL OFL 1.1): the files and
licence are in src/asset/fonts, built by script/opentui-mono.py. The legal library has the Privacy Policy and
the Terms only; the legal drafts are not in this branch.
2026-11-05 17:37:51 -06:00

52 lines
2.6 KiB
TypeScript

// Fails the build when a development tool reaches the browser bundle: Settings (settings-panel.tsx),
// Design mode (design-mode.tsx, design-overlay.tsx) or the device preview (device-preview.tsx,
// device-preview-panel.tsx). They load only on the development server, through loaders a production
// build compiles away: `import.meta.env.DEV ? lazy(() => import("./settings-panel")) : undefined`.
// Run after `vite build`, optionally with the output directory: `bun script/check-client-bundle.ts .output`.
import path from "node:path"
import { Glob } from "bun"
const root = path.resolve(process.argv[2] ?? path.join(import.meta.dir, "..", ".output"), "public")
// Strings only the tools' own code contains, as they survive minification.
const scriptMarkers = [
"opencode-site-design-mode", // design-mode.tsx: whether Design mode is on
"opencode-site-design-copy-v2", // design-mode.tsx: the saved copy choices
"design-export", // design-overlay.tsx
"settings-backdrop", // settings-panel.tsx
'opencode-site-device-preview"', // device-preview-panel.tsx: the saved device
"Toggle Design mode", // search-index.ts: the ⌘K action
"Open Settings", // search-index.ts: the ⌘K action
]
// The tools' styles (settings-panel.css, design-mode.css, device-preview.css).
const styleMarker =
/\[data-component="?(settings-panel|settings-backdrop|design-overlay|design-controls|design-export|history-toast|device-preview)"?\]/
// Chunks named after the tools' modules.
const chunkName =
/(^|\/)(design-mode|design-overlay|settings-panel|device-preview|device-preview-panel|page-settings|settings-transfer)-[\w-]+\.(js|css)$/
const files = await Array.fromAsync(new Glob("**/*.{js,mjs,css}").scan({ cwd: root }))
if (!files.length) {
console.error(`check-client-bundle: no client output in ${root}; run vite build first`)
process.exit(1)
}
const found = (
await Promise.all(
files.map(async (file) => {
if (chunkName.test(file)) return [`${file}: a development tool's chunk`]
const text = await Bun.file(path.join(root, file)).text()
if (file.endsWith(".css")) {
const match = text.match(styleMarker)
return match ? [`${file}: ${match[0]}`] : []
}
return scriptMarkers.filter((marker) => text.includes(marker)).map((marker) => `${file}: ${marker}`)
}),
)
).flat()
if (found.length) {
console.error(
"check-client-bundle: Settings, Design mode or device preview code is in the client bundle:\n " +
found.join("\n "),
)
process.exit(1)
}
console.log(`check-client-bundle: ${files.length} client files, no Settings, Design mode or device preview code`)