fix: read version from package.json instead of modifying session.ts (#753)

I am working to simplify the build process. As a first step, update
`session.ts` so it reads the `version` from `package.json` at runtime so
we no longer have to modify it during the build process. I want to get
to a place where the build looks like:

```
cd codex-cli
pnpm i
pnpm build
RELEASE_DIR=$(mktemp -d)
cp -r bin "$RELEASE_DIR/bin"
cp -r dist "$RELEASE_DIR/dist"
cp -r src "$RELEASE_DIR/src" # important if we want sourcemaps to continue to work
cp ../README.md "$RELEASE_DIR"
VERSION=$(printf '0.1.%d' $(date +%y%m%d%H%M))
jq --arg version "$VERSION" '.version = $version' package.json > "$RELEASE_DIR/package.json"
```

Then the contents of `$RELEASE_DIR` should be good to `npm publish`, no?
This commit is contained in:
Michael Bolin
2025-04-30 11:03:10 -07:00
committed by GitHub
parent c432d9ef81
commit 84aaefa102
3 changed files with 10 additions and 3 deletions

View File

@@ -1,4 +1,11 @@
export const CLI_VERSION = "0.1.2504251709"; // Must be in sync with package.json.
// Node ESM supports JSON imports behind an assertion. TypeScript's
// `resolveJsonModule` takes care of the typings.
//
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import pkg from "../../package.json" assert { type: "json" };
// Read the version directly from package.json.
export const CLI_VERSION: string = (pkg as { version: string }).version;
export const ORIGIN = "codex_cli_ts";
export type TerminalChatSession = {