fix: remove PluginManager.getPackageName

This commit is contained in:
chenos 2023-09-13 14:40:43 +08:00
parent 49e1641b58
commit de8fc8079a
3 changed files with 13 additions and 30 deletions

View File

@ -1,7 +1,6 @@
import { Cache, createCache } from '@nocobase/cache';
import { lodash } from '@nocobase/utils';
import Application from '../application';
import { PluginManager } from '../plugin-manager';
import { getResource } from './resource';
export class Locale {
@ -67,7 +66,14 @@ export class Locale {
const names = this.app.pm.getAliases();
for (const name of names) {
try {
const packageName = PluginManager.getPackageName(name);
const p = this.app.pm.get(name);
if (!p) {
continue;
}
const packageName = p.options?.packageName;
if (!packageName) {
continue;
}
// this.app.log.debug(`load [${packageName}] locale resource `);
// this.app.setMaintainingMessage(`load [${packageName}] locale resource `);
const res = getResource(packageName, lang);

View File

@ -1,4 +1,3 @@
import { PluginManager } from '@nocobase/server';
import { requireModule } from '@nocobase/utils';
import { merge } from './merge';
@ -30,7 +29,10 @@ export const getPluginsSwagger = async (db: any, pluginNames?: string[]) => {
});
const swaggers = {};
for (const plugin of plugins) {
const packageName = PluginManager.getPackageName(plugin.get('name'));
const packageName = plugin.get('packageName');
if (!packageName) {
continue;
}
const res = loadSwagger(packageName);
if (Object.keys(res).length) {
swaggers[plugin.get('name')] = res;

View File

@ -1,4 +1,4 @@
import { Plugin, PluginManager, getExposeUrl } from '@nocobase/server';
import { Plugin } from '@nocobase/server';
import fs from 'fs';
import { resolve } from 'path';
import { getAntdLocale } from './antd';
@ -69,7 +69,6 @@ export class ClientPlugin extends Plugin {
});
this.app.acl.allow('app', 'getLang');
this.app.acl.allow('app', 'getInfo');
this.app.acl.allow('app', 'getPlugins');
this.app.acl.allow('plugins', '*', 'public');
this.app.acl.registerSnippet({
name: 'app',
@ -115,30 +114,6 @@ export class ClientPlugin extends Plugin {
};
await next();
},
async getPlugins(ctx, next) {
const pm = ctx.db.getRepository('applicationPlugins');
const PLUGIN_CLIENT_ENTRY_FILE = 'dist/client/index.js';
const items = await pm.find({
filter: {
enabled: true,
},
});
ctx.body = items
.map((item) => {
try {
const packageName = PluginManager.getPackageName(item.name);
return {
...item.toJSON(),
packageName,
url: getExposeUrl(packageName, PLUGIN_CLIENT_ENTRY_FILE),
};
} catch {
return false;
}
})
.filter(Boolean);
await next();
},
async clearCache(ctx, next) {
await ctx.cache.reset();
await next();