chore: cleanup
This commit is contained in:
@@ -1104,20 +1104,23 @@ export namespace Config {
|
|||||||
mergeDeep(await loadFile(path.join(Global.Path.config, "opencode.jsonc"))),
|
mergeDeep(await loadFile(path.join(Global.Path.config, "opencode.jsonc"))),
|
||||||
)
|
)
|
||||||
|
|
||||||
await import(path.join(Global.Path.config, "config"), {
|
const legacy = path.join(Global.Path.config, "config")
|
||||||
with: {
|
if (existsSync(legacy)) {
|
||||||
type: "toml",
|
await import(pathToFileURL(legacy).href, {
|
||||||
},
|
with: {
|
||||||
})
|
type: "toml",
|
||||||
.then(async (mod) => {
|
},
|
||||||
const { provider, model, ...rest } = mod.default
|
|
||||||
if (provider && model) result.model = `${provider}/${model}`
|
|
||||||
result["$schema"] = "https://opencode.ai/config.json"
|
|
||||||
result = mergeDeep(result, rest)
|
|
||||||
await Bun.write(path.join(Global.Path.config, "config.json"), JSON.stringify(result, null, 2))
|
|
||||||
await fs.unlink(path.join(Global.Path.config, "config"))
|
|
||||||
})
|
})
|
||||||
.catch(() => {})
|
.then(async (mod) => {
|
||||||
|
const { provider, model, ...rest } = mod.default
|
||||||
|
if (provider && model) result.model = `${provider}/${model}`
|
||||||
|
result["$schema"] = "https://opencode.ai/config.json"
|
||||||
|
result = mergeDeep(result, rest)
|
||||||
|
await Bun.write(path.join(Global.Path.config, "config.json"), JSON.stringify(result, null, 2))
|
||||||
|
await fs.unlink(legacy)
|
||||||
|
})
|
||||||
|
.catch(() => {})
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -17,6 +17,10 @@ const cache = new Map<string, Promise<Context>>()
|
|||||||
|
|
||||||
const DISPOSE_TIMEOUT_MS = 10_000
|
const DISPOSE_TIMEOUT_MS = 10_000
|
||||||
|
|
||||||
|
const disposal = {
|
||||||
|
all: undefined as Promise<void> | undefined,
|
||||||
|
}
|
||||||
|
|
||||||
export const Instance = {
|
export const Instance = {
|
||||||
async provide<R>(input: { directory: string; init?: () => Promise<any>; fn: () => R }): Promise<R> {
|
async provide<R>(input: { directory: string; init?: () => Promise<any>; fn: () => R }): Promise<R> {
|
||||||
let existing = cache.get(input.directory)
|
let existing = cache.get(input.directory)
|
||||||
@@ -80,20 +84,34 @@ export const Instance = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
async disposeAll() {
|
async disposeAll() {
|
||||||
Log.Default.info("disposing all instances")
|
if (disposal.all) return disposal.all
|
||||||
for (const [key, value] of cache) {
|
|
||||||
const ctx = await withTimeout(value, DISPOSE_TIMEOUT_MS).catch((error) => {
|
disposal.all = iife(async () => {
|
||||||
Log.Default.warn("instance dispose timed out", { key, error })
|
Log.Default.info("disposing all instances")
|
||||||
return undefined
|
const entries = [...cache.entries()]
|
||||||
})
|
for (const [key, value] of entries) {
|
||||||
if (!ctx) {
|
if (cache.get(key) !== value) continue
|
||||||
cache.delete(key)
|
|
||||||
continue
|
const ctx = await withTimeout(value, DISPOSE_TIMEOUT_MS).catch((error) => {
|
||||||
|
Log.Default.warn("instance dispose timed out", { key, error })
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
|
||||||
|
if (!ctx) {
|
||||||
|
if (cache.get(key) === value) cache.delete(key)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cache.get(key) !== value) continue
|
||||||
|
|
||||||
|
await context.provide(ctx, async () => {
|
||||||
|
await Instance.dispose()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
await context.provide(ctx, async () => {
|
}).finally(() => {
|
||||||
await Instance.dispose()
|
disposal.all = undefined
|
||||||
})
|
})
|
||||||
}
|
|
||||||
cache.clear()
|
return disposal.all
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,9 +66,11 @@ export namespace State {
|
|||||||
|
|
||||||
tasks.push(task)
|
tasks.push(task)
|
||||||
}
|
}
|
||||||
|
await Promise.all(tasks)
|
||||||
|
|
||||||
entries.clear()
|
entries.clear()
|
||||||
recordsByKey.delete(key)
|
recordsByKey.delete(key)
|
||||||
await Promise.all(tasks)
|
|
||||||
disposalFinished = true
|
disposalFinished = true
|
||||||
log.info("state disposal completed", { key })
|
log.info("state disposal completed", { key })
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user