2026-05-21 19:26:52 -04:00
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
|
|
|
|
import { fileURLToPath } from 'url';
|
|
|
|
|
import { join, dirname } from 'path';
|
|
|
|
|
|
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
const foldsPath = join(__dirname, '../node_modules/folds/dist/index.js');
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
let content = readFileSync(foldsPath, 'utf8');
|
2026-05-21 20:49:33 -04:00
|
|
|
|
2026-05-21 19:26:52 -04:00
|
|
|
// Defensive guard: if src is not a function, render null instead of crashing
|
|
|
|
|
const original = 'children: src(filled)';
|
|
|
|
|
const patched = 'children: typeof src === "function" ? src(filled) : null';
|
2026-05-21 20:49:33 -04:00
|
|
|
|
2026-05-21 19:26:52 -04:00
|
|
|
if (content.includes(patched)) {
|
|
|
|
|
console.log('folds patch already applied.');
|
|
|
|
|
} else if (content.includes(original)) {
|
|
|
|
|
content = content.replace(original, patched);
|
|
|
|
|
writeFileSync(foldsPath, content, 'utf8');
|
|
|
|
|
console.log('Applied defensive Icon src guard to folds.');
|
|
|
|
|
} else {
|
2026-06-28 10:55:19 -04:00
|
|
|
// Genuine "patch could not be applied" case: the target string is gone
|
|
|
|
|
// (folds renamed/restructured it) AND it isn't already patched. Fail hard
|
|
|
|
|
// so the postinstall hook / CI breaks loudly instead of silently shipping
|
|
|
|
|
// an unpatched folds (which crashes at render with "src is not a function").
|
|
|
|
|
console.error(
|
|
|
|
|
'ERROR: folds Icon patch target not found - folds may have updated. ' +
|
|
|
|
|
'Update the patch target string in scripts/patch-folds.mjs before building.',
|
|
|
|
|
);
|
|
|
|
|
process.exit(1);
|
2026-05-21 19:26:52 -04:00
|
|
|
}
|
|
|
|
|
} catch (e) {
|
2026-06-28 10:55:19 -04:00
|
|
|
console.error('ERROR: Could not patch folds:', e.message);
|
|
|
|
|
process.exit(1);
|
2026-05-21 19:26:52 -04:00
|
|
|
}
|