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')
|
||||
*/
|
||||
|
||||
import { readFileSync, writeFileSync } from "node:fs";
|
||||
import { createRequire } from "node:module";
|
||||
import { access, readFile, writeFile } from "node:fs/promises";
|
||||
|
||||
const require = createRequire(import.meta.url);
|
||||
const pkg = require.resolve("@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js");
|
||||
let src = readFileSync(pkg, "utf-8");
|
||||
const candidates = [
|
||||
"node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||
"node_modules/@indiekit/indiekit/node_modules/@rmdes/indiekit-endpoint-activitypub/lib/federation-setup.js",
|
||||
];
|
||||
|
||||
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_ALIASES = ` if (profile.alsoKnownAs?.length > 0) {
|
||||
const OLD = ` if (profile.alsoKnownAs?.length > 0) {
|
||||
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));
|
||||
}
|
||||
if (profile.movedTo) {
|
||||
@@ -29,11 +25,29 @@ const NEW_ALIASES = ` if (profile.alsoKnownAs?.length > 0) {
|
||||
}
|
||||
${MARKER}`;
|
||||
|
||||
if (!src.includes(OLD_ALIASES)) {
|
||||
console.error("[patch-actor-aliases-successor] Could not find target block — check federation-setup.js version");
|
||||
process.exit(1);
|
||||
async function exists(p) {
|
||||
try { await access(p); return true; } catch { return false; }
|
||||
}
|
||||
|
||||
src = src.replace(OLD_ALIASES, NEW_ALIASES);
|
||||
writeFileSync(pkg, src, "utf-8");
|
||||
console.log("[patch-actor-aliases-successor] Applied: alsoKnownAs→aliases, added movedTo→successor");
|
||||
let patched = false;
|
||||
for (const filePath of candidates) {
|
||||
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