Files
indiekit-server/scripts/patch-session-maxage.mjs
Sven a14a68ca8f fix: sync postinstall/serve scripts with actual scripts directory
Commit 774261f removed 6 AP patch scripts (integrated into fork) but left
their references in package.json, causing npm ci to fail with exit 1.
Also commits 3 server-side-only scripts that were missing from the repo.

- Remove: patch-ap-startup-gate-bypass, patch-ap-federation-infra,
  patch-ap-syndication, patch-ap-mastodon-statuses, patch-ap-mastodon-misc,
  patch-ap-oauth-token-expiry (from both postinstall and serve)
- Add to postinstall: patch-microsub-compose-draft-guard,
  patch-microsub-no-bookmark-autofollow, patch-microsub-reader-ap-dispatch,
  patch-ap-enrich-actor-data, patch-ap-stubs-remove-duplicate-routes,
  patch-session-maxage
- Commit 3 previously server-only scripts to repo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 17:13:42 +02:00

42 lines
1.2 KiB
JavaScript

import { access, readFile, writeFile } from "node:fs/promises";
const candidates = [
"node_modules/@indiekit/indiekit/config/express.js",
];
const marker = "SESSION_MAX_AGE_DAYS";
const from = "maxAge: 7 * 24 * 60 * 60 * 1000, // 7 days,";
const to = "maxAge: Number.parseInt(process.env.SESSION_MAX_AGE_DAYS || '30', 10) * 24 * 60 * 60 * 1000, // SESSION_MAX_AGE_DAYS days";
async function exists(filePath) {
try { await access(filePath); 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] Session maxAge patch already applied");
continue;
}
if (!source.includes(from)) {
console.warn("[postinstall] Skipping session maxAge patch: upstream format changed");
continue;
}
await writeFile(filePath, source.replace(from, to), "utf8");
patched += 1;
}
if (checked === 0) {
console.log("[postinstall] No indiekit express config found");
} else if (patched > 0) {
console.log("[postinstall] Patched session maxAge to use SESSION_MAX_AGE_DAYS env var (default 30)");
}