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
fix(release): keep winget from replacing nightly builds
Elian Doran40980c72e2df
diff --git a/scripts/update-nightly-version.spec.ts b/scripts/update-nightly-version.spec.tsnew file mode 100644index 0000000000..bca5697a51--- /dev/null+++ b/scripts/update-nightly-version.spec.ts@@ -0,0 +1,18 @@+import { describe, expect, it } from "vitest";++import { processVersion } from "./update-nightly-version";++const DATE = new Date("2026-10-25T14:03:09Z");++describe("processVersion", () => {+ it("bumps the patch of a released version so the nightly sorts above it", () => {+ expect(processVersion("0.106.1", DATE)).toBe("0.106.2-test-261025-140309");+ expect(processVersion("0.106.9", DATE)).toBe("0.106.10-test-261025-140309");+ });++ it("keeps the base of a pre-release and of an existing nightly", () => {+ expect(processVersion("0.107.0-beta", DATE)).toBe("0.107.0-test-261025-140309");+ expect(processVersion("0.107.0-rc1", DATE)).toBe("0.107.0-rc1-test-261025-140309");+ expect(processVersion("0.106.2-test-261024-000000", DATE)).toBe("0.106.2-test-261025-140309");+ });+});diff --git a/scripts/update-nightly-version.ts b/scripts/update-nightly-version.tsindex fa49954dfe..e300befc22 100644--- a/scripts/update-nightly-version.ts+++ b/scripts/update-nightly-version.ts@@ -7,7 +7,8 @@* user might run into module not found errors or styling errors caused by an old cache.** This script is supposed to be run in the CI, which will update locally the version field of- * `package.json` to contain the date. For example, `0.90.9-beta` will become `0.90.9-test-YYMMDD-HHMMSS`.+ * `package.json` to contain the date. For example, `0.90.9-beta` will become `0.90.9-test-YYMMDD-HHMMSS`,+ * and the released `0.90.9` will become `0.90.10-test-YYMMDD-HHMMSS`.**/@@ -15,22 +16,34 @@ import fs from "fs";import { dirname, join } from "path";import { fileURLToPath } from "url";-function processVersion(version) {- // Remove the beta suffix if any.- version = version.replace("-beta", "");+const SCRIPT_PATH = fileURLToPath(import.meta.url);- // Add the nightly suffix, plus the date.- const referenceDate = new Date().toISOString().substring(2, 19).replace(/[-:]*/g, "").replace("T", "-");- version = `${version}-test-${referenceDate}`;+/**+ * Returns the nightly version for the `package.json` version `version`, built at `date`.+ *+ * A pre-release sorts below its release, so a nightly of a released version bumps the patch+ * number first; otherwise winget and the in-app update check offer the release as an upgrade.+ */+export function processVersion(version: string, date: Date) {+ if (version.includes("-test-")) {+ version = version.split("-test-")[0];+ } else if (version.endsWith("-beta")) {+ version = version.replace("-beta", "");+ } else if (/^\d+\.\d+\.\d+$/.test(version)) {+ const [ major, minor, patch ] = version.split(".");+ version = `${major}.${minor}.${Number(patch) + 1}`;+ }- return version;+ // Add the nightly suffix, plus the date.+ const referenceDate = date.toISOString().substring(2, 19).replace(/[-:]*/g, "").replace("T", "-");+ return `${version}-test-${referenceDate}`;}-function patchPackageJson(packageJsonPath) {+function patchPackageJson(packageJsonPath: string, date: Date) {// Read the version from package.json and process it.const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));- const currentVersion = packageJson.version.split("-test-")[0];- const adjustedVersion = processVersion(currentVersion);+ const currentVersion = packageJson.version;+ const adjustedVersion = processVersion(currentVersion, date);console.log("Current version is", currentVersion);console.log("Adjusted version is", adjustedVersion);@@ -41,20 +54,23 @@ function patchPackageJson(packageJsonPath) {}function main() {- const scriptDir = dirname(fileURLToPath(import.meta.url));+ const scriptDir = dirname(SCRIPT_PATH);+ const date = new Date();const rootPackageJson = join(scriptDir, "..", "package.json");- patchPackageJson(rootPackageJson);+ patchPackageJson(rootPackageJson, date);for (const app of ["server", "client", "standalone", "desktop"]) {const appPackageJsonPath = join(scriptDir, "..", "apps", app, "package.json");- patchPackageJson(appPackageJsonPath);+ patchPackageJson(appPackageJsonPath, date);}for (const packageName of [ "pdfjs-viewer" ]) {const packageJsonPath = join(scriptDir, "..", "packages", packageName, "package.json");- patchPackageJson(packageJsonPath);+ patchPackageJson(packageJsonPath, date);}}-main();+if (process.argv[1] === SCRIPT_PATH) {+ main();+}