Skip to content

Commit d57e0f0

Browse files
app: fix PATH for packaged app (gh/codex); prod asset base
1 parent 0817b23 commit d57e0f0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"vite": "^5.0.10"
4242
},
4343
"dependencies": {
44+
"fix-path": "^4.0.0",
4445
"@radix-ui/react-alert-dialog": "^1.1.15",
4546
"@radix-ui/react-collapsible": "^1.1.12",
4647
"@radix-ui/react-select": "^2.2.6",

src/main/main.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
import { app, nativeImage } from 'electron'
2+
// Ensure PATH matches the user's shell when launched from Finder (macOS)
3+
// so Homebrew/NPM global binaries like `gh` and `codex` are found.
4+
try {
5+
// Lazy import to avoid bundler complaints if not present on other platforms
6+
// We also defensively prepend common Homebrew locations.
7+
// eslint-disable-next-line @typescript-eslint/no-var-requires
8+
const fixPath = require('fix-path');
9+
if (typeof fixPath === 'function') fixPath();
10+
} catch {
11+
// no-op if fix-path isn't available at runtime
12+
}
13+
14+
if (process.platform === 'darwin') {
15+
const extras = ['/opt/homebrew/bin', '/usr/local/bin', '/opt/homebrew/sbin', '/usr/local/sbin'];
16+
const cur = process.env.PATH || '';
17+
const parts = cur.split(':').filter(Boolean);
18+
for (const p of extras) {
19+
if (!parts.includes(p)) parts.unshift(p);
20+
}
21+
process.env.PATH = parts.join(':');
22+
23+
// As a last resort, ask the user's login shell for PATH and merge it in.
24+
try {
25+
const { execSync } = require('child_process');
26+
const shell = process.env.SHELL || '/bin/zsh';
27+
const loginPath = execSync(`${shell} -ilc 'echo -n $PATH'`, { encoding: 'utf8' });
28+
if (loginPath) {
29+
const merged = new Set((loginPath + ':' + process.env.PATH).split(':').filter(Boolean));
30+
process.env.PATH = Array.from(merged).join(':');
31+
}
32+
} catch {}
33+
}
234
import { join } from 'path'
335
import { existsSync, readFileSync } from 'fs'
436
import { createMainWindow } from './app/window'

0 commit comments

Comments
 (0)