/** * Copies the pdf.js worker into /public so the browser can load it as a plain * asset. Running pdf.js on the main thread is not supported, and bundler asset * handling for workers differs between webpack and Turbopack, so an explicit * copy is the most predictable option. * * Wired to `predev` and `prebuild` in package.json. */ import { copyFileSync, existsSync, mkdirSync } from "node:fs"; import { dirname, join } from "node:path"; import { fileURLToPath } from "node:url"; const root = join(dirname(fileURLToPath(import.meta.url)), ".."); const candidates = [ "pdfjs-dist/build/pdf.worker.min.mjs", "pdfjs-dist/build/pdf.worker.mjs", ]; const destination = join(root, "public", "pdf.worker.min.mjs"); mkdirSync(join(root, "public"), { recursive: true }); for (const candidate of candidates) { const source = join(root, "node_modules", candidate); if (existsSync(source)) { copyFileSync(source, destination); console.log(`[freezmo] copied ${candidate} -> public/pdf.worker.min.mjs`); process.exit(0); } } console.error("[freezmo] could not find the pdf.js worker — run `npm install` first"); process.exit(1);