mirror of
https://github.com/sst/opencode.git
synced 2025-12-23 10:11:41 +00:00
fix duplicate plugin subscriptions
This commit is contained in:
parent
8b70b89fde
commit
894cbaa51e
1 changed files with 6 additions and 2 deletions
|
|
@ -12,7 +12,11 @@ const context = Context.create<Context>("instance")
|
|||
const cache = new Map<string, Context>()
|
||||
|
||||
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)
|
||||
if (!existing) {
|
||||
const project = await Project.fromDirectory(input.directory)
|
||||
|
|
@ -24,8 +28,8 @@ export const Instance = {
|
|||
}
|
||||
return context.provide(existing, async () => {
|
||||
if (!cache.has(input.directory)) {
|
||||
await input.init?.()
|
||||
cache.set(input.directory, existing)
|
||||
await input.init?.()
|
||||
}
|
||||
return input.fn()
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue