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
This commit is contained in:
@@ -17,7 +17,8 @@
|
|||||||
"lint": "eslint src",
|
"lint": "eslint src",
|
||||||
"lint:fix": "eslint src --fix",
|
"lint:fix": "eslint src --fix",
|
||||||
"format": "prettier --write \"src/**/*.ts\" \"addon/**/*.js\"",
|
"format": "prettier --write \"src/**/*.ts\" \"addon/**/*.js\"",
|
||||||
"format:check": "prettier --check \"src/**/*.ts\" \"addon/**/*.js\""
|
"format:check": "prettier --check \"src/**/*.ts\" \"addon/**/*.js\"",
|
||||||
|
"postinstall": "node scripts/patch-scaffold.mjs"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
45
scripts/patch-scaffold.mjs
Normal file
45
scripts/patch-scaffold.mjs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
/**
|
||||||
|
* 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."
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,12 +1,18 @@
|
|||||||
import { defineConfig } from "zotero-plugin-scaffold";
|
import { defineConfig } from "zotero-plugin-scaffold";
|
||||||
import pkg from "./package.json";
|
import pkg from "./package.json";
|
||||||
|
|
||||||
|
const GITEA_BASE = "https://gitea.bueso.eu/ignacio.ballesteros/zotero-notes-export-org";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
source: ["src", "addon"],
|
source: ["src", "addon"],
|
||||||
dist: ".scaffold/build",
|
dist: ".scaffold/build",
|
||||||
name: pkg.config.addonName,
|
name: pkg.config.addonName,
|
||||||
id: pkg.config.addonID,
|
id: pkg.config.addonID,
|
||||||
namespace: pkg.config.addonRef,
|
namespace: pkg.config.addonRef,
|
||||||
|
// Explicit URLs are required because zotero-plugin-scaffold's URL parser
|
||||||
|
// only handles .com domains and cannot parse our self-hosted Gitea instance.
|
||||||
|
xpiDownloadLink: `${GITEA_BASE}/releases/download/v{{version}}/{{xpiName}}.xpi`,
|
||||||
|
updateURL: `${GITEA_BASE}/releases/download/release/{{updateJson}}`,
|
||||||
build: {
|
build: {
|
||||||
esbuildOptions: [
|
esbuildOptions: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user