Files
indiekit-server/scripts/patch-webmention-sender-hentry-syntax.mjs
svemagie c6b0e7025a fix: patch webmention-sender syntax error (h-entry double quote)
Adds patch-webmention-sender-hentry-syntax.mjs to fix a typo in
@rmdes/indiekit-endpoint-webmention-sender@1.0.8 that prevents the
module from loading:

  _html.includes("h-entry"")  →  _html.includes("h-entry")

The extra closing quote causes a SyntaxError at startup, which means
the webmention sender never runs and the background sync never starts.
Patch runs before the other webmention-sender patches in both
postinstall and serve so the file is valid JS before further transforms.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 22:33:37 +01:00

66 lines
1.8 KiB
JavaScript

/**
* Patch @rmdes/indiekit-endpoint-webmention-sender to fix a syntax error on
* line 289 where "h-entry"" (double closing quote) causes the module to fail
* to load entirely, preventing the webmention sender from starting.
*
* Root cause: typo in the upstream package — an extra `"` after the string
* literal `"h-entry"` makes the JS parser see an unterminated expression:
*
* _html.includes("h-entry"") ← broken
* _html.includes("h-entry") ← fixed
*/
import { access, readFile, writeFile } from "node:fs/promises";
const candidates = [
"node_modules/@rmdes/indiekit-endpoint-webmention-sender/lib/controllers/webmention-sender.js",
];
const marker = "[patched:hentry-syntax]";
const oldSnippet = `_html.includes("h-entry"")`;
const newSnippet = `_html.includes("h-entry") /* ${marker} */`;
async function exists(filePath) {
try {
await access(filePath);
return true;
} catch {
return false;
}
}
let filesChecked = 0;
let filesPatched = 0;
for (const filePath of candidates) {
if (!(await exists(filePath))) {
continue;
}
filesChecked += 1;
const source = await readFile(filePath, "utf8");
if (source.includes(marker)) {
console.log("[patch] webmention-sender-hentry-syntax: already applied");
continue;
}
if (!source.includes(oldSnippet)) {
console.log(
`[patch] webmention-sender-hentry-syntax: target snippet not found in ${filePath} (package updated or already fixed upstream)`
);
continue;
}
const updated = source.replace(oldSnippet, newSnippet);
await writeFile(filePath, updated, "utf8");
filesPatched += 1;
}
if (filesChecked === 0) {
console.log("[patch] webmention-sender-hentry-syntax: package file not found");
} else if (filesPatched > 0) {
console.log(`[patch] webmention-sender-hentry-syntax: patched ${filesPatched}/${filesChecked} file(s)`);
}