83c024dd66
getConfigContext() emitted a console.warn when called before initConfigContext() completed. Since initConfigContext runs async (spawns opencode --version subprocess), other modules calling getConfigDir/getConfigJson could trigger this warning during startup. The fallback behavior is intentional and safe (defaults to standard CLI paths), but console.warn writes to stderr which the TUI captures, causing the warning to render inside the user's textbox. Fixes #2183
47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
import { getOpenCodeConfigPaths } from "../../shared"
|
|
import type {
|
|
OpenCodeBinaryType,
|
|
OpenCodeConfigPaths,
|
|
} from "../../shared/opencode-config-dir-types"
|
|
|
|
export interface ConfigContext {
|
|
binary: OpenCodeBinaryType
|
|
version: string | null
|
|
paths: OpenCodeConfigPaths
|
|
}
|
|
|
|
let configContext: ConfigContext | null = null
|
|
|
|
export function initConfigContext(binary: OpenCodeBinaryType, version: string | null): void {
|
|
const paths = getOpenCodeConfigPaths({ binary, version })
|
|
configContext = { binary, version, paths }
|
|
}
|
|
|
|
export function getConfigContext(): ConfigContext {
|
|
if (!configContext) {
|
|
const paths = getOpenCodeConfigPaths({ binary: "opencode", version: null })
|
|
configContext = { binary: "opencode", version: null, paths }
|
|
}
|
|
return configContext
|
|
}
|
|
|
|
export function resetConfigContext(): void {
|
|
configContext = null
|
|
}
|
|
|
|
export function getConfigDir(): string {
|
|
return getConfigContext().paths.configDir
|
|
}
|
|
|
|
export function getConfigJson(): string {
|
|
return getConfigContext().paths.configJson
|
|
}
|
|
|
|
export function getConfigJsonc(): string {
|
|
return getConfigContext().paths.configJsonc
|
|
}
|
|
|
|
export function getOmoConfigPath(): string {
|
|
return getConfigContext().paths.omoConfig
|
|
}
|