6b76463941
- 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.
27 lines
1.1 KiB
TypeScript
27 lines
1.1 KiB
TypeScript
/**
|
|
* Embedded stats dashboard archive handling.
|
|
*
|
|
* `embedded-client.generated.txt` holds the base64 of a gzipped tar of the
|
|
* built dashboard (`dist/client`). It is populated by
|
|
* `scripts/generate-client-bundle.ts --generate` for compiled binaries and the
|
|
* prepacked npm bundle, and reset to an empty file afterwards so the dev tree
|
|
* keeps building the dashboard from source.
|
|
*/
|
|
|
|
/**
|
|
* Decode the generated archive text.
|
|
*
|
|
* Returns `null` when the content is blank or not a raw gzip archive encoded as
|
|
* base64 — notably the legacy placeholder that contained a TypeScript
|
|
* `export const … = "";` stub, which must be treated as "no archive embedded"
|
|
* rather than decoded into garbage bytes.
|
|
*/
|
|
export function decodeEmbeddedClientArchive(txt: string): Buffer | null {
|
|
const normalized = txt.replaceAll(/\s+/g, "");
|
|
if (!normalized) return null;
|
|
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(normalized)) return null;
|
|
const archiveBytes = Buffer.from(normalized, "base64");
|
|
if (archiveBytes[0] !== 0x1f || archiveBytes[1] !== 0x8b) return null;
|
|
return archiveBytes;
|
|
}
|