fix(cli-run): skip unresolved opencode bin path injection
This commit is contained in:
@@ -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) : []
|
||||
|
||||
|
||||
Reference in New Issue
Block a user