Files
aksdb 2c2c7a97c6 🧪 Fail the build when the client bundle carries the server runtime
The postbuild step now recreates the tracked build placeholder and checks
that the client bundle holds Svelte's browser runtime and the service
worker registration, so a wrong export condition cannot ship unnoticed.
2026-12-02 19:05:47 +01:00

27 lines
1.1 KiB
JavaScript

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);
}