fix(windows): resolve symlinked config paths for plugin detection (fixes #2271)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { existsSync } from "node:fs"
|
||||
import { existsSync, realpathSync } from "node:fs"
|
||||
import { homedir } from "node:os"
|
||||
import { join, resolve } from "node:path"
|
||||
|
||||
@@ -42,14 +42,25 @@ function getTauriConfigDir(identifier: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
function resolveConfigPath(pathValue: string): string {
|
||||
const resolvedPath = resolve(pathValue)
|
||||
if (!existsSync(resolvedPath)) return resolvedPath
|
||||
|
||||
try {
|
||||
return realpathSync(resolvedPath)
|
||||
} catch {
|
||||
return resolvedPath
|
||||
}
|
||||
}
|
||||
|
||||
function getCliConfigDir(): string {
|
||||
const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim()
|
||||
if (envConfigDir) {
|
||||
return resolve(envConfigDir)
|
||||
return resolveConfigPath(envConfigDir)
|
||||
}
|
||||
|
||||
const xdgConfig = process.env.XDG_CONFIG_HOME || join(homedir(), ".config")
|
||||
return join(xdgConfig, "opencode")
|
||||
return resolveConfigPath(join(xdgConfig, "opencode"))
|
||||
}
|
||||
|
||||
export function getOpenCodeConfigDir(options: OpenCodeConfigDirOptions): string {
|
||||
@@ -60,7 +71,7 @@ export function getOpenCodeConfigDir(options: OpenCodeConfigDirOptions): string
|
||||
}
|
||||
|
||||
const identifier = isDevBuild(version) ? TAURI_APP_IDENTIFIER_DEV : TAURI_APP_IDENTIFIER
|
||||
const tauriDir = getTauriConfigDir(identifier)
|
||||
const tauriDir = resolveConfigPath(getTauriConfigDir(identifier))
|
||||
|
||||
if (checkExisting) {
|
||||
const legacyDir = getCliConfigDir()
|
||||
@@ -92,7 +103,7 @@ export function detectExistingConfigDir(binary: OpenCodeBinaryType, version?: st
|
||||
|
||||
const envConfigDir = process.env.OPENCODE_CONFIG_DIR?.trim()
|
||||
if (envConfigDir) {
|
||||
locations.push(resolve(envConfigDir))
|
||||
locations.push(resolveConfigPath(envConfigDir))
|
||||
}
|
||||
|
||||
if (binary === "opencode-desktop") {
|
||||
|
||||
Reference in New Issue
Block a user