load file plugins immediately

actual-tui-plugins
Sebastian Herrlinger 2026-03-05 09:32:48 +01:00
parent 66ac0b3394
commit 8a7d0875d8
1 changed files with 30 additions and 7 deletions

View File

@ -112,22 +112,32 @@ export namespace TuiPlugin {
fn: async () => {
const config = await TuiConfig.get()
const plugins = config.plugin ?? []
if (plugins.length) await TuiConfig.waitForDependencies()
let deps: Promise<void> | undefined
const wait = async () => {
if (deps) {
await deps
return
}
deps = TuiConfig.waitForDependencies().catch((error) => {
log.warn("failed waiting for tui plugin dependencies", { error })
})
await deps
}
for (const item of plugins) {
const loadOne = async (item: (typeof plugins)[number], retry = false) => {
const spec = Config.pluginSpecifier(item)
log.info("loading tui plugin", { path: spec })
log.info("loading tui plugin", { path: spec, retry })
const target = await resolvePluginTarget(spec).catch((error) => {
log.error("failed to resolve tui plugin", { path: spec, error })
log.error("failed to resolve tui plugin", { path: spec, retry, error })
return
})
if (!target) continue
if (!target) return false
const mod = await import(target).catch((error) => {
log.error("failed to load tui plugin", { path: spec, error })
log.error("failed to load tui plugin", { path: spec, retry, error })
return
})
if (!mod) continue
if (!mod) return false
for (const [name, entry] of uniqueModuleEntries(mod)) {
if (!entry || typeof entry !== "object") {
@ -149,6 +159,19 @@ export namespace TuiPlugin {
if (!tuiPlugin) continue
await tuiPlugin(input, Config.pluginOptions(item))
}
return true
}
for (const item of plugins) {
const ok = await loadOne(item)
if (ok) continue
const spec = Config.pluginSpecifier(item)
if (!spec.startsWith("file://")) continue
await wait()
await loadOne(item, true)
}
},
}).catch((error) => {