Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions .github/workflows/build-binaries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
26 changes: 21 additions & 5 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -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 "?.?.?";
}
})();
Loading