Skip to content

Commit 151b923

Browse files
committed
fix: include cache bin directory in which() lookups
Move Global.Path.bin from the data directory to the cache directory, and append it to PATH in which() so tools installed via npm are discoverable without being on the system PATH.
1 parent ddcb32a commit 151b923

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

packages/opencode/src/global/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export namespace Global {
1818
return process.env.OPENCODE_TEST_HOME || os.homedir()
1919
},
2020
data,
21-
bin: path.join(data, "bin"),
21+
bin: path.join(cache, "bin"),
2222
log: path.join(data, "log"),
2323
cache,
2424
config,

packages/opencode/src/util/which.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import whichPkg from "which"
2+
import path from "path"
3+
import { Global } from "../global"
24

35
export function which(cmd: string, env?: NodeJS.ProcessEnv) {
6+
const base = env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path ?? ""
7+
const full = base ? base + path.delimiter + Global.Path.bin : Global.Path.bin
48
const result = whichPkg.sync(cmd, {
59
nothrow: true,
6-
path: env?.PATH ?? env?.Path ?? process.env.PATH ?? process.env.Path,
10+
path: full,
711
pathExt: env?.PATHEXT ?? env?.PathExt ?? process.env.PATHEXT ?? process.env.PathExt,
812
})
913
return typeof result === "string" ? result : null

0 commit comments

Comments
 (0)