fix(pwa): honour the adapter flag and precache an offline entry point

Three defects that together meant `npm run test:build` could not pass in any of
its four variants:

- svelte.config.js constructed adapter-netlify inline and never used the
  `adapter` export from adapter.mjs, so NODE_ADAPTER=true still produced a flat
  build/ directory while the build test expects the node adapter's build/client
  layout. adapter.mjs now returns netlify (the deployment target) or node, and
  svelte.config.js consumes it.

- No route is prerendered, so workbox's glob found no HTML document and a
  generateSW build precached nothing navigable: the app had no offline support
  in that mode at all. Adds the root entry and a navigation fallback, matching
  what prompt-sw.ts already did by hand for injectManifest builds.

- The build scripts used by the tests skipped the tailwind step that `build`
  runs, so static/output.css was never generated on a clean checkout and the
  app under test had no stylesheet.

The offline entry point assertion now also accepts the unquoted object key that
prompt-sw.ts's own precache call survives minification as.
This commit is contained in:
Josh Creek
2026-09-13 17:35:29 +01:00
parent de39dc78ea
commit f9b7bbdf0a
5 changed files with 34 additions and 22 deletions
+6 -6
View File
@@ -7,12 +7,12 @@
"dev-generate": "GENERATE_SW=true npx tailwindcss -i ./static/input.css -o ./static/output.css && vite dev",
"dev-generate-suppress-w": "GENERATE_SW=true SUPPRESS_WARNING=true npx tailwindcss -i ./static/input.css -o ./static/output.css && vite dev",
"sprites:build": "node scripts/optimize-sprites.mjs",
"build-generate-sw": "GENERATE_SW=true vite build",
"build-generate-sw-node": "NODE_ADAPTER=true GENERATE_SW=true vite build",
"build": "npx tailwindcss -i ./static/input.css -o ./static/output.css && vite build",
"build-inject-manifest": "vite build",
"build-inject-manifest-node": "NODE_ADAPTER=true vite build",
"build-self-destroying": "SELF_DESTROYING_SW=true vite build",
"build-generate-sw": "npm run tailwind && GENERATE_SW=true vite build",
"build-generate-sw-node": "npm run tailwind && NODE_ADAPTER=true GENERATE_SW=true vite build",
"build": "npm run tailwind && vite build",
"build-inject-manifest": "npm run tailwind && vite build",
"build-inject-manifest-node": "npm run tailwind && NODE_ADAPTER=true vite build",
"build-self-destroying": "npm run tailwind && SELF_DESTROYING_SW=true vite build",
"preview": "vite preview --port=4173",
"preview-node": "PORT=4173 node build",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",