fix(cli-run): skip unresolved opencode bin path injection

This commit is contained in:
YeonGyu-Kim
2026-02-18 15:49:44 +09:00
parent 9c5d80af1d
commit 3f16057a4b
2 changed files with 29 additions and 2 deletions
+10
View File
@@ -1,5 +1,6 @@
import { delimiter, dirname } from "node:path"
import { createRequire } from "node:module"
import { existsSync } from "node:fs"
type EnvLike = Record<string, string | undefined>
@@ -8,6 +9,7 @@ const resolveFromCurrentModule = createRequire(import.meta.url).resolve
export function prependResolvedOpencodeBinToPath(
env: EnvLike = process.env,
resolve: (id: string) => string = resolveFromCurrentModule,
pathExists: (path: string) => boolean = existsSync,
): void {
let resolvedPath: string
try {
@@ -16,7 +18,15 @@ export function prependResolvedOpencodeBinToPath(
return
}
if (!pathExists(resolvedPath)) {
return
}
const opencodeBinDir = dirname(resolvedPath)
if (!pathExists(opencodeBinDir)) {
return
}
const currentPath = env.PATH ?? ""
const pathSegments = currentPath ? currentPath.split(delimiter) : []