Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore(flatpak): keep the vendored manifest's pnpm pin in step with the repo
Elian Doran2ed0f7688de4
diff --git a/.claude/skills/packaging-for-flathub/SKILL.md b/.claude/skills/packaging-for-flathub/SKILL.mdindex 5ede91ca36..58466fac8a 100644--- a/.claude/skills/packaging-for-flathub/SKILL.md+++ b/.claude/skills/packaging-for-flathub/SKILL.md@@ -104,6 +104,14 @@ that SHA.points at `flatpak-node/pnpm`; the archive root holds an executable `pnpm`, so no`chmod`/symlink step. Refs older than pnpm 12 are rejected by `checkPnpmSupported` —pnpm 11 had a single wrapper tarball and the per-arch URL would 404.++ A release run re-pins pnpm from the **packaged ref's** `packageManager`, so the+ published manifest is never stale no matter what the vendored copy says. Between+ releases Renovate moves `packageManager` and knows nothing about the manifest, so a+ spec in `update-repo.spec.ts` fails once the two diverge and+ `pnpm chore:sync-flatpak-pnpm` rewrites both URLs and both `sha256`s from the working+ tree. Renovate cannot own this itself: a regex manager moves a version but computes no+ hash, which would trade a stale pin for a mismatch inside Flathub's builder.- **`flathub.json`** carries `disable-external-data-checker: true` (the checker probesbroken URLs *without* `x-checker-data`, so it would poll ~2400 generated npm sources)and `automerge-flathubbot-prs: false` — the linter errors on `true`diff --git a/package.json b/package.jsonindex 5df7878eae..566f7c1a32 100644--- a/package.json+++ b/package.json@@ -33,6 +33,7 @@"electron:start-prod": "pnpm desktop:start-prod","chore:ci-update-nightly-version": "tsx ./scripts/update-nightly-version.ts","chore:release-notes-body": "node --experimental-strip-types ./scripts/release-notes-body.mts",+ "chore:sync-flatpak-pnpm": "node --experimental-strip-types ./scripts/flatpak/update-repo.mts --sync-pnpm","chore:update-build-info": "tsx ./scripts/update-build-info.mts","chore:update-flake-electron": "tsx ./scripts/update-flake-electron.ts","chore:update-version": "tsx ./scripts/update-version.ts",diff --git a/scripts/flatpak/update-repo.mts b/scripts/flatpak/update-repo.mtsindex a0910ddd65..270aa4c18a 100644--- a/scripts/flatpak/update-repo.mts+++ b/scripts/flatpak/update-repo.mts@@ -9,9 +9,12 @@* Usage:** pnpm exec tsx ./scripts/flatpak/update-repo.mts <packaging-repo-dir> [ref]+ * pnpm exec tsx ./scripts/flatpak/update-repo.mts --sync-pnpm** `ref` defaults to HEAD; a tag pins `tag:` and `commit:`, anything else pins- * the bare commit (the beta case).+ * the bare commit (the beta case). `--sync-pnpm` rewrites the vendored+ * manifest's own pnpm sources from the working tree's package.json instead,+ * which is what `pnpm chore:sync-flatpak-pnpm` runs.*/import { execFileSync } from "node:child_process";@@ -19,7 +22,8 @@ import { createHash } from "node:crypto";import { appendFileSync, copyFileSync, readFileSync, statSync, writeFileSync } from "node:fs";import { join, resolve } from "node:path";-const FLATPAK_DIR = join(import.meta.dirname, "../../apps/desktop/flatpak");+const REPO_ROOT = join(import.meta.dirname, "../..");+const FLATPAK_DIR = join(REPO_ROOT, "apps/desktop/flatpak");const MANIFEST_NAME = "org.triliumnotes.Trilium.yml";// The wrapper is a manifest source; flathub.json configures Flathub's bots and// only takes effect on the packaging repo's default branch.@@ -57,6 +61,28 @@ export async function main(argv: string[]) {console.log(`Updated ${repoDir}: ${tag ?? "beta"} @ ${commit}, pnpm ${pnpmVersion}.`);}+/**+ * Moves the vendored manifest's pnpm sources onto the version the working tree+ * pins. A release run derives them from the packaged ref instead, so between+ * releases this is what keeps the manifest in step with `packageManager`.+ */+export async function syncPnpmPins() {+ const manifestPath = join(FLATPAK_DIR, MANIFEST_NAME);+ const manifest = readFileSync(manifestPath, "utf-8");+ const pnpmVersion = parsePnpmVersion(readFileSync(join(REPO_ROOT, "package.json"), "utf-8"));+ if (getPnpmVersion(manifest) === pnpmVersion) {+ console.log(`${manifestPath} already pins pnpm ${pnpmVersion}.`);+ return;+ }++ checkPnpmSupported(pnpmVersion);+ writeFileSync(manifestPath, updatePnpmPins(manifest, pnpmVersion, {+ x64: await sha256OfUrl(pnpmExeUrl("x64", pnpmVersion)),+ arm64: await sha256OfUrl(pnpmExeUrl("arm64", pnpmVersion))+ }));+ console.log(`Pinned pnpm ${pnpmVersion} in ${manifestPath}.`);+}+/** Step outputs for the workflow that opens the pull request; the tag is empty for a beta. */export function formatOutputs(commit: string, tag: string | undefined, pnpmVersion: string): string {return `commit=${commit}\nshort=${commit.slice(0, 8)}\ntag=${tag ?? ""}\npnpm=${pnpmVersion}\n`;@@ -132,7 +158,7 @@ async function sha256OfUrl(url: string): Promise<string> {}function git(...args: string[]): string {- return execFileSync("git", args, { cwd: join(import.meta.dirname, "../..") }).toString().trim();+ return execFileSync("git", args, { cwd: REPO_ROOT }).toString().trim();}function isTag(ref: string): boolean {@@ -146,7 +172,9 @@ function isTag(ref: string): boolean {// Only when run as a script — the pure helpers above are imported by the spec.if (process.argv[1] === import.meta.filename) {- main(process.argv.slice(2)).catch((err) => {+ const argv = process.argv.slice(2);+ const run = argv[0] === "--sync-pnpm" ? syncPnpmPins() : main(argv);+ run.catch((err) => {console.error(err instanceof Error ? err.message : err);process.exit(1);});diff --git a/scripts/flatpak/update-repo.spec.ts b/scripts/flatpak/update-repo.spec.tsindex caeac83173..a08e73effe 100644--- a/scripts/flatpak/update-repo.spec.ts+++ b/scripts/flatpak/update-repo.spec.ts@@ -1,3 +1,5 @@+import { readFileSync } from "node:fs";+import { describe, expect, it } from "vitest";import { checkPnpmSupported, formatOutputs, getPnpmVersion, parsePnpmVersion, updateGitSource, updatePnpmPins } from "./update-repo.mjs";@@ -92,4 +94,12 @@ describe("pnpm pins", () => {expect(() => updatePnpmPins(withoutArm, "12.5.0", { x64: "a".repeat(64), arm64: "b".repeat(64) })).toThrow(/arm64/);});++ // Renovate moves `packageManager` and knows nothing about the manifest, which no+ // release run reads back; `pnpm chore:sync-flatpak-pnpm` is what fixes this red.+ it("keeps the vendored manifest on the pnpm the repository pins", () => {+ const read = (path: string) => readFileSync(new URL(path, import.meta.url), "utf-8");+ expect(getPnpmVersion(read("../../apps/desktop/flatpak/org.triliumnotes.Trilium.yml")))+ .toBe(parsePnpmVersion(read("../../package.json")));+ });});