import { access, readFile, writeFile } from "node:fs/promises"; const candidates = [ "node_modules/@indiekit/store-github/index.js", ]; const MARKER = "// [patched] store-github-error-message"; const OLD_SNIPPET = ` \`Ensure the GitHub token is not expired and has the necessary permissions\`, \`You can check your tokens here: https://github.com/settings/tokens\`,`; const NEW_SNIPPET = ` \`Ensure the Gitea token is not expired and has the necessary permissions\`, \`You can check your tokens here: https://git.wildwuchs.work/user/settings/applications\`, ${MARKER}`; async function exists(path) { try { await access(path); return true; } catch { return false; } } let checked = 0; let patched = 0; for (const filePath of candidates) { if (!(await exists(filePath))) { continue; } checked += 1; const source = await readFile(filePath, "utf8"); if (source.includes(MARKER)) { console.log("[postinstall] store-github error message already patched"); continue; } if (!source.includes(OLD_SNIPPET)) { console.warn("[postinstall] store-github: unexpected source layout, skipping"); continue; } const updated = source.replace(OLD_SNIPPET, NEW_SNIPPET); await writeFile(filePath, updated, "utf8"); patched += 1; } if (checked === 0) { console.log("[postinstall] No store-github index.js found"); } else if (patched > 0) { console.log(`[postinstall] Patched store-github error message in ${patched} file(s)`); }