Files
HealthLog/scripts/generate-sw-version.mjs
T
Marc-André Bombeck 6c7fc7dc84 chore(release): v1.4.45 — analytics 9 s perf fix + audit-marathon closure + v1.4.44 hotfix merged
Audit-marathon close: 14 waves + W10 QA + reconcile. Perf fix (analytics 9 s -> 2-3 s), Zod multi-issue rollout (41 routes), Withings parked-state automation, mobile-UI WCAG 2.5.5 close, QoL i18n + offline banner + account delete, security PII drop + replay-injection scan. Migration 0075 required. Tests 4815 -> 5076.
2026-05-21 23:13:21 +02:00

38 lines
1.5 KiB
JavaScript

#!/usr/bin/env node
/**
* v1.4.43 QoL (L3) — write the active package.json version into
* `public/sw-version.js`. The Service Worker (`public/sw.js`) loads
* this file via `importScripts('/sw-version.js')` and reads
* `self.__APP_VERSION__` to key its `CACHE_VERSION`.
*
* Pre-fix the SW carried a hand-bumped literal that drifted four
* releases stale; the `activate`-step's old-cache eviction became
* a no-op for every deploy in v1.4.38.4 → v1.4.42. Running this
* script as a `prebuild` step re-anchors the version on every build,
* so the eviction now fires reliably.
*
* Idempotent: writes the file unconditionally. Safe to commit the
* generated file or `.gitignore` it — either way `pnpm build` reruns
* the generator.
*/
import { readFileSync, writeFileSync } from "node:fs";
import { join, dirname } from "node:path";
import { fileURLToPath } from "node:url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const repoRoot = join(__dirname, "..");
const pkgPath = join(repoRoot, "package.json");
const outPath = join(repoRoot, "public", "sw-version.js");
const pkg = JSON.parse(readFileSync(pkgPath, "utf8"));
const version = `v${pkg.version}`;
const banner =
"// AUTO-GENERATED by scripts/generate-sw-version.mjs — do not edit.\n";
const body = `self.__APP_VERSION__ = ${JSON.stringify(version)};\n`;
writeFileSync(outPath, banner + body, "utf8");
// One-line log so the build output shows the version we baked in.
process.stdout.write(`sw-version.js → ${version}\n`);