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.
23 lines
1010 B
JavaScript
23 lines
1010 B
JavaScript
#!/usr/bin/env node
|
|
// 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";
|
|
|
|
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(/SHELL_VERSION = "v(\d+)"/);
|
|
if (!match) {
|
|
console.error(`Couldn't find SHELL_VERSION in ${swPath}`);
|
|
process.exit(1);
|
|
}
|
|
const next = Number(match[1]) + 1;
|
|
const updated = contents.replace(/SHELL_VERSION = "v\d+"/, `SHELL_VERSION = "v${next}"`);
|
|
await writeFile(swPath, updated);
|
|
console.log(`Bumped service worker SHELL_VERSION to v${next}`);
|