fix: always load version from package.json at runtime

This commit is contained in:
Michael Bolin
2025-05-12 18:01:44 -07:00
parent 61b881d4e5
commit 99e67d2e44
11 changed files with 33 additions and 15 deletions

View File

@@ -1,12 +1,13 @@
import type { ApprovalPolicy } from "./approvals";
import type { AppConfig } from "./utils/config";
import type { TerminalChatSession } from "./utils/session.js";
import type { ResponseItem } from "openai/resources/responses/responses";
import TerminalChat from "./components/chat/terminal-chat";
import TerminalChatPastRollout from "./components/chat/terminal-chat-past-rollout";
import { checkInGit } from "./utils/check-in-git";
import { CLI_VERSION, type TerminalChatSession } from "./utils/session.js";
import { onExit } from "./utils/terminal";
import { CLI_VERSION } from "./version";
import { ConfirmInput } from "@inkjs/ui";
import { Box, Text, useApp, useStdin } from "ink";
import React, { useMemo, useState } from "react";

View File

@@ -584,7 +584,7 @@ export default function TerminalChatInput({
try {
const os = await import("node:os");
const { CLI_VERSION } = await import("../../utils/session.js");
const { CLI_VERSION } = await import("../../version.js");
const { buildBugReportUrl } = await import(
"../../utils/bug-report.js"
);

View File

@@ -24,7 +24,6 @@ import {
uniqueById,
} from "../../utils/model-utils.js";
import { createOpenAIClient } from "../../utils/openai-client.js";
import { CLI_VERSION } from "../../utils/session.js";
import { shortCwd } from "../../utils/short-path.js";
import { saveRollout } from "../../utils/storage/save-rollout.js";
import ApprovalModeOverlay from "../approval-mode-overlay.js";
@@ -36,6 +35,7 @@ import chalk from "chalk";
import { Box, Text } from "ink";
import { spawn } from "node:child_process";
import React, { useEffect, useMemo, useRef, useState } from "react";
import { CLI_VERSION } from "src/version.js";
import { inspect } from "util";
export type OverlayModeType =

View File

@@ -24,7 +24,6 @@ import { parseToolCallArguments } from "../parsers.js";
import { responsesCreateViaChatCompletions } from "../responses.js";
import {
ORIGIN,
CLI_VERSION,
getSessionId,
setCurrentModel,
setSessionId,
@@ -33,6 +32,7 @@ import { handleExecCommand } from "./handle-exec-command.js";
import { HttpsProxyAgent } from "https-proxy-agent";
import { randomUUID } from "node:crypto";
import OpenAI, { APIConnectionTimeoutError, AzureOpenAI } from "openai";
import { CLI_VERSION } from "src/version.js";
// Wait time before retrying after rate limit errors (ms).
const RATE_LIMIT_RETRY_WAIT_MS = parseInt(

View File

@@ -1,7 +1,7 @@
import type { AgentName } from "package-manager-detector";
import { detectInstallerByPath } from "./package-manager-detector";
import { CLI_VERSION } from "./session";
import { CLI_VERSION } from "../version";
import boxen from "boxen";
import chalk from "chalk";
import { getLatestVersion } from "fast-npm-meta";

View File

@@ -1,9 +1,3 @@
// Node ESM supports JSON imports behind an assertion. TypeScript's
// `resolveJsonModule` takes care of the typings.
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 = {

8
codex-cli/src/version.ts Normal file
View File

@@ -0,0 +1,8 @@
// Note that "../package.json" is marked external in build.mjs. This ensures
// that the contents of package.json will always be read at runtime, which is
// preferable so we do not have to make a temporary change to package.json in
// the source tree to update the version number in the code.
import pkg from "../package.json" with { type: "json" };
// Read the version directly from package.json.
export const CLI_VERSION: string = (pkg as { version: string }).version;