fix(vite): guard cleanStaleChunks — vp test deleted every built chunk
The cleanStaleChunks plugin lives in the shared vite config, so its closeBundle hook also fired under `vp test` — where generateBundle never runs, produced stayed empty, and the sweep deleted every hashed chunk in web/static (28 files → 3). The entries still referenced their old imports, so every page 404'd and Alpine never started: the whole reader and media system appeared dead after merely running the test suite. Guard: skip the sweep when produced.size === 0 — not a build run, no build output to clean. Verified: build → 28 files, test → 28 files; back-to-back builds stay byte-identical.
This commit is contained in:
1 parent
e5315f1b94
commit
6791d611f0
1 file changed
+8
@@ -19,6 +19,13 @@ const pdfjsAssets = () => ({
|
||||
// so hashed chunks from previous builds would otherwise accumulate
|
||||
// forever and leak into Docker images via the build context. Remove
|
||||
// any *-<hash>.js/.css/.mjs(.map) that this build did not produce.
|
||||
//
|
||||
// The produced.size === 0 guard is load-bearing: this config also drives
|
||||
// `vp test`, and vitest runs closeBundle with generateBundle never having
|
||||
// fired — an empty produced set means "not a build run", and sweeping
|
||||
// then deleted every live chunk (the 2026-10-21 incident where
|
||||
// `npm run test` gutted web/static down to the three entry files and
|
||||
// every page 404'd its imports).
|
||||
const cleanStaleChunks = () => {
|
||||
const produced = new Set<string>();
|
||||
return {
|
||||
@@ -27,6 +34,7 @@ const cleanStaleChunks = () => {
|
||||
for (const fileName of Object.keys(bundle)) produced.add(fileName);
|
||||
},
|
||||
closeBundle() {
|
||||
if (produced.size === 0) return;
|
||||
const outDir = "web/static";
|
||||
const chunkRe = /-[A-Za-z0-9_-]{8}\.(js|css|mjs)(\.map)?$/;
|
||||
for (const f of readdirSync(outDir)) {
|
||||
|
||||
Reference in new issue
Block a user