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
refactor(flatpak): template the manifest's pins instead of rewriting values
Elian Dorana2cf0dbee442
diff --git a/.claude/skills/packaging-for-flathub/SKILL.md b/.claude/skills/packaging-for-flathub/SKILL.mdindex 115471b972..f635792ecf 100644--- a/.claude/skills/packaging-for-flathub/SKILL.md+++ b/.claude/skills/packaging-for-flathub/SKILL.md@@ -110,14 +110,22 @@ that SHA.`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.- **The vendored pins are allowed to trail the repository** — the git ref and the pnpm- version both. `update-repo.mts` re-pins pnpm from the **packaged ref's**- `packageManager` and fetches the two `sha256`s while it writes the packaging repo, so- the published manifest is right whatever the vendored copy says. Renovate moves- `packageManager` without touching the manifest; do not add a check that fails on the- gap. One was tried and reverted: on a `pull_request` run the comparison sees main's- `package.json` against the branch's manifest, so a bump on main reddens every open- pull request, none of which can fix it.+ **The vendored manifest holds no pins of its own** — `__TAG__`, `__COMMIT__`,+ `__PNPM_VERSION__`, `__PNPM_SHA256_X64__` and `__PNPM_SHA256_ARM64__` are placeholders+ `update-repo.mts` fills in from the packaged ref, fetching the two tarballs for their+ hashes every run. So there is nothing to keep in step and nothing to gate: a check that+ compared a vendored pin with `package.json` was tried and reverted, because on a+ `pull_request` run it sees main's `package.json` against the branch's manifest and one+ Renovate bump reddens every open pull request, none of which can fix it.++ Consequences: the vendored manifest is a template, not a buildable one (it also+ references a `generated-sources.json` that lives only in the packaging repo), and+ `checkPlaceholdersFilled` fails the run when a new `__NAME__` appears that nothing+ fills — including one written inside a comment. Verify a change to the templating by+ rendering into an empty directory and diffing against the packaging repo:+ `node --experimental-strip-types scripts/flatpak/update-repo.mts /tmp/out [ref]`.+ **Never `cp -r` the packaging repo** to do it — its `.flatpak-builder/` holds a+ multi-gigabyte build tree.- **`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/apps/desktop/flatpak/org.triliumnotes.Trilium.yml b/apps/desktop/flatpak/org.triliumnotes.Trilium.ymlindex 75ee4bfbc0..0d4fac03bb 100644--- a/apps/desktop/flatpak/org.triliumnotes.Trilium.yml+++ b/apps/desktop/flatpak/org.triliumnotes.Trilium.yml@@ -65,19 +65,19 @@ modules:sources:- type: giturl: https://github.com/TriliumNext/Trilium.git- tag: v0.105.0- commit: a0908a6e1e1741a3c3824d803da07300183dcb0c+ tag: __TAG__+ commit: __COMMIT__- generated-sources.json# pnpm 12 ships as a native binary per platform; the wrapper package's# postinstall, which an offline sandbox cannot run, is what would pick one.- type: archive- url: https://registry.npmjs.org/@pnpm/exe.linux-x64/-/exe.linux-x64-12.4.2.tgz- sha256: 545b89d5c6026ac33d4c28bd3c6cc38cc050d571b35a4e69f13aad4a441af142+ url: https://registry.npmjs.org/@pnpm/exe.linux-x64/-/exe.linux-x64-__PNPM_VERSION__.tgz+ sha256: __PNPM_SHA256_X64__dest: flatpak-node/pnpmonly-arches: [x86_64]- type: archive- url: https://registry.npmjs.org/@pnpm/exe.linux-arm64/-/exe.linux-arm64-12.4.2.tgz- sha256: c3bb8caba00f308733b0876d245e1e1f3ad656e6605f4f85dd861457267ae9f2+ url: https://registry.npmjs.org/@pnpm/exe.linux-arm64/-/exe.linux-arm64-__PNPM_VERSION__.tgz+ sha256: __PNPM_SHA256_ARM64__dest: flatpak-node/pnpmonly-arches: [aarch64]# The launch wrapper stays a repo file, reviewable without opening the checkout.diff --git a/scripts/flatpak/update-repo.mts b/scripts/flatpak/update-repo.mtsindex 0290083629..fe20dd28a4 100644--- a/scripts/flatpak/update-repo.mts+++ b/scripts/flatpak/update-repo.mts@@ -11,8 +11,9 @@* pnpm exec tsx ./scripts/flatpak/update-repo.mts <packaging-repo-dir> [ref]** `ref` defaults to HEAD; a tag pins `tag:` and `commit:`, anything else pins- * the bare commit (the beta case). The vendored manifest's own pins are a- * starting point this rewrites, so they can trail the repository.+ * the bare commit (the beta case). The vendored manifest carries a+ * `__PLACEHOLDER__` for every value this fills in, so it holds no pin of its+ * own to fall behind the repository.*/import { execFileSync } from "node:child_process";@@ -41,13 +42,12 @@ export async function main(argv: string[]) {let manifest = updateGitSource(readFileSync(join(FLATPAK_DIR, MANIFEST_NAME), "utf-8"), commit, tag);const pnpmVersion = parsePnpmVersion(git("show", `${commit}:package.json`));- if (getPnpmVersion(manifest) !== pnpmVersion) {- checkPnpmSupported(pnpmVersion);- manifest = updatePnpmPins(manifest, pnpmVersion, {- x64: await sha256OfUrl(pnpmExeUrl("x64", pnpmVersion)),- arm64: await sha256OfUrl(pnpmExeUrl("arm64", pnpmVersion))- });- }+ checkPnpmSupported(pnpmVersion);+ manifest = updatePnpmPins(manifest, pnpmVersion, {+ x64: await sha256OfUrl(pnpmExeUrl("x64", pnpmVersion)),+ arm64: await sha256OfUrl(pnpmExeUrl("arm64", pnpmVersion))+ });+ checkPlaceholdersFilled(manifest);writeFileSync(join(repoDir, MANIFEST_NAME), manifest);for (const file of COPIED_FILES) {@@ -66,12 +66,20 @@ export function formatOutputs(commit: string, tag: string | undefined, pnpmVersi/** Pins the manifest's git source; without a tag, the `tag:` line goes (a beta builds a bare commit). */export function updateGitSource(manifest: string, commit: string, tag?: string): string {- const gitSource = /(url: https:\/\/github\.com\/TriliumNext\/Trilium\.git\n)(\s*tag: \S+\n)?(\s*)commit: [0-9a-f]{40}/;- if (!gitSource.test(manifest)) {+ const tagLine = /^[ \t]*tag: __TAG__\n/m;+ if (!tagLine.test(manifest) || !manifest.includes("__COMMIT__")) {throw new Error("Found no Trilium git source to pin in the manifest.");}- return manifest.replace(gitSource, (_, urlLine: string, _tagLine: string, indent: string) =>- `${urlLine}${tag ? `${indent}tag: ${tag}\n` : ""}${indent}commit: ${commit}`);+ const tagged = tag ? manifest.replace("__TAG__", tag) : manifest.replace(tagLine, "");+ return tagged.replace("__COMMIT__", commit);+}++/** Catches a placeholder added to the manifest that nothing here fills in. */+export function checkPlaceholdersFilled(manifest: string) {+ const left = /__[A-Z0-9_]+__/.exec(manifest);+ if (left) {+ throw new Error(`The manifest still holds ${left[0]}, which nothing fills in.`);+ }}/**@@ -86,15 +94,6 @@ export function checkPnpmSupported(version: string) {}}-/** The version the manifest's per-arch pnpm sources currently pin. */-export function getPnpmVersion(manifest: string): string {- const url = /exe\.linux-x64-([\d.]+)\.tgz/.exec(manifest);- if (!url) {- throw new Error("Found no pnpm source in the manifest.");- }- return url[1];-}-export function parsePnpmVersion(packageJson: string): string {const { packageManager } = JSON.parse(packageJson);const version = /^pnpm@([\d.]+)/.exec(packageManager ?? "")?.[1];@@ -109,14 +108,17 @@ export function updatePnpmPins(version: string,hashes: { x64: string; arm64: string }): string {+ const pins = {+ __PNPM_VERSION__: version,+ __PNPM_SHA256_X64__: hashes.x64,+ __PNPM_SHA256_ARM64__: hashes.arm64+ };let updated = manifest;- for (const arch of ["x64", "arm64"] as const) {- const source = new RegExp(- `(exe\\.linux-${arch}/-/exe\\.linux-${arch}-)[\\d.]+(\\.tgz\\n\\s*sha256: )[0-9a-f]{64}`);- if (!source.test(updated)) {- throw new Error(`Found no pnpm source for ${arch} in the manifest.`);+ for (const [placeholder, value] of Object.entries(pins)) {+ if (!updated.includes(placeholder)) {+ throw new Error(`Found no ${placeholder} to fill in the manifest.`);}- updated = updated.replace(source, `$1${version}$2${hashes[arch]}`);+ updated = updated.replaceAll(placeholder, value);}return updated;}diff --git a/scripts/flatpak/update-repo.spec.ts b/scripts/flatpak/update-repo.spec.tsindex caeac83173..1272b6cf6a 100644--- a/scripts/flatpak/update-repo.spec.ts+++ b/scripts/flatpak/update-repo.spec.ts@@ -1,6 +1,6 @@import { describe, expect, it } from "vitest";-import { checkPnpmSupported, formatOutputs, getPnpmVersion, parsePnpmVersion, updateGitSource, updatePnpmPins } from "./update-repo.mjs";+import { checkPlaceholdersFilled, checkPnpmSupported, formatOutputs, parsePnpmVersion, updateGitSource, updatePnpmPins } from "./update-repo.mjs";const MANIFEST = `\modules:@@ -8,28 +8,28 @@ modules:sources:- type: giturl: https://github.com/TriliumNext/Trilium.git- tag: v0.105.0- commit: a0908a6e1e1741a3c3824d803da07300183dcb0c+ tag: __TAG__+ commit: __COMMIT__- generated-sources.json- type: archive- url: https://registry.npmjs.org/@pnpm/exe.linux-x64/-/exe.linux-x64-12.4.2.tgz- sha256: 545b89d5c6026ac33d4c28bd3c6cc38cc050d571b35a4e69f13aad4a441af142+ url: https://registry.npmjs.org/@pnpm/exe.linux-x64/-/exe.linux-x64-__PNPM_VERSION__.tgz+ sha256: __PNPM_SHA256_X64__dest: flatpak-node/pnpmonly-arches: [x86_64]- type: archive- url: https://registry.npmjs.org/@pnpm/exe.linux-arm64/-/exe.linux-arm64-12.4.2.tgz- sha256: c3bb8caba00f308733b0876d245e1e1f3ad656e6605f4f85dd861457267ae9f2+ url: https://registry.npmjs.org/@pnpm/exe.linux-arm64/-/exe.linux-arm64-__PNPM_VERSION__.tgz+ sha256: __PNPM_SHA256_ARM64__dest: flatpak-node/pnpmonly-arches: [aarch64]`;const NEW_COMMIT = "1234567890abcdef1234567890abcdef12345678";+const HASHES = { x64: "a".repeat(64), arm64: "b".repeat(64) };describe("updateGitSource", () => {- it("pins a release: tag and commit both move", () => {+ it("pins a release: tag and commit both fill in", () => {const updated = updateGitSource(MANIFEST, NEW_COMMIT, "v0.106.0");expect(updated).toContain(` tag: v0.106.0\n commit: ${NEW_COMMIT}`);- expect(updated).not.toContain("v0.105.0");});it("pins a beta: the tag line goes, only the commit stays", () => {@@ -38,14 +38,10 @@ describe("updateGitSource", () => {expect(updated).not.toContain("tag:");});- it("re-adds a tag to a commit-only manifest", () => {- const beta = updateGitSource(MANIFEST, NEW_COMMIT);- const release = updateGitSource(beta, NEW_COMMIT, "v0.106.0");- expect(release).toContain(` tag: v0.106.0\n commit: ${NEW_COMMIT}`);- });-- it("rejects a manifest without the git source", () => {+ it("rejects a manifest without the placeholders, filled ones included", () => {expect(() => updateGitSource("modules: []", NEW_COMMIT)).toThrow(/git source/);+ const filled = updateGitSource(MANIFEST, NEW_COMMIT, "v0.106.0");+ expect(() => updateGitSource(filled, NEW_COMMIT, "v0.107.0")).toThrow(/git source/);});});@@ -59,10 +55,6 @@ describe("formatOutputs", () => {});describe("pnpm pins", () => {- it("reads the pinned version", () => {- expect(getPnpmVersion(MANIFEST)).toBe("12.4.2");- });-it("parses packageManager, with or without a corepack checksum", () => {expect(parsePnpmVersion(`{ "packageManager": "[email protected]" }`)).toBe("12.5.0");expect(parsePnpmVersion(`{ "packageManager": "[email protected]+sha512.abc" }`)).toBe("12.5.0");@@ -70,14 +62,10 @@ describe("pnpm pins", () => {expect(() => parsePnpmVersion(`{}`)).toThrow(/undefined/);});- it("moves both per-arch sources to the new version and hashes", () => {- const updated = updatePnpmPins(MANIFEST, "12.5.0", {- x64: "a".repeat(64),- arm64: "b".repeat(64)- });- expect(updated).toContain(`exe.linux-x64-12.5.0.tgz\n sha256: ${"a".repeat(64)}`);- expect(updated).toContain(`exe.linux-arm64-12.5.0.tgz\n sha256: ${"b".repeat(64)}`);- expect(updated).not.toContain("12.4.2");+ it("fills the version into both per-arch sources, each with its own hash", () => {+ const updated = updatePnpmPins(MANIFEST, "12.5.0", HASHES);+ expect(updated).toContain(`exe.linux-x64-12.5.0.tgz\n sha256: ${HASHES.x64}`);+ expect(updated).toContain(`exe.linux-arm64-12.5.0.tgz\n sha256: ${HASHES.arm64}`);});it("rejects a ref older than the per-arch pnpm packages", () => {@@ -88,8 +76,16 @@ describe("pnpm pins", () => {});it("rejects a manifest missing a per-arch source", () => {- const withoutArm = MANIFEST.replace("exe.linux-arm64", "exe.linux-mips");- expect(() => updatePnpmPins(withoutArm, "12.5.0", { x64: "a".repeat(64), arm64: "b".repeat(64) }))- .toThrow(/arm64/);+ const withoutArm = MANIFEST.replace("__PNPM_SHA256_ARM64__", "deadbeef");+ expect(() => updatePnpmPins(withoutArm, "12.5.0", HASHES)).toThrow(/__PNPM_SHA256_ARM64__/);+ });+});++describe("checkPlaceholdersFilled", () => {+ it("passes a fully pinned manifest and names what a partial one left behind", () => {+ const pinned = updatePnpmPins(updateGitSource(MANIFEST, NEW_COMMIT, "v0.106.0"), "12.5.0", HASHES);+ expect(() => checkPlaceholdersFilled(pinned)).not.toThrow();+ expect(() => checkPlaceholdersFilled(`${pinned} sha256: __ELECTRON_SHA256__\n`))+ .toThrow(/__ELECTRON_SHA256__/);});});