feat: add safe project upgrades and production performance fixes

This commit is contained in:
2026-07-12 16:54:22 +05:30
parent a524c08126
commit 935b3103dd
68 changed files with 555 additions and 107 deletions
+37
View File
@@ -0,0 +1,37 @@
import { afterEach, expect, test } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { compareVersions, notifyIfUpdateAvailable } from "../src/update-notifier.ts";
const originalCache = process.env.WRNEXUS_UPDATE_CACHE;
afterEach(() => {
if (originalCache === undefined) delete process.env.WRNEXUS_UPDATE_CACHE;
else process.env.WRNEXUS_UPDATE_CACHE = originalCache;
});
test("compareVersions compares stable semantic versions", () => {
expect(compareVersions("0.2.14", "0.2.13")).toBe(1);
expect(compareVersions("0.2.13", "0.2.13")).toBe(0);
expect(compareVersions("0.2.12", "0.2.13")).toBe(-1);
});
test("cached update checks suggest the exact upgrade command", () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-notify-"));
const cache = join(root, "update.json");
process.env.WRNEXUS_UPDATE_CACHE = cache;
writeFileSync(cache, JSON.stringify({ checkedAt: Date.now(), latest: "0.2.14" }));
const messages: string[] = [];
const original = console.log;
console.log = (...parts) => messages.push(parts.join(" "));
try {
notifyIfUpdateAvailable("0.2.13", "dev");
expect(messages.join("\n")).toContain("WRNexusJS 0.2.13 → 0.2.14");
expect(messages.join("\n")).toContain("wrnexus update --latest");
} finally {
console.log = original;
rmSync(root, { recursive: true, force: true });
}
});
+37
View File
@@ -0,0 +1,37 @@
import { expect, test } from "bun:test";
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { updateApp } from "../src/update.ts";
test("updateApp migrates project files without marking an unverified update complete", () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-update-"));
mkdirSync(join(root, "app", "pages"), { recursive: true });
writeFileSync(
join(root, "package.json"),
JSON.stringify({
name: "legacy-app",
scripts: { dev: "wrnexus dev ." },
dependencies: { "@wrnexus/core": "0.2.13" },
wrnexus: { version: "0.2.13" },
}),
);
writeFileSync(join(root, ".gitignore"), "node_modules/\n");
try {
const result = updateApp(root, "0.2.14", false);
expect(result).not.toBeNull();
const pkg = JSON.parse(readFileSync(join(root, "package.json"), "utf8"));
expect(pkg.dependencies["@wrnexus/core"]).toBe("^0.2.14");
expect(pkg.scripts.build).toBe("wrnexus build .");
expect(pkg.scripts.start).toBe("bun dist/server.js");
expect(pkg.scripts.production).toBe("bun run build && bun run start");
expect(pkg.wrnexus.version).toBe("0.2.13");
const gitignore = readFileSync(join(root, ".gitignore"), "utf8");
expect(gitignore).toContain("!.env.example");
expect(gitignore).toContain("mobile/android/");
} finally {
rmSync(root, { recursive: true, force: true });
}
});