Files
zotero-notes-export-org/scripts/patch-scaffold.mjs
Ignacio Ballesteros e356f50927 fix: patch scaffold URL parser to support self-hosted Gitea (.eu TLD)
zotero-plugin-scaffold hardcodes a .com-only regex in parseRepoUrl,
causing build failures with non-.com repository URLs. Add:
- scripts/patch-scaffold.mjs: postinstall script that fixes the regex
- zotero-plugin.config.ts: explicit xpiDownloadLink and updateURL
  so scaffold generates correct update.json without relying on the parser
2026-02-17 22:42:48 +01:00

46 lines
1.6 KiB
JavaScript

/**
* Patches zotero-plugin-scaffold's parseRepoUrl to accept non-.com domains.
*
* The upstream regex hardcodes `.com` in the URL pattern, which breaks builds
* when the repository is hosted on a self-hosted Gitea instance (any other TLD).
* This script runs automatically via the `postinstall` npm hook after every
* `npm install` / `npm ci`.
*/
import { readFileSync, writeFileSync } from "fs";
import { resolve, dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const target = resolve(
__dirname,
"../node_modules/zotero-plugin-scaffold/dist/shared/zotero-plugin-scaffold.Lk5EW_9z.mjs"
);
let content;
try {
content = readFileSync(target, "utf8");
} catch {
console.warn("[patch-scaffold] Target file not found, skipping patch.");
process.exit(0);
}
// Original: matches only .com hosts
// /:\/\/.+com\/([^/]+)\/([^.]+)\.git$/
// Replacement: matches any host and makes .git suffix optional
// /:\/\/.+?\/([^/]+)\/([^/.]+)(?:\.git)?$/
const SEARCH = String.raw`url.match(/:\/\/.+com\/([^/]+)\/([^.]+)\.git$/)`;
const REPLACE = String.raw`url.match(/:\/\/.+?\/([^/]+)\/([^/.]+)(?:\.git)?$/)`;
if (content.includes(SEARCH)) {
writeFileSync(target, content.replace(SEARCH, REPLACE), "utf8");
console.log("[patch-scaffold] Applied: parseRepoUrl now accepts any TLD.");
} else if (content.includes(REPLACE)) {
console.log("[patch-scaffold] Already patched, nothing to do.");
} else {
console.warn(
"[patch-scaffold] Could not find target string — scaffold may have been updated. " +
"Check scripts/patch-scaffold.mjs and update SEARCH/REPLACE strings."
);
}