From cf95660406a78cdd14edc8ab66aa15fd8572b4f0 Mon Sep 17 00:00:00 2001 From: svemagie <869694+svemagie@users.noreply.github.com> Date: Tue, 31 Mar 2026 20:18:39 +0200 Subject: [PATCH] fix: resvg in deploy, not patches needed --- package.json | 2 +- scripts/patch-resvg-freebsd-runtime.mjs | 25 ------------- scripts/patch-resvg-js-runtime.mjs | 49 ------------------------- 3 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 scripts/patch-resvg-freebsd-runtime.mjs delete mode 100644 scripts/patch-resvg-js-runtime.mjs diff --git a/package.json b/package.json index 0f0718d..d645711 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "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", - "postinstall": "node scripts/patch-resvg-freebsd-runtime.mjs || true && node scripts/patch-resvg-js-runtime.mjs || true" + "postinstall": "" }, "dependencies": { "@11ty/eleventy": "^3.0.0", diff --git a/scripts/patch-resvg-freebsd-runtime.mjs b/scripts/patch-resvg-freebsd-runtime.mjs deleted file mode 100644 index 79302e7..0000000 --- a/scripts/patch-resvg-freebsd-runtime.mjs +++ /dev/null @@ -1,25 +0,0 @@ -// 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}`); diff --git a/scripts/patch-resvg-js-runtime.mjs b/scripts/patch-resvg-js-runtime.mjs deleted file mode 100644 index a91ea73..0000000 --- a/scripts/patch-resvg-js-runtime.mjs +++ /dev/null @@ -1,49 +0,0 @@ -// 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); - } -})();