Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
36 changes: 35 additions & 1 deletion codex-cli/bin/codex.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,50 @@ function getUpdatedPath(newDirs) {
return updatedPath;
}

function detectPackageManager() {
const userAgent = process.env.npm_config_user_agent || "";
if (/\bbun\//.test(userAgent)) {
return "bun";
}

const execPath = process.env.npm_execpath || "";
if (execPath.includes("bun")) {
return "bun";
}

if (
process.env.BUN_INSTALL ||
process.env.BUN_INSTALL_GLOBAL_DIR ||
process.env.BUN_INSTALL_BIN_DIR
) {
return "bun";
}

if (userAgent) {
return "npm";
}

return null;
}

const additionalDirs = [];
const pathDir = path.join(archRoot, "path");
if (existsSync(pathDir)) {
additionalDirs.push(pathDir);
}
const updatedPath = getUpdatedPath(additionalDirs);

const env = { ...process.env, PATH: updatedPath };
const packageManager = detectPackageManager();
if (packageManager === "bun") {
env.CODEX_MANAGED_BY_BUN = "1";
} else {
env.CODEX_MANAGED_BY_NPM = "1";
}

const child = spawn(binaryPath, process.argv.slice(2), {
stdio: "inherit",
env: { ...process.env, PATH: updatedPath, CODEX_MANAGED_BY_NPM: "1" },
env,
});

child.on("error", (err) => {
Expand Down
10 changes: 9 additions & 1 deletion codex-rs/tui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ async fn run_ratatui_app(

let current_version = env!("CARGO_PKG_VERSION");
let exe = std::env::current_exe()?;
let managed_by_bun = std::env::var_os("CODEX_MANAGED_BY_BUN").is_some();
let managed_by_npm = std::env::var_os("CODEX_MANAGED_BY_NPM").is_some();

let mut content_lines: Vec<Line<'static>> = vec![
Expand All @@ -330,7 +331,14 @@ async fn run_ratatui_app(
Line::from(""),
];

if managed_by_npm {
if managed_by_bun {
let bun_cmd = "bun install -g @openai/codex@latest";
content_lines.push(Line::from(vec![
"Run ".into(),
bun_cmd.cyan(),
" to update.".into(),
]));
} else if managed_by_npm {
let npm_cmd = "npm install -g @openai/codex@latest";
content_lines.push(Line::from(vec![
"Run ".into(),
Expand Down
Loading