From 03e4e397ecc2f410b994f8d2d7da01ba3cd3ba32 Mon Sep 17 00:00:00 2001 From: halfaipg Date: Wed, 29 Jul 2026 21:55:05 -0400 Subject: [PATCH] fix(release): support npm and native version lookup --- .github/workflows/build-binaries.yml | 13 +++++++++++-- package-lock.json | 4 ++-- package.json | 2 +- src/version.ts | 26 +++++++++++++++++++++----- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build-binaries.yml b/.github/workflows/build-binaries.yml index 65984f2..d9c0c03 100644 --- a/.github/workflows/build-binaries.yml +++ b/.github/workflows/build-binaries.yml @@ -71,7 +71,11 @@ jobs: EOF - name: Compile ${{ matrix.target }} - run: bun build --compile --target=${{ matrix.target }} src/cli.tsx --outfile=${{ matrix.asset }} + run: | + VERSION_JSON="$(node -p "JSON.stringify(require('./package.json').version)")" + bun build --compile --target=${{ matrix.target }} \ + --define "CODEBASE_BUILD_VERSION=${VERSION_JSON}" \ + src/cli.tsx --outfile=${{ matrix.asset }} - name: Smoke-test binary # Only the linux-x64 binary can run on the linux runner. The @@ -143,7 +147,12 @@ jobs: EOF - name: Compile native Windows binary - run: bun build --compile --target=bun-windows-x64 src/cli.tsx --outfile=codebase.exe + shell: pwsh + run: | + $versionJson = node -p "JSON.stringify(require('./package.json').version)" + bun build --compile --target=bun-windows-x64 ` + --define "CODEBASE_BUILD_VERSION=$versionJson" ` + src/cli.tsx --outfile=codebase.exe - name: Invoke --version and --help # Both should exit 0 on a healthy binary. Asking for --help also diff --git a/package-lock.json b/package-lock.json index f31e99f..cd22f5a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codebase-cli", - "version": "2.0.0-pre.85", + "version": "2.0.0-pre.86", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "codebase-cli", - "version": "2.0.0-pre.85", + "version": "2.0.0-pre.86", "license": "MIT", "dependencies": { "@agentclientprotocol/sdk": "^1.3.0", diff --git a/package.json b/package.json index f245934..fef0f30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "codebase-cli", - "version": "2.0.0-pre.85", + "version": "2.0.0-pre.86", "description": "Codebase CLI — a TypeScript coding agent on the pi-mono runtime. OAuth-aware, any LLM provider, single install.", "keywords": [ "ai", diff --git a/src/version.ts b/src/version.ts index c5894da..86c359d 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,8 +1,24 @@ -import packageMetadata from "../package.json"; +import { readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import { fileURLToPath } from "node:url"; + +declare const CODEBASE_BUILD_VERSION: string | undefined; /** - * Keep package.json as the single source of truth, but import it so native - * Bun builds embed the version instead of trying to read a neighboring file - * that does not exist beside a standalone binary. + * Native builds replace CODEBASE_BUILD_VERSION at compile time. The npm + * package keeps package.json beside dist/, so regular Node installs resolve + * the same source of truth from disk without JSON-module import semantics. */ -export const VERSION = packageMetadata.version; +export const VERSION: string = (() => { + if (typeof CODEBASE_BUILD_VERSION !== "undefined" && CODEBASE_BUILD_VERSION) { + return CODEBASE_BUILD_VERSION; + } + + try { + const here = dirname(fileURLToPath(import.meta.url)); + const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8")) as { version?: string }; + return pkg.version ?? "?.?.?"; + } catch { + return "?.?.?"; + } +})();