Refactor PDF conversion utilities and update Linux build script
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
Some checks failed
farmcontrol/farmcontrol-server/pipeline/head There was a failure building this commit
- Removed unnecessary external dependencies from the Linux binary build script to streamline the build process. - Simplified the import mechanism for the `pdf-to-img` and `sharp` modules in the PDF conversion utilities, enhancing module loading efficiency.
This commit is contained in:
parent
bee95563d8
commit
56628cbbe5
@ -26,15 +26,6 @@ const result = await Bun.build({
|
|||||||
outdir: path.join(rootDir, "build/linux-bundle"),
|
outdir: path.join(rootDir, "build/linux-bundle"),
|
||||||
target: "bun",
|
target: "bun",
|
||||||
format: "esm",
|
format: "esm",
|
||||||
external: [
|
|
||||||
"sharp",
|
|
||||||
"canvas",
|
|
||||||
"@napi-rs/canvas",
|
|
||||||
"pdf-to-img",
|
|
||||||
"pdfjs-dist",
|
|
||||||
"@img/*",
|
|
||||||
"@napi-rs/*",
|
|
||||||
],
|
|
||||||
define: {
|
define: {
|
||||||
"process.env.FC_PACKAGE_VERSION": JSON.stringify(packageJson.version),
|
"process.env.FC_PACKAGE_VERSION": JSON.stringify(packageJson.version),
|
||||||
"process.env.FC_BUILD_NUMBER": JSON.stringify(buildNumber),
|
"process.env.FC_BUILD_NUMBER": JSON.stringify(buildNumber),
|
||||||
|
|||||||
@ -1,25 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
* PDF conversion utilities loaded on demand so headless startup
|
* PDF conversion utilities loaded on demand so headless startup
|
||||||
* does not require ESM-only pdf-to-img at module load time.
|
* does not require pdf-to-img at module load time.
|
||||||
*/
|
*/
|
||||||
import { pathToFileURL } from "node:url";
|
|
||||||
import { createRequire } from "node:module";
|
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
|
||||||
|
|
||||||
async function importPackage(name) {
|
|
||||||
const packagePath = require.resolve(name);
|
|
||||||
return import(pathToFileURL(packagePath).href);
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveDefault(module) {
|
function resolveDefault(module) {
|
||||||
return module?.default ?? module;
|
return module?.default ?? module;
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function convertPDFToImage(pdfInput, options = {}) {
|
export async function convertPDFToImage(pdfInput, options = {}) {
|
||||||
const [pdfToImgModule, sharpModule] = await Promise.all([
|
const [pdfToImgModule, sharpModule] = await Promise.all([
|
||||||
importPackage("pdf-to-img"),
|
import("pdf-to-img"),
|
||||||
importPackage("sharp"),
|
import("sharp"),
|
||||||
]);
|
]);
|
||||||
const { pdf } = pdfToImgModule;
|
const { pdf } = pdfToImgModule;
|
||||||
const sharp = resolveDefault(sharpModule);
|
const sharp = resolveDefault(sharpModule);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user