import { mkdirSync, readdirSync, readFileSync, statSync, writeFileSync } from 'node:fs'; import { join } from 'node:path'; mkdirSync('build', { recursive: true }); writeFileSync('build/.gitkeep', ''); // The client bundle must carry Svelte's browser runtime. When the bundler resolves the // server build instead, onMount is a no-op that gets tree-shaken away, the app stays on // its loading screen and every test still passes. const filesIn = (dir) => readdirSync(dir).flatMap((name) => { const path = join(dir, name); return statSync(path).isDirectory() ? filesIn(path) : path; }); const scripts = filesIn('build/_app/immutable') .filter((path) => path.endsWith('.js')) .map((path) => readFileSync(path, 'utf8')); if (scripts.some((code) => code.includes('lifecycle_function_unavailable'))) { console.error('Build check failed: the client bundle contains Svelte\'s server runtime.'); process.exit(1); } if (!scripts.some((code) => code.includes('serviceWorker'))) { console.error('Build check failed: the service worker registration is missing from the client bundle.'); process.exit(1); }