fix(lib/plugins): only run dependencies in runPluginLate

This commit is contained in:
PalmDevs 2025-07-26 01:58:17 +07:00
parent 7b4d566e4d
commit b40e2f51ab
No known key found for this signature in database
GPG key ID: 6FAE8F8677ACA8BA
2 changed files with 21 additions and 7 deletions

View file

@ -15,7 +15,7 @@ export const pRootNodes = new Set<AnyPlugin>()
export const pLeafOrSingleNodes = new Set<AnyPlugin>()
// Visited non-leaf nodes
const visited = new WeakSet<AnyPlugin>()
const visited = new Set<AnyPlugin>()
// Ordered list of plugins to be started
export const pListOrdered: AnyPlugin[] = []
@ -48,6 +48,7 @@ export function computePendingNodes() {
pPending.clear()
pLeafOrSingleNodes.clear()
pRootNodes.clear()
visited.clear()
}
export function resolvePluginGraph(plugin: AnyPlugin) {

View file

@ -11,7 +11,12 @@ import {
pDecoratorsStart,
pImplicitDeps,
} from './decorators'
import { pLeafOrSingleNodes, pPending } from './dependency-graph'
import {
computePendingNodes,
pLeafOrSingleNodes,
pListOrdered,
pPending,
} from './dependency-graph'
import type {
InitPluginApi,
Plugin,
@ -299,8 +304,7 @@ export async function enablePlugin(plugin: AnyPlugin) {
await Promise.all(
getPluginDependencies(plugin).map(dep => {
if (dep.flags & Flag.Enabled) return
return runPluginLate(dep)
if (!isPluginEnabled(dep)) return enablePlugin(dep)
}),
)
@ -318,9 +322,18 @@ export async function runPluginLate(plugin: AnyPlugin) {
plugin.flags |= Flag.EnabledLate
await preInitPlugin(plugin)
await initPlugin(plugin)
await startPlugin(plugin)
// Reset previous computations
pListOrdered.length = 0
pPending.add(plugin)
computePendingNodes()
await Promise.all(
pListOrdered.map(async function runLate(plugin) {
await preInitPlugin(plugin)
await initPlugin(plugin)
await startPlugin(plugin)
}),
)
}
/**