mirror of
https://github.com/garrytan/gbrain.git
synced 2026-07-27 22:15:33 +00:00
Pre-fix, /admin returned 404 on every globally-installed binary because
serve-http.ts:780 resolved admin/dist via process.cwd(). The admin SPA
files are checked into git but `bun build --compile` does NOT embed
arbitrary directories — only assets imported via `with { type: 'file' }`
ESM imports land in the compiled binary.
Wire:
- scripts/build-admin-embedded.ts walks admin/dist/, emits
src/admin-embedded.ts with one `with { type: 'file' }` import per
file + a manifest map (request path → resolved path + mime).
Auto-invoked by `bun run build:admin`.
- src/admin-embedded.ts is the auto-generated module. Bun resolves
every file: import to a path that works at runtime inside the
compiled binary (same pattern as src/core/chunkers/code.ts WASM
imports).
- serve-http.ts switches to two-tier resolution: cwd-relative
admin/dist for dev (Vite hot-rebuild), embedded manifest otherwise.
Embedded path reads bytes lazily and caches per-asset for the
lifetime of the process.
- scripts/check-admin-embedded.sh CI gate re-runs the generator and
fails on drift (mirrors check-wasm-embedded.sh). PRs that rebuild
admin/dist but forget to regenerate the embedded module fail loud.
- package.json wires build:admin-embedded + check:admin-embedded.
Closes #1090.
36 lines
1.2 KiB
Bash
Executable File
36 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# CI gate: src/admin-embedded.ts must match admin/dist/ contents.
|
|
#
|
|
# This protects against the v0.36.x #1090 bug class re-emerging — a PR
|
|
# that rebuilds admin/dist but forgets to regenerate src/admin-embedded.ts
|
|
# would silently break /admin on every fresh install of the compiled
|
|
# binary. The Vite build outputs hashed filenames, so a stale embedded
|
|
# manifest references nonexistent assets.
|
|
#
|
|
# How: re-run the generator, then `git diff --exit-code` on the output.
|
|
# Exits 0 when in sync, 1 when the generator produces different output
|
|
# than what's committed.
|
|
#
|
|
# Mirrors scripts/check-wasm-embedded.sh's pattern.
|
|
|
|
set -euo pipefail
|
|
|
|
cd "$(dirname "$0")/.."
|
|
|
|
if [ ! -d admin/dist ]; then
|
|
echo "[check:admin-embedded] no admin/dist (run \`cd admin && bun run build\` first); skipping"
|
|
exit 0
|
|
fi
|
|
|
|
bun run scripts/build-admin-embedded.ts > /dev/null
|
|
|
|
if ! git diff --exit-code -- src/admin-embedded.ts; then
|
|
echo ""
|
|
echo "[check:admin-embedded] src/admin-embedded.ts is out of sync with admin/dist/."
|
|
echo " Fix: bun run build:admin && bun run build:admin-embedded"
|
|
echo " Then re-commit the regenerated src/admin-embedded.ts."
|
|
exit 1
|
|
fi
|
|
|
|
echo "[check:admin-embedded] OK"
|