/** * Patch: add Content-Type: application/json to store-github #client requests. * * The #client method only sets `accept` and `authorization` headers. * GitHub's API infers JSON from the body without Content-Type; Gitea's API * requires an explicit Content-Type: application/json header on POST/PUT * requests — without it the body is not parsed and Gitea returns 422 * Unprocessable Entity. */ import { readFile, writeFile, access } from "node:fs/promises"; const TARGET = "node_modules/@indiekit/store-github/index.js"; const MARKER = "// [patch] store-github-content-type"; const OLD = ` accept: "application/vnd.github+json", authorization: \`token \${token}\`,`; const NEW = ` accept: "application/vnd.github+json", authorization: \`token \${token}\`, "content-type": "application/json", ${MARKER}`; async function exists(p) { try { await access(p); return true; } catch { return false; } } if (!(await exists(TARGET))) { console.log(`[postinstall] store-github-content-type: target not found, skipping`); process.exit(0); } const source = await readFile(TARGET, "utf8"); if (source.includes(MARKER)) { console.log("[postinstall] store-github-content-type: already patched"); process.exit(0); } if (!source.includes(OLD)) { console.warn("[postinstall] store-github-content-type: snippet not found — skipping"); process.exit(0); } await writeFile(TARGET, source.replace(OLD, NEW), "utf8"); console.log(`[postinstall] store-github-content-type: patched ${TARGET}`);