fix: fixed stats dashboard asset serving for bundled CLI distributions

- Fixed npm CLI bundling by invoking `generate-client-bundle.ts --generate` before build and `--reset` after.
- Added `PI_BUNDLED` handling in `packages/stats/src/server.ts` and switched bundled distributions to embedded assets.
- Decoded embedded archives via `decodeEmbeddedClientArchive` and treated legacy placeholder content as missing.
- Handled missing dashboard source/build directories as ENOENT during mtime scans to avoid startup crashes.
- Extended `--smoke-test` to start the stats server and validate dashboard HTML contains expected asset markers.
This commit is contained in:
can1357
2026-06-10 10:41:04 +02:00
parent bbe85b6661
commit 6b76463941
10 changed files with 162 additions and 72 deletions
+28 -19
View File
@@ -51,25 +51,34 @@ async function cleanBundleOutputs(): Promise<void> {
async function main(): Promise<void> {
const start = Bun.nanoseconds();
await cleanBundleOutputs();
await runCommand([
"bun",
"build",
"--target=bun",
"--outdir",
"dist",
"--minify-whitespace",
"--minify-syntax",
"--keep-names",
"--external",
"mupdf",
"--external",
"@oh-my-pi/pi-natives",
"--external",
"@huggingface/transformers",
"--define",
'process.env.PI_BUNDLED="true"',
"./src/cli.ts",
]);
// The npm bundle ships no stats dashboard sources or prebuilt dist/client,
// so embed the dashboard archive the same way compiled binaries do
// (scripts/build-binary.ts). Reset afterwards to keep the checked-in
// placeholder empty.
await runCommand(["bun", "--cwd=../stats", "scripts/generate-client-bundle.ts", "--generate"]);
try {
await runCommand([
"bun",
"build",
"--target=bun",
"--outdir",
"dist",
"--minify-whitespace",
"--minify-syntax",
"--keep-names",
"--external",
"mupdf",
"--external",
"@oh-my-pi/pi-natives",
"--external",
"@huggingface/transformers",
"--define",
'process.env.PI_BUNDLED="true"',
"./src/cli.ts",
]);
} finally {
await runCommand(["bun", "--cwd=../stats", "scripts/generate-client-bundle.ts", "--reset"]);
}
await ensureShebang();
const stat = await fs.stat(cliPath);
const elapsedMs = (Bun.nanoseconds() - start) / 1_000_000;