fix: resvg in deploy, not patches needed
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
"build:css": "postcss css/tailwind.css -o css/style.css",
|
"build:css": "postcss css/tailwind.css -o css/style.css",
|
||||||
"check:upstream-widgets": "node scripts/check-upstream-widget-drift.mjs",
|
"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"
|
"postinstall": ""
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@11ty/eleventy": "^3.0.0",
|
"@11ty/eleventy": "^3.0.0",
|
||||||
|
|||||||
@@ -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}`);
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
Reference in New Issue
Block a user