refactor: convert config path constants to getter functions for dynamic OPENCODE_CONFIG_DIR support
🤖 Generated with assistance of OhMyOpenCode
This commit is contained in:
@@ -94,6 +94,26 @@ describe("loadPluginExtendedConfig", () => {
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test("#given OPENCODE_CONFIG_DIR points at a profile dir after module import #when loading extended config #then it reads the profile config file", async () => {
|
||||
//#given
|
||||
const profileConfigDir = join(tempDirectory, ".config", "opencode", "profiles", "today")
|
||||
const profileConfigPath = join(profileConfigDir, "opencode-cc-plugin.json")
|
||||
mkdirSync(profileConfigDir, { recursive: true })
|
||||
process.env.OPENCODE_CONFIG_DIR = profileConfigDir
|
||||
writeConfigFile(profileConfigPath, ["profile-stop"])
|
||||
|
||||
//#when
|
||||
clearPluginExtendedConfigCache()
|
||||
const result = await loadPluginExtendedConfig()
|
||||
|
||||
//#then
|
||||
expect(result).toEqual({
|
||||
disabledHooks: {
|
||||
Stop: ["profile-stop"],
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
function writeConfigFile(filePath: string, stopPatterns: string[]): void {
|
||||
|
||||
@@ -23,15 +23,18 @@ interface PluginExtendedConfigCacheEntry {
|
||||
cachedAt: number
|
||||
}
|
||||
|
||||
const USER_CONFIG_PATH = join(getOpenCodeConfigDir({ binary: "opencode" }), "opencode-cc-plugin.json")
|
||||
const configCache = new Map<string, PluginExtendedConfigCacheEntry>()
|
||||
|
||||
function getUserConfigPath(): string {
|
||||
return join(getOpenCodeConfigDir({ binary: "opencode" }), "opencode-cc-plugin.json")
|
||||
}
|
||||
|
||||
function getProjectConfigPath(): string {
|
||||
return join(process.cwd(), ".opencode", "opencode-cc-plugin.json")
|
||||
}
|
||||
|
||||
function getCacheKey(): string {
|
||||
return process.cwd()
|
||||
return `${process.cwd()}::${getUserConfigPath()}`
|
||||
}
|
||||
|
||||
function getCachedConfig(cacheKey: string): PluginExtendedConfig | undefined {
|
||||
@@ -89,7 +92,7 @@ export async function loadPluginExtendedConfig(): Promise<PluginExtendedConfig>
|
||||
return cachedConfig
|
||||
}
|
||||
|
||||
const userConfig = await loadConfigFromPath(USER_CONFIG_PATH)
|
||||
const userConfig = await loadConfigFromPath(getUserConfigPath())
|
||||
const projectConfig = await loadConfigFromPath(getProjectConfigPath())
|
||||
|
||||
const merged: PluginExtendedConfig = {
|
||||
|
||||
Reference in New Issue
Block a user