fix: build native resvg, cache it
Build & Deploy / build-and-deploy (push) Failing after 20s

This commit is contained in:
svemagie
2026-03-31 20:10:26 +02:00
parent cbd5f1b994
commit 938e6fecb7
3 changed files with 76 additions and 1 deletions
+2 -1
View File
@@ -9,7 +9,8 @@
"dev": "eleventy --serve --watch",
"build:css": "postcss css/tailwind.css -o css/style.css",
"check:upstream-widgets": "node scripts/check-upstream-widget-drift.mjs",
"check:upstream-widgets:strict": "node scripts/check-upstream-widget-drift.mjs --strict"
"check:upstream-widgets:strict": "node scripts/check-upstream-widget-drift.mjs --strict",
"postinstall": "node scripts/patch-resvg-freebsd-runtime.mjs || true && node scripts/patch-resvg-js-runtime.mjs || true"
},
"dependencies": {
"@11ty/eleventy": "^3.0.0",
+25
View File
@@ -0,0 +1,25 @@
// 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}`);
+49
View File
@@ -0,0 +1,49 @@
// patch-resvg-js-runtime.mjs
// Patch @resvg/resvg-js to load native binary dynamically and handle missing FreeBSD binary gracefully
// Usage: node scripts/patch-resvg-js-runtime.mjs
import { promises as fs } from 'fs';
import path from 'path';
const MARKER = '// [patch] dynamic require for resvg-js';
const PATCH_TARGETS = [
'node_modules/@resvg/resvg-js/index.js',
'node_modules/@indiekit/indiekit/node_modules/@resvg/resvg-js/index.js',
];
const OLD_SNIPPET = `const {{ binding }} = require('./js-binding.js');`;
const NEW_SNIPPET = `let {{ binding }};
try {
{{ binding }} = require('./js-binding.js');
} catch (err) {
console.warn('[resvg-js] Native binary not found or failed to load:', err.message); // [patch] dynamic require for resvg-js
}`;
async function patchFile(filePath) {
try {
let code = await fs.readFile(filePath, 'utf8');
if (code.includes(MARKER)) {
console.log(`[patch-resvg-js-runtime] Already patched: ${filePath}`);
return;
}
if (!code.includes(`require('./js-binding.js')`)) {
console.warn(`[patch-resvg-js-runtime] Skipping (no require found): ${filePath}`);
return;
}
code = code.replace(
/const (\w+) = require\('\.\/js-binding\.js'\);/,
(m, binding) => NEW_SNIPPET.replace(/\{\{ binding \}\}/g, binding)
);
await fs.writeFile(filePath, code, 'utf8');
console.log(`[patch-resvg-js-runtime] Patched: ${filePath}`);
} catch (err) {
if (err.code !== 'ENOENT') throw err;
}
}
(async () => {
for (const relPath of PATCH_TARGETS) {
const absPath = path.resolve(process.cwd(), relPath);
await patchFile(absPath);
}
})();