fix(build): copy-pdf-worker must never mask the real build error

closeBundle also runs when the build FAILED mid-render (dist/ absent); the
plugin's copyFileSync then threw ENOENT and vite reported THAT instead of the
actual render error — exactly what hid the real failure in the Windows desktop
CI run. Now: warn-and-skip on any error, mkdir the dest dir when copying.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-07-01 22:53:32 -04:00
parent 0adce52d37
commit 34592d9144
+15 -3
View File
@@ -59,9 +59,21 @@ function copyPdfWorker() {
return {
name: 'copy-pdf-worker',
closeBundle() {
const src = path.resolve('node_modules/pdfjs-dist/build/pdf.worker.min.mjs');
const dest = path.resolve('dist/pdf.worker.min.js');
if (fs.existsSync(src)) fs.copyFileSync(src, dest);
// Never throw from here: closeBundle also runs when the build FAILED
// mid-render (dist/ absent) and an exception here MASKS the real build
// error in vite's report (seen on the Windows CI runner). Warn and skip.
try {
const src = path.resolve('node_modules/pdfjs-dist/build/pdf.worker.min.mjs');
const dest = path.resolve('dist/pdf.worker.min.js');
if (!fs.existsSync(src)) {
console.warn('[copy-pdf-worker] source worker missing, skipped:', src);
return;
}
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.copyFileSync(src, dest);
} catch (err) {
console.warn('[copy-pdf-worker] skipped:', err?.message ?? err);
}
},
};
}