refactor(cli): dispose bootstrap instance explicitly (#27721)

This commit is contained in:
Shoubhit Dash
2026-05-15 16:30:54 +05:30
committed by GitHub
parent 727a83aa7a
commit bf64f8cbb5
2 changed files with 31 additions and 14 deletions

View File

@@ -1,17 +1,11 @@
import { Instance } from "../project/instance"
import { InstanceRuntime } from "../project/instance-runtime"
import { WithInstance } from "../project/with-instance"
import { context } from "../project/instance-context"
export async function bootstrap<T>(directory: string, cb: () => Promise<T>) {
return WithInstance.provide({
directory,
fn: async () => {
try {
const result = await cb()
return result
} finally {
await InstanceRuntime.disposeInstance(Instance.current)
}
},
})
const ctx = await InstanceRuntime.load({ directory })
try {
return await context.provide(ctx, cb)
} finally {
await InstanceRuntime.disposeInstance(ctx)
}
}