Files
indiekit-blog/scripts/patch-resvg-freebsd-runtime.mjs
svemagie 938e6fecb7
Some checks failed
Build & Deploy / build-and-deploy (push) Failing after 20s
fix: build native resvg, cache it
2026-03-31 20:10:26 +02:00

26 lines
1.0 KiB
JavaScript

// patch-resvg-freebsd-runtime.mjs
// Patch script to restore FreeBSD resvg-js native binary from cache
// Usage: node scripts/patch-resvg-freebsd-runtime.mjs
import { existsSync, copyFileSync } from 'fs';
import { join } from 'path';
const MARKER = '[patch] resvg-js freebsd binary restore';
const RESVG_VERSION = require('../node_modules/@resvg/resvg-js/package.json').version;
const CACHE_DIR = `/usr/local/git/.cache/resvg-freebsd/`;
const CACHE_FILE = join(CACHE_DIR, `resvg-freebsd-x64-${RESVG_VERSION}.node`);
const DEST_DIR = join(process.cwd(), 'node_modules', '@resvg', 'resvg-js', 'linux-x64'); // Use linux-x64 as fallback if no freebsd dir
const DEST_FILE = join(DEST_DIR, 'resvg-js.node');
if (!existsSync(CACHE_FILE)) {
console.warn(`${MARKER}: Cached FreeBSD resvg-js binary not found at ${CACHE_FILE}`);
process.exit(0);
}
if (!existsSync(DEST_DIR)) {
require('fs').mkdirSync(DEST_DIR, { recursive: true });
}
copyFileSync(CACHE_FILE, DEST_FILE);
console.log(`${MARKER}: Restored resvg-js FreeBSD binary to ${DEST_FILE}`);