Split The code is public; the app answers only to the crew.
One bundle, built at start-up: stop committing static/app.*.js so a merge cannot serve last week's game #26
Sign in to join this conversation.
Split The code is public; the app answers only to the crew.
Build the client when the server starts and take the built file out of git, because the check is red on
mainright now and production is serving a bundle that predates the last two merges.What is wrong, measured on
3b044c4(=main, = this branch):git ls-files static/lists two bundles,app.942a1ec39a.jsandapp.d616a602f9.js, andbun testfails:the bundle in static/ is the one the sources produce—Expected to contain: "app.9585cc6287.js". Neither committed file is what the sources produce.findScript()(src/server.ts:113) takes the firstapp.*.jsthatreaddirSyncreturns, so which stale bundle a browser gets is filesystem order.app.942a1ec39a.js; #24 branched before that and builtapp.d616a602f9.js. The two merges do not conflict textually, so both files survived and neither matches the merged sources. 343dfe4 had to sweep up three of them the same way. This is structural: every pull touchingsrc/client/will do it again.Done looks like:
static/app.*.jsis no longer tracked by git, and.gitignorecovers it for anyone who still writes one locally.src/server.tsbuilds the client once at start-up through the existingbundle(), keeps the bytes and the content-hash name in memory, and answersGET /static/app.<hash>.jswithcontent-type: text/javascript; charset=utf-8,cache-control: public, max-age=31536000, immutableand the wholeSECURITYfloor.<script src>is that name, so a code change is a new URL and a stale cache is impossible.static/are still served exactly as they are now, path still confined to the directory.bun testpasses on a clean clone, and a test covers both halves: the script path the page renders is the onebundle()produces, and aGETof it answers 200 with the immutable cache header and the security headers.bun run buildstill writes a file for anyone who wants one; the README says the bundle is built at start-up and is not committed.bundle()takes).Files:
src/server.ts,src/server.test.ts,scripts/build.ts,.gitignore,static/(deletions),README.md, maybesrc/pages/game.ts.Risks: start-up now does real work — measure it. Having
src/import fromscripts/is the wrong way round; movingbundle()intosrc/bundle.tsand leavingscripts/build.tsas the thin CLI keeps modules named for one concept. Do not widen the CSP — the script is still same-origin. Do not reach for a bundler dependency;Bun.buildis already doing this.Why it goes first: while the artifact is in git, two client pulls merging in sequence reproduce exactly the breakage that is on
mainnow. Everything else on this map waits for it.Suggested: scout.