@rickgetz/codex 0.143.0-rick.1 → 0.144.0-rick.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/codex.js +50 -5
  2. package/package.json +2 -2
package/bin/codex.js CHANGED
@@ -11,6 +11,7 @@ import { fileURLToPath } from "url";
11
11
  const __filename = fileURLToPath(import.meta.url);
12
12
  const __dirname = path.dirname(__filename);
13
13
  const require = createRequire(import.meta.url);
14
+ const codexPackageRoot = realpathSync(path.join(__dirname, ".."));
14
15
 
15
16
  const PLATFORM_PACKAGE_SUFFIX_BY_TARGET = {
16
17
  "x86_64-unknown-linux-musl": "linux-x64",
@@ -111,7 +112,9 @@ function findCodexExecutable() {
111
112
  const updateCommand =
112
113
  packageManager === "bun"
113
114
  ? `bun install -g ${rootPackageName}@latest`
114
- : `npm install -g ${rootPackageName}@latest`;
115
+ : packageManager === "pnpm"
116
+ ? `pnpm add -g ${rootPackageName}@latest`
117
+ : `npm install -g ${rootPackageName}@latest`;
115
118
  throw new Error(
116
119
  `Missing optional dependency ${platformPackage}. Reinstall Codex: ${updateCommand}`,
117
120
  );
@@ -125,11 +128,47 @@ const binaryPath = findCodexExecutable();
125
128
  // and guarantees that when either the child terminates or the parent
126
129
  // receives a fatal signal, both processes exit in a predictable manner.
127
130
 
131
+ function isPnpmOwnedCodexInstall(nodeModulesDir) {
132
+ if (!existsSync(path.join(nodeModulesDir, ".modules.yaml"))) {
133
+ return false;
134
+ }
135
+
136
+ try {
137
+ return (
138
+ realpathSync(path.join(nodeModulesDir, "@openai", "codex")) ===
139
+ codexPackageRoot
140
+ );
141
+ } catch {
142
+ return false;
143
+ }
144
+ }
145
+
128
146
  /**
129
147
  * Use heuristics to detect the package manager that was used to install Codex
130
148
  * in order to give the user a hint about how to update it.
131
149
  */
132
150
  function detectPackageManager() {
151
+ // pnpm's owning node_modules directory can be several parents above the
152
+ // package in isolated global layouts. Search ancestors of both the canonical
153
+ // package root and lexical entrypoint because pnpm may link either path.
154
+ const entrypointDir = path.dirname(path.resolve(process.argv[1]));
155
+ for (const startDir of new Set([codexPackageRoot, entrypointDir])) {
156
+ const filesystemRoot = path.parse(startDir).root;
157
+ for (
158
+ let currentDir = startDir;
159
+ currentDir !== filesystemRoot;
160
+ currentDir = path.dirname(currentDir)
161
+ ) {
162
+ if (isPnpmOwnedCodexInstall(path.join(currentDir, "node_modules"))) {
163
+ return "pnpm";
164
+ }
165
+ }
166
+
167
+ if (isPnpmOwnedCodexInstall(path.join(filesystemRoot, "node_modules"))) {
168
+ return "pnpm";
169
+ }
170
+ }
171
+
133
172
  const userAgent = process.env.npm_config_user_agent || "";
134
173
  if (/\bbun\//.test(userAgent)) {
135
174
  return "bun";
@@ -150,15 +189,21 @@ function detectPackageManager() {
150
189
  return userAgent ? "npm" : null;
151
190
  }
152
191
 
192
+ const packageManager = detectPackageManager();
153
193
  const packageManagerEnvVar =
154
- detectPackageManager() === "bun"
194
+ packageManager === "bun"
155
195
  ? "CODEX_MANAGED_BY_BUN"
156
- : "CODEX_MANAGED_BY_NPM";
196
+ : packageManager === "pnpm"
197
+ ? "CODEX_MANAGED_BY_PNPM"
198
+ : "CODEX_MANAGED_BY_NPM";
157
199
  const env = {
158
200
  ...process.env,
159
- [packageManagerEnvVar]: "1",
160
- CODEX_MANAGED_PACKAGE_ROOT: realpathSync(path.join(__dirname, "..")),
201
+ CODEX_MANAGED_PACKAGE_ROOT: codexPackageRoot,
161
202
  };
203
+ delete env.CODEX_MANAGED_BY_NPM;
204
+ delete env.CODEX_MANAGED_BY_BUN;
205
+ delete env.CODEX_MANAGED_BY_PNPM;
206
+ env[packageManagerEnvVar] = "1";
162
207
 
163
208
  const child = spawn(binaryPath, process.argv.slice(2), {
164
209
  stdio: "inherit",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rickgetz/codex",
3
- "version": "0.143.0-rick.1",
3
+ "version": "0.144.0-rick.1",
4
4
  "description": "Codex CLI is a coding agent from OpenAI that runs locally on your computer.",
5
5
  "license": "Apache-2.0",
6
6
  "bin": {
@@ -20,6 +20,6 @@
20
20
  },
21
21
  "packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319",
22
22
  "optionalDependencies": {
23
- "@rickgetz/codex-darwin-arm64": "npm:@rickgetz/codex@0.143.0-rick.1-darwin-arm64"
23
+ "@rickgetz/codex-darwin-arm64": "npm:@rickgetz/codex@0.144.0-rick.1-darwin-arm64"
24
24
  }
25
25
  }