fix: remote plugin name (#2872)

This commit is contained in:
jack zhang 2023-10-19 19:17:58 +08:00 committed by GitHub
parent cc676c3dda
commit 07c5b7b0eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 21 deletions

View File

@ -47,8 +47,8 @@ export class PluginManager {
pluginData: pluginList,
devDynamicImport: this.app.devDynamicImport,
});
for await (const plugin of plugins) {
await this.add(plugin);
for await (const [name, pluginClass] of plugins) {
await this.add(pluginClass, { name });
}
} catch (error) {
if (401 === error?.response?.status) {

View File

@ -27,7 +27,10 @@ export function definePluginClient(packageName: string) {
});
}
export function getRemotePlugins(requirejs: any, pluginData: PluginData[] = []): Promise<Array<typeof Plugin>> {
export function getRemotePlugins(
requirejs: any,
pluginData: PluginData[] = [],
): Promise<Array<[string, typeof Plugin]>> {
requirejs.requirejs.config({
waitSeconds: 120,
paths: pluginData.reduce<Record<string, string>>((acc, cur) => {
@ -43,10 +46,13 @@ export function getRemotePlugins(requirejs: any, pluginData: PluginData[] = []):
return new Promise((resolve, reject) => {
requirejs.requirejs(
packageNames,
(...plugins: (typeof Plugin & { default?: typeof Plugin })[]) => {
const res = plugins.filter((item) => item).map((item) => item.default || item);
(...pluginModules: (typeof Plugin & { default?: typeof Plugin })[]) => {
const res = pluginModules
.map<[string, typeof Plugin]>((item, index) => [pluginData[index].name, item.default || item])
.filter((item) => item[1]);
resolve(res);
const emptyPlugins = plugins
const emptyPlugins = pluginModules
.map((item, index) => (!item ? index : null))
.filter((i) => i !== null)
.map((i) => pluginData[i].packageName);
@ -69,36 +75,37 @@ interface GetPluginsOption {
devDynamicImport?: DevDynamicImport;
}
export async function getPlugins(options: GetPluginsOption): Promise<Array<typeof Plugin>> {
export async function getPlugins(options: GetPluginsOption): Promise<Array<[string, typeof Plugin]>> {
const { requirejs, pluginData, devDynamicImport } = options;
if (pluginData.length === 0) return [];
if (process.env.NODE_ENV === 'development' && !process.env.USE_REMOTE_PLUGIN) {
const plugins: Array<typeof Plugin> = [];
const res: Array<[string, typeof Plugin]> = [];
const resolveDevPlugins: Record<string, typeof Plugin> = {};
const pluginPackageNames = pluginData.map((item) => item.packageName);
if (devDynamicImport) {
for await (const packageName of pluginPackageNames) {
const plugin = await devDynamicImport(packageName);
if (plugin) {
plugins.push(plugin.default);
resolveDevPlugins[packageName] = plugin.default;
for await (const plugin of pluginData) {
const pluginModule = await devDynamicImport(plugin.packageName);
if (pluginModule) {
res.push([plugin.name, pluginModule.default]);
resolveDevPlugins[plugin.name] = pluginModule.default;
} else {
console.error(`[nocobase]: plugin ${plugin.packageName} load error`);
}
}
defineDevPlugins(resolveDevPlugins);
}
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.packageName]);
const remotePlugins = pluginData.filter((item) => !resolveDevPlugins[item.name]);
if (remotePlugins.length === 0) {
return plugins;
return res;
}
const remotePluginList = await getRemotePlugins(requirejs, remotePlugins);
plugins.push(...remotePluginList);
return plugins;
res.push(...remotePluginList);
return res;
}
return getRemotePlugins(requirejs, pluginData);

View File

@ -250,7 +250,7 @@ export class NocoBaseBuildInPlugin extends Plugin {
});
}
async addPlugins() {
await this.app.pm.add(LocalePlugin, { name: 'locale' });
await this.app.pm.add(LocalePlugin, { name: 'builtin-locale' });
await this.app.pm.add(AdminLayoutPlugin, { name: 'admin-layout' });
await this.app.pm.add(SystemSettingsPlugin, { name: 'system-setting' });
await this.app.pm.add(PinnedListPlugin, {
@ -275,8 +275,8 @@ export class NocoBaseBuildInPlugin extends Plugin {
await this.app.pm.add(BlockSchemaComponentPlugin, { name: 'block-schema-component' });
await this.app.pm.add(AntdSchemaComponentPlugin, { name: 'antd-schema-component' });
await this.app.pm.add(SigninPageExtensionPlugin, { name: 'signin-page-extension' });
await this.app.pm.add(ACLPlugin, { name: 'acl' });
await this.app.pm.add(ACLPlugin, { name: 'builtin-acl' });
await this.app.pm.add(RemoteDocumentTitlePlugin, { name: 'remote-document-title' });
await this.app.pm.add(PMPlugin, { name: 'pm' });
await this.app.pm.add(PMPlugin, { name: 'builtin-pm' });
}
}