Skip to content

Commit 66d4010

Browse files
committed
fix: restore codex.js entry point to match deployed package layout
The 0.138.0 merge left unresolved conflict markers in codex-cli/bin/codex.js, breaking npm installs. The upstream refactor changed the binary path to vendor/{triple}/bin/codex, but our packaging still uses vendor/{triple}/codex/codex. Restored the pre-0.138.0 version that matches our actual npm deployment.
1 parent 4ad7632 commit 66d4010

1 file changed

Lines changed: 12 additions & 34 deletions

File tree

codex-cli/bin/codex.js

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ if (!platformPackage) {
7575
throw new Error(`Unsupported target triple: ${targetTriple}`);
7676
}
7777

78-
<<<<<<< HEAD
7978
const codexBinaryName = process.platform === "win32" ? "codex.exe" : "codex";
8079
const localVendorRoot = path.join(__dirname, "..", "vendor");
8180
const localBinaryPath = path.join(
@@ -105,27 +104,6 @@ try {
105104
}
106105

107106
if (!vendorRoot) {
108-
=======
109-
function findCodexExecutable() {
110-
let vendorRoot;
111-
try {
112-
const packageJsonPath = require.resolve(`${platformPackage}/package.json`);
113-
vendorRoot = path.join(path.dirname(packageJsonPath), "vendor");
114-
} catch {
115-
vendorRoot = path.join(__dirname, "..", "vendor");
116-
}
117-
118-
const codexExecutable = path.join(
119-
vendorRoot,
120-
targetTriple,
121-
"bin",
122-
process.platform === "win32" ? "codex.exe" : "codex",
123-
);
124-
if (existsSync(codexExecutable)) {
125-
return codexExecutable;
126-
}
127-
128-
>>>>>>> rust-v0.138.0
129107
const packageManager = detectPackageManager();
130108
const updateCommand =
131109
packageManager === "bun"
@@ -136,19 +114,25 @@ function findCodexExecutable() {
136114
);
137115
}
138116

139-
<<<<<<< HEAD
140117
const archRoot = path.join(vendorRoot, targetTriple);
141118
const binaryPath = path.join(archRoot, "codex", codexBinaryName);
142-
=======
143-
const binaryPath = findCodexExecutable();
144-
>>>>>>> rust-v0.138.0
145119

146120
// Use an asynchronous spawn instead of spawnSync so that Node is able to
147121
// respond to signals (e.g. Ctrl-C / SIGINT) while the native binary is
148122
// executing. This allows us to forward those signals to the child process
149123
// and guarantees that when either the child terminates or the parent
150124
// receives a fatal signal, both processes exit in a predictable manner.
151125

126+
function getUpdatedPath(newDirs) {
127+
const pathSep = process.platform === "win32" ? ";" : ":";
128+
const existingPath = process.env.PATH || "";
129+
const updatedPath = [
130+
...newDirs,
131+
...existingPath.split(pathSep).filter(Boolean),
132+
].join(pathSep);
133+
return updatedPath;
134+
}
135+
152136
/**
153137
* Use heuristics to detect the package manager that was used to install Codex
154138
* in order to give the user a hint about how to update it.
@@ -174,7 +158,6 @@ function detectPackageManager() {
174158
return userAgent ? "npm" : null;
175159
}
176160

177-
<<<<<<< HEAD
178161
const additionalDirs = [];
179162
const pathDir = path.join(archRoot, "path");
180163
if (existsSync(pathDir)) {
@@ -183,17 +166,12 @@ if (existsSync(pathDir)) {
183166
const updatedPath = getUpdatedPath(additionalDirs);
184167

185168
const env = { ...process.env, PATH: updatedPath };
186-
=======
187-
>>>>>>> rust-v0.138.0
188169
const packageManagerEnvVar =
189170
detectPackageManager() === "bun"
190171
? "CODEX_MANAGED_BY_BUN"
191172
: "CODEX_MANAGED_BY_NPM";
192-
const env = {
193-
...process.env,
194-
[packageManagerEnvVar]: "1",
195-
CODEX_MANAGED_PACKAGE_ROOT: realpathSync(path.join(__dirname, "..")),
196-
};
173+
env[packageManagerEnvVar] = "1";
174+
env.CODEX_MANAGED_PACKAGE_ROOT = realpathSync(path.join(__dirname, ".."));
197175

198176
const child = spawn(binaryPath, process.argv.slice(2), {
199177
stdio: "inherit",

0 commit comments

Comments
 (0)