Skip to content

Build your personal knowledge base with Trilium Notes

fix(desktop): ship the PDFium wasm by sharing the server's asset copies

Elian Doran845d6137841f
diff --git a/apps/desktop/scripts/build.ts b/apps/desktop/scripts/build.ts
index e229a8f4d2..0343565b03 100644
--- a/apps/desktop/scripts/build.ts
+++ b/apps/desktop/scripts/build.ts
@@ -27,15 +27,7 @@ async function main() {
// Copy assets.
build.copy("src/assets", "assets/");
- build.copy("/apps/server/src/assets", "assets/");
- build.copy("/packages/trilium-core/src/assets/schema.sql", "assets/schema.sql");
- // The LLM skill sheets moved to core with the rest of the stack, but the
- // Node hosts still read them from RESOURCE_DIR. See server core_assets.ts.
- build.copy("/packages/trilium-core/src/assets/llm/skills", "assets/llm/skills/");
- // The Codex ACP adapter runs as a script of its own in a worker thread. See the server's
- // codex_binary.ts.
- build.copy("/node_modules/@agentclientprotocol/codex-acp/dist/index.js", "assets/codex-acp.mjs");
- build.copy("/packages/share-theme/src/templates", "share-theme/templates/");
+ build.copyServerAssets();
// Copy node modules dependencies
build.copyNodeModules([ "better-sqlite3" ]);
diff --git a/apps/server/scripts/build.ts b/apps/server/scripts/build.ts
index 107b57452e..24e24b27e6 100644
--- a/apps/server/scripts/build.ts
+++ b/apps/server/scripts/build.ts
@@ -12,25 +12,9 @@ async function main() {
await build.buildTesseractWorker("src/services/ocr/tesseract_worker.ts");
// Copy assets
- build.copy("src/assets", "assets/");
+ build.copyServerAssets();
// The healthcheck docker runs; the Dockerfiles point at it inside the image.
build.copy("docker_healthcheck.sh", "docker_healthcheck.sh");
- // schema.sql lives in trilium-core but is loaded at server startup. The
- // bundled main.mjs can't `require.resolve("@triliumnext/core/...")` in
- // Docker (no workspace symlinks in the image), so we copy the file
- // alongside the server's own assets and read it via RESOURCE_DIR at
- // runtime. See main.ts.
- build.copy("/packages/trilium-core/src/assets/schema.sql", "assets/schema.sql");
- // Same story for the LLM skill sheets: core owns them, the server reads them
- // from RESOURCE_DIR at runtime. See core_assets.ts.
- build.copy("/packages/trilium-core/src/assets/llm/skills", "assets/llm/skills/");
- // PDFium rasterizes scanned PDF pages for OCR. Its own loader resolves the wasm relative to
- // `import.meta.url`, which in a split bundle is a hash-named file under chunks/, so the bytes
- // are handed to it explicitly from here instead. See pdf_renderer.ts.
- build.copy("/node_modules/@hyzyla/pdfium/dist/pdfium.wasm", "assets/pdfium.wasm");
- // The Codex ACP adapter runs as a script of its own in a worker thread. See codex_binary.ts.
- build.copy("/node_modules/@agentclientprotocol/codex-acp/dist/index.js", "assets/codex-acp.mjs");
- build.copy("/packages/share-theme/src/templates", "share-theme/templates/");
// Copy node modules dependencies
build.copyNodeModules([ "better-sqlite3" ]);
diff --git a/scripts/build-utils.ts b/scripts/build-utils.ts
index dfe08178c0..77ac151621 100644
--- a/scripts/build-utils.ts
+++ b/scripts/build-utils.ts
@@ -169,6 +169,27 @@ export default class BuildHelper {
}
}
+ /**
+ * Copies the assets the server code reads from `RESOURCE_DIR` at runtime. Both the server and
+ * the desktop app run that code, so both builds call this.
+ */
+ copyServerAssets() {
+ this.copy("/apps/server/src/assets", "assets/");
+ // Core owns these, but the bundle cannot resolve `@triliumnext/core` paths where no
+ // workspace exists (Docker, a packaged app), so they are read from RESOURCE_DIR instead.
+ // See core_assets.ts.
+ this.copy("/packages/trilium-core/src/assets/schema.sql", "assets/schema.sql");
+ this.copy("/packages/trilium-core/src/assets/llm/skills", "assets/llm/skills/");
+ // PDFium's own loader resolves the wasm against `import.meta.url`, which in the split
+ // bundle names a file under chunks/. See pdf_renderer.ts.
+ this.copy("/node_modules/@hyzyla/pdfium/dist/pdfium.wasm", "assets/pdfium.wasm");
+ // The Codex ACP adapter runs as a script of its own in a worker thread. See
+ // codex_binary.ts.
+ this.copy(
+ "/node_modules/@agentclientprotocol/codex-acp/dist/index.js", "assets/codex-acp.mjs");
+ this.copy("/packages/share-theme/src/templates", "share-theme/templates/");
+ }
+
buildFrontend() {
this.triggerBuildAndCopyTo("apps/client", "public/");