mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
fix: load plugins in dependency order (#5706)
* fix: load plugins in dependency order * fix: missing package name
This commit is contained in:
parent
575460e3e9
commit
ed98cfa394
@ -7,8 +7,9 @@
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import Topo from '@hapi/topo';
|
||||
import { Repository } from '@nocobase/database';
|
||||
import lodash from 'lodash';
|
||||
import { default as _, default as lodash } from 'lodash';
|
||||
import { PluginManager } from './plugin-manager';
|
||||
|
||||
export class PluginManagerRepository extends Repository {
|
||||
@ -110,14 +111,42 @@ export class PluginManagerRepository extends Repository {
|
||||
return pluginNames;
|
||||
}
|
||||
|
||||
async sort(names: string[]) {
|
||||
const pluginNames = _.castArray(names);
|
||||
if (pluginNames.length === 1) {
|
||||
return pluginNames;
|
||||
}
|
||||
const sorter = new Topo.Sorter<string>();
|
||||
for (const pluginName of pluginNames) {
|
||||
const packageJson = await PluginManager.getPackageJson(pluginName);
|
||||
const peerDependencies = Object.keys(packageJson?.peerDependencies || {});
|
||||
sorter.add(pluginName, { after: peerDependencies, group: packageJson?.packageName || pluginName });
|
||||
}
|
||||
return sorter.nodes;
|
||||
}
|
||||
|
||||
async getItems() {
|
||||
const exists = await this.collection.existsInDb();
|
||||
if (!exists) {
|
||||
return [];
|
||||
}
|
||||
return await this.find({
|
||||
const items = await this.find({
|
||||
sort: 'id',
|
||||
});
|
||||
const sortedItems = [];
|
||||
const map = {};
|
||||
for (const item of items) {
|
||||
if (item.packageName) {
|
||||
map[item.packageName] = item;
|
||||
} else {
|
||||
sortedItems.push(item);
|
||||
}
|
||||
}
|
||||
const names = await this.sort(Object.keys(map));
|
||||
for (const name of names) {
|
||||
sortedItems.push(map[name]);
|
||||
}
|
||||
return sortedItems;
|
||||
}
|
||||
|
||||
async init() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user