Fix stale/mismatched engine cache causing "ASM_CONSTS[...] is not a function" live
The service worker's engine cache key relied on a manual CACHE_VERSION bump that was forgotten across the last two @valknar/vpinball-wasm version bumps, so returning visitors kept getting served old cached vpinball.js/.wasm/.data via cache-first with no revalidation — the origin server itself was serving a correct, matching 0.3.4 set the whole time (verified via headers/sizes against the local build). Split CACHE_VERSION into a manually-bumped SHELL_VERSION and an ENGINE_VERSION that copy-engine-assets.mjs now writes automatically from the installed engine's package.json on every build, so the engine cache always busts in lockstep with the dependency version — no step to forget.
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#!/usr/bin/env node
|
||||
// Bumps public/sw.js's CACHE_VERSION so a deploy invalidates old caches —
|
||||
// run this before cutting a release that changes the app shell or updates
|
||||
// the vendored vpinball-wasm engine build.
|
||||
// Bumps public/sw.js's SHELL_VERSION so a deploy invalidates old shell
|
||||
// caches — run this before cutting a release that changes SHELL_ASSETS or
|
||||
// the shell's caching behavior. (The engine cache busts itself automatically
|
||||
// from the installed vpinball-wasm version — see copy-engine-assets.mjs.)
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
@@ -10,12 +11,12 @@ const rootDir = path.dirname(path.dirname(fileURLToPath(import.meta.url)));
|
||||
const swPath = path.join(rootDir, "public", "sw.js");
|
||||
|
||||
const contents = await readFile(swPath, "utf8");
|
||||
const match = contents.match(/CACHE_VERSION = "v(\d+)"/);
|
||||
const match = contents.match(/SHELL_VERSION = "v(\d+)"/);
|
||||
if (!match) {
|
||||
console.error(`Couldn't find CACHE_VERSION in ${swPath}`);
|
||||
console.error(`Couldn't find SHELL_VERSION in ${swPath}`);
|
||||
process.exit(1);
|
||||
}
|
||||
const next = Number(match[1]) + 1;
|
||||
const updated = contents.replace(/CACHE_VERSION = "v\d+"/, `CACHE_VERSION = "v${next}"`);
|
||||
const updated = contents.replace(/SHELL_VERSION = "v\d+"/, `SHELL_VERSION = "v${next}"`);
|
||||
await writeFile(swPath, updated);
|
||||
console.log(`Bumped service worker CACHE_VERSION to v${next}`);
|
||||
console.log(`Bumped service worker SHELL_VERSION to v${next}`);
|
||||
|
||||
Reference in New Issue
Block a user