Fix patch-actor-aliases-successor: use candidates pattern instead of require.resolve()
Deploy Indiekit Server / deploy (push) Successful in 1m44s
Deploy Indiekit Server / deploy (push) Successful in 1m44s
require.resolve() failed with ERR_PACKAGE_PATH_NOT_EXPORTED because the package exports field doesn't expose ./lib/federation-setup.js as a public path. Rewritten to use filesystem candidates array like all other patches.
This commit is contained in:
@@ -4,24 +4,20 @@
|
|||||||
* - Add movedTo → personOptions.successor (Fedify uses 'successor')
|
* - Add movedTo → personOptions.successor (Fedify uses 'successor')
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { readFileSync, writeFileSync } from "node:fs";
|
import { access, readFile, writeFile } from "node:fs/promises";
|
||||||
import { createRequire } from "node:module";
|
|
||||||
|
|
||||||
const require = createRequire(import.meta.url);
|
const candidates = [
|
||||||
const pkg = require.resolve("@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js");
|
"node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||||
let src = readFileSync(pkg, "utf-8");
|
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||||
|
];
|
||||||
|
|
||||||
const MARKER = "// patch-actor-aliases-successor: applied";
|
const MARKER = "// patch-actor-aliases-successor: applied";
|
||||||
if (src.includes(MARKER)) {
|
|
||||||
console.log("[patch-actor-aliases-successor] Already applied");
|
|
||||||
process.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fix 1: alsoKnownAs → aliases
|
const OLD = ` if (profile.alsoKnownAs?.length > 0) {
|
||||||
const OLD_ALIASES = ` if (profile.alsoKnownAs?.length > 0) {
|
|
||||||
personOptions.alsoKnownAs = profile.alsoKnownAs.map((u) => new URL(u));
|
personOptions.alsoKnownAs = profile.alsoKnownAs.map((u) => new URL(u));
|
||||||
}`;
|
}`;
|
||||||
const NEW_ALIASES = ` if (profile.alsoKnownAs?.length > 0) {
|
|
||||||
|
const NEW = ` if (profile.alsoKnownAs?.length > 0) {
|
||||||
personOptions.aliases = profile.alsoKnownAs.map((u) => new URL(u));
|
personOptions.aliases = profile.alsoKnownAs.map((u) => new URL(u));
|
||||||
}
|
}
|
||||||
if (profile.movedTo) {
|
if (profile.movedTo) {
|
||||||
@@ -29,11 +25,29 @@ const NEW_ALIASES = ` if (profile.alsoKnownAs?.length > 0) {
|
|||||||
}
|
}
|
||||||
${MARKER}`;
|
${MARKER}`;
|
||||||
|
|
||||||
if (!src.includes(OLD_ALIASES)) {
|
async function exists(p) {
|
||||||
console.error("[patch-actor-aliases-successor] Could not find target block — check federation-setup.js version");
|
try { await access(p); return true; } catch { return false; }
|
||||||
process.exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
src = src.replace(OLD_ALIASES, NEW_ALIASES);
|
let patched = false;
|
||||||
writeFileSync(pkg, src, "utf-8");
|
for (const filePath of candidates) {
|
||||||
console.log("[patch-actor-aliases-successor] Applied: alsoKnownAs→aliases, added movedTo→successor");
|
if (!(await exists(filePath))) continue;
|
||||||
|
const src = await readFile(filePath, "utf8");
|
||||||
|
if (src.includes(MARKER)) {
|
||||||
|
console.log(`[postinstall] patch-actor-aliases-successor: already applied in ${filePath}`);
|
||||||
|
patched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!src.includes(OLD)) {
|
||||||
|
console.log(`[postinstall] patch-actor-aliases-successor: target not found in ${filePath}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
await writeFile(filePath, src.replace(OLD, NEW), "utf8");
|
||||||
|
console.log(`[postinstall] patch-actor-aliases-successor: applied to ${filePath}`);
|
||||||
|
patched = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!patched) {
|
||||||
|
console.log("[postinstall] patch-actor-aliases-successor: no target file found");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user