Skip to content

Commit 5afc596

Browse files
authored
Merge pull request #16 from codebase/codex/release-version-runtime
fix(release): support npm and native version lookup
2 parents 97cdef3 + 03e4e39 commit 5afc596

4 files changed

Lines changed: 35 additions & 10 deletions

File tree

.github/workflows/build-binaries.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ jobs:
7171
EOF
7272
7373
- name: Compile ${{ matrix.target }}
74-
run: bun build --compile --target=${{ matrix.target }} src/cli.tsx --outfile=${{ matrix.asset }}
74+
run: |
75+
VERSION_JSON="$(node -p "JSON.stringify(require('./package.json').version)")"
76+
bun build --compile --target=${{ matrix.target }} \
77+
--define "CODEBASE_BUILD_VERSION=${VERSION_JSON}" \
78+
src/cli.tsx --outfile=${{ matrix.asset }}
7579
7680
- name: Smoke-test binary
7781
# Only the linux-x64 binary can run on the linux runner. The
@@ -143,7 +147,12 @@ jobs:
143147
EOF
144148
145149
- name: Compile native Windows binary
146-
run: bun build --compile --target=bun-windows-x64 src/cli.tsx --outfile=codebase.exe
150+
shell: pwsh
151+
run: |
152+
$versionJson = node -p "JSON.stringify(require('./package.json').version)"
153+
bun build --compile --target=bun-windows-x64 `
154+
--define "CODEBASE_BUILD_VERSION=$versionJson" `
155+
src/cli.tsx --outfile=codebase.exe
147156
148157
- name: Invoke --version and --help
149158
# Both should exit 0 on a healthy binary. Asking for --help also

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codebase-cli",
3-
"version": "2.0.0-pre.85",
3+
"version": "2.0.0-pre.86",
44
"description": "Codebase CLI — a TypeScript coding agent on the pi-mono runtime. OAuth-aware, any LLM provider, single install.",
55
"keywords": [
66
"ai",

src/version.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
import packageMetadata from "../package.json";
1+
import { readFileSync } from "node:fs";
2+
import { dirname, join } from "node:path";
3+
import { fileURLToPath } from "node:url";
4+
5+
declare const CODEBASE_BUILD_VERSION: string | undefined;
26

37
/**
4-
* Keep package.json as the single source of truth, but import it so native
5-
* Bun builds embed the version instead of trying to read a neighboring file
6-
* that does not exist beside a standalone binary.
8+
* Native builds replace CODEBASE_BUILD_VERSION at compile time. The npm
9+
* package keeps package.json beside dist/, so regular Node installs resolve
10+
* the same source of truth from disk without JSON-module import semantics.
711
*/
8-
export const VERSION = packageMetadata.version;
12+
export const VERSION: string = (() => {
13+
if (typeof CODEBASE_BUILD_VERSION !== "undefined" && CODEBASE_BUILD_VERSION) {
14+
return CODEBASE_BUILD_VERSION;
15+
}
16+
17+
try {
18+
const here = dirname(fileURLToPath(import.meta.url));
19+
const pkg = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8")) as { version?: string };
20+
return pkg.version ?? "?.?.?";
21+
} catch {
22+
return "?.?.?";
23+
}
24+
})();

0 commit comments

Comments
 (0)