fix(coding-agent): bundle mupdf into the compiled binary so PDF reads work

The vendored markit engine kept `mupdf` external, but a single-file
`bun --compile` binary has no node_modules to resolve it from, so the
standalone binary aborted at startup with `Cannot find package 'mupdf'`
— the otherwise-lazy import is resolved eagerly at boot. Bundle mupdf and
embed its WASM blob (scripts/embed-mupdf-wasm.ts, reset after the build);
npm and source installs still load mupdf from node_modules.

Import mupdf lazily inside the PDF converter so the bundled markit chunk's
init stays synchronous: mupdf's top-level await otherwise made the chunk
init async and bun's compiled bundler failed to await it through the
barrel, exposing the converters before their module-level const tables
initialized (undefined EXTENSIONS). Also keeps the ~10MB wasm off non-PDF
document conversions.
This commit is contained in:
can1357
2026-06-18 20:44:58 +02:00
parent 2023a6f674
commit 88aa88f605
9 changed files with 128 additions and 13 deletions
@@ -44,6 +44,7 @@ async function main(): Promise<void> {
await runCommand(["bun", "--cwd=../stats", "scripts/generate-client-bundle.ts", "--generate"]);
await runCommand(["bun", "scripts/generate-docs-index.ts", "--generate"]);
await runCommand(["bun", "--cwd=../natives", "run", "embed:native"]);
await runCommand(["bun", "scripts/embed-mupdf-wasm.ts", "--generate"]);
try {
const buildEnv = shouldAdhocSignDarwinBinary() ? { ...Bun.env, BUN_NO_CODESIGN_MACHO_BINARY: "1" } : Bun.env;
await runCommand(
@@ -61,8 +62,6 @@ async function main(): Promise<void> {
"--define",
`process.env.PI_TINY_TRANSFORMERS_VERSION=${JSON.stringify(transformersVersion)}`,
"--external",
"mupdf",
"--external",
"fastembed",
"--external",
"onnxruntime-node",
@@ -97,6 +96,7 @@ async function main(): Promise<void> {
await runCommand(["codesign", "--force", "--sign", "-", outputPath]);
}
} finally {
await runCommand(["bun", "scripts/embed-mupdf-wasm.ts", "--reset"]);
await runCommand(["bun", "--cwd=../natives", "run", "embed:native", "--reset"]);
}
} finally {