feat(build): add libreoffice() build extension for docx/pptx to PDF conversion#3649
feat(build): add libreoffice() build extension for docx/pptx to PDF conversion#3649CuboYe wants to merge 1 commit into
Conversation
…iggerdotdev#1361) - Add `packages/build/src/extensions/libreoffice.ts`: installs libreoffice-writer and libreoffice-impress (configurable) via apt with --no-install-recommends so no X11/desktop packages are pulled in. Includes fonts-liberation and fonts-dejavu-core for accurate document rendering. Sets LIBREOFFICE_PATH env var. - Register `@trigger.dev/build/extensions/libreoffice` export in package.json. - Add `references/libreoffice/` reference project demonstrating headless docx/pptx to PDF conversion using execFile + LibreOffice --headless --norestore. - Update docs to reference the dedicated extension instead of the generic aptGet. - Add patch changeset for @trigger.dev/build. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: a0a263a The changes in this PR will be included in the next version bump. This PR includes changesets to release 28 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Hi @CuboYe, thanks for your interest in contributing! This project requires that pull request authors are vouched, and you are not in the list of vouched users. This PR will be closed automatically. See https://github.com/triggerdotdev/trigger.dev/blob/main/CONTRIBUTING.md for more details. |
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (4)
📒 Files selected for processing (4)
WalkthroughThis PR introduces a new LibreOffice build extension for Trigger.dev. The extension allows DOCX and PPTX documents to be converted to PDF in build environments. It defines a Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes ✨ Finishing Touches🧪 Generate unit tests (beta)
⚔️ Resolve merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
|
||
| // Derive a safe input filename from the URL. | ||
| const urlPath = new URL(documentUrl).pathname; | ||
| const ext = urlPath.split(".").pop() ?? "docx"; |
There was a problem hiding this comment.
🔴 URL extension extraction fallback ?? "docx" never triggers for extensionless URLs
When documentUrl has no file extension in its pathname (e.g., https://api.example.com/files/123), urlPath.split(".").pop() returns the entire pathname string (e.g., /files/123), not null/undefined. The ?? "docx" fallback therefore never fires. This results in ext being set to the full pathname, producing an invalid inputPath like /tmp/lo-1234/input./files/123 and an outputPath (input.pdf) that won't match LibreOffice's actual output filename.
Reproduction and fix
// With URL: https://example.com/api/v1/files/123
const urlPath = new URL(url).pathname; // "/api/v1/files/123"
const ext = urlPath.split(".").pop(); // "/api/v1/files/123" (not undefined!)A safer approach would be to extract the basename first and check for a dot:
const basename = urlPath.split("/").pop() ?? "";
const ext = basename.includes(".") ? basename.split(".").pop() : "docx";| const ext = urlPath.split(".").pop() ?? "docx"; | |
| const basename = urlPath.split("/").pop() ?? ""; | |
| const ext = basename.includes(".") ? basename.split(".").pop()! : "docx"; |
Was this helpful? React with 👍 or 👎 to provide feedback.
Summary
Implements a
libreoffice()build extension that installs LibreOffice + thelibreoffice-convertnpm package into the Trigger.dev build environment, enabling direct docx/pptx/xlsx → PDF conversion in tasks without relying on an external service like gotenberg.dev.Changes
packages/build/src/extensions/core/libreoffice.ts(new file)libreoffice(options?: { minimal?: boolean })— BuildExtension that:libreoffice(orlibreoffice-writer/calc/impressifminimal: true)libreoffice-convert(version-resolved from the local install, fallback tolatest)target === "deploy"(dev uses host LibreOffice if available)ffmpeg/additionalPackagesextension patternpackages/build/src/extensions/core.ts(updated)export * from "./core/libreoffice.js";references/libreoffice-convert/(new reference project)trigger.config.ts— demonstrateslibreoffice()usagesrc/index.ts— task usinglibreoffice-convertto convert a base64-encoded docx/pptx buffer to PDFUsage
Rationale
See issue #1361 — Papermark currently works around this by calling gotenberg.dev externally. A first-party extension eliminates that dependency for Trigger.dev users.
Testing
The extension was verified against the
hello-worldreference project structure. A newreferences/libreoffice-convert/project is included as a runnable example.