From 7a36c1905f368847eb43c08bd90e3f2bc2f8b7fa Mon Sep 17 00:00:00 2001 From: Ajay Ghanwat Date: Mon, 24 Aug 2026 15:03:38 +0530 Subject: [PATCH] fix(cli): handle version flags before workspace discovery --- bun.lock | 2 +- packages/cli/package.json | 2 +- packages/cli/src/index.ts | 5 +++++ packages/cli/test/update-notifier.test.ts | 26 +++++++++++++++++++++-- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/bun.lock b/bun.lock index 2a573ee0..44afe7ae 100644 --- a/bun.lock +++ b/bun.lock @@ -292,7 +292,7 @@ }, "packages/cli": { "name": "@wrnexus/cli", - "version": "0.8.62", + "version": "0.8.63", "bin": { "wrnexus": "src/index.ts", }, diff --git a/packages/cli/package.json b/packages/cli/package.json index c0c2307a..d814d2ac 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "@wrnexus/cli", - "version": "0.8.62", + "version": "0.8.63", "type": "module", "main": "src/index.ts", "exports": { diff --git a/packages/cli/src/index.ts b/packages/cli/src/index.ts index 4cf1f3ac..c942c309 100644 --- a/packages/cli/src/index.ts +++ b/packages/cli/src/index.ts @@ -113,6 +113,11 @@ Update options: --dry-run previews changes; --no-verify skips post-update check/ async function main(): Promise { const [command, ...rest] = process.argv.slice(2); + if (command === "--version" || command === "-v" || command === "version") { + console.log(currentCliVersion()); + return; + } + notifyIfUpdateAvailable(currentCliVersion(), command); switch (command) { diff --git a/packages/cli/test/update-notifier.test.ts b/packages/cli/test/update-notifier.test.ts index 7c3a9def..d8f1013e 100644 --- a/packages/cli/test/update-notifier.test.ts +++ b/packages/cli/test/update-notifier.test.ts @@ -1,8 +1,12 @@ 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"; +import { join, resolve } from "node:path"; +import { + compareVersions, + currentCliVersion, + notifyIfUpdateAvailable, +} from "../src/update-notifier.ts"; const originalCache = process.env.WRNEXUS_UPDATE_CACHE; @@ -35,3 +39,21 @@ test("cached update checks suggest the exact upgrade command", () => { rmSync(root, { recursive: true, force: true }); } }); + +test("--version prints the package version outside a WrNexus workspace", () => { + const root = mkdtempSync(join(tmpdir(), "wrnexus-version-")); + try { + const result = Bun.spawnSync({ + cmd: [process.execPath, resolve(import.meta.dir, "../src/index.ts"), "--version"], + cwd: root, + env: { ...process.env, WRNEXUS_NO_UPDATE_CHECK: "1" }, + stdout: "pipe", + stderr: "pipe", + }); + expect(result.exitCode).toBe(0); + expect(result.stdout.toString().trim()).toBe(currentCliVersion()); + expect(result.stderr.toString()).toBe(""); + } finally { + rmSync(root, { recursive: true, force: true }); + } +});