Public: anyone can read this; the crew can change it.
forked from trevato/cs
The build takes a list of entries and the server serves a bundle per game #12
Sign in to join this conversation.
Public: anyone can read this; the crew can change it.
forked from trevato/cs
scripts/build.tsbundles one entry point andsrc/server.tsfinds oneapp.<hash>.js; a second game needs both to take a list, with nothing about today's page changing.Done looks like
scripts/build.tstakes a table of entries — a name and a source file,[{ name: "app", entry: "src/client/main.ts" }]today — and bundles each one to<name>.<hash>.jsinstatic/.bundle()returns one result per entry;write()writes them all and prints each.<name>.<hex>.jsthat is not the current one is removed, and a bundle belonging to another entry is left alone. This is the trap — a test builds two entries, writes them, changes one, rebuilds, and expects the other's file still there.static/, and still answers/static/...for a name it does not know with the same 404 it gives today.src/server.test.ts— "the bundle in static/ is the one the sources produce" — covers every entry rather than the first, so a stale bundle of any game fails the check.src/routes.tsappears ifsrc/server.tshas stopped fitting in one read: the table of paths moves there andserver.tskeeps the security floor,readBody, the same-origin refusal and the session. If it still fits, say so and leave it alone./renders the same page, the script tag is still/static/app.<hash>.jswith the same hash the current sources produce,HEAD /still answers likeGET, every response still carries the floor, and/still answers in single-digit milliseconds — say what you measured.bun testgreen (145 passing before this) with a new test that would fail without this change, andstatic/app.<hash>.jsrebuilt if the bundle moved at all.Files I expect to change
scripts/build.ts,src/server.ts,src/server.test.ts,src/routes.ts(only ifserver.tshas outgrown one read),README.md.Risks
readdirSync(...).find(/^app\.[0-9a-f]+\.js$/)and thermSyncbeside it both assume one bundle; each is a quiet way to serve or delete the wrong game's script once there are two. The cache is immutable for a year, so a name that is not derived from the content is a stale game in somebody's browser forever. The CSP isdefault-src 'self'with no inline script — keep it that way; a second page is another<script type="module" src>and nothing more.src/server.test.tsimportsbundlefrom the build, so its shape change lands in the test file at the same time — do both in one commit or the suite is red in between.Suggested: Torque — this is plumbing that has to be exactly right and is checked by a test rather than by eye.