fix: plugin sort

This commit is contained in:
chenos 2025-06-19 14:58:44 +08:00 committed by GitHub
parent 0cbcd03390
commit af42e47771
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1141,7 +1141,21 @@ export class PluginManager {
if (this['_initPresetPlugins']) {
return;
}
const sorter = new Topo.Sorter<string>();
for (const plugin of this.options.plugins) {
if (typeof plugin === 'string') {
try {
const packageJson = await PluginManager.getPackageJson(plugin);
const peerDependencies = Object.keys(packageJson.peerDependencies || {});
sorter.add(plugin, { after: peerDependencies, group: packageJson.packageName });
} catch (error) {
sorter.add(plugin);
}
} else {
sorter.add(plugin);
}
}
for (const plugin of sorter.nodes) {
const [p, opts = {}] = Array.isArray(plugin) ? plugin : [plugin];
await this.add(p, { enabled: true, isPreset: true, ...opts });
}