From e62d383bf16198d4edab523b0cf913bacc74583a Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 26 Oct 2023 11:01:45 +0800 Subject: [PATCH] fix: removed plugins, no longer added when upgrading (#2917) --- packages/core/server/src/plugin.ts | 4 +- packages/presets/nocobase/src/server/index.ts | 58 +++++++++++++------ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/packages/core/server/src/plugin.ts b/packages/core/server/src/plugin.ts index 9eb472036..5cfbf2ca1 100644 --- a/packages/core/server/src/plugin.ts +++ b/packages/core/server/src/plugin.ts @@ -110,7 +110,7 @@ export abstract class Plugin implements PluginInterface { async toJSON(options: any = {}) { const { locale = 'en-US' } = options; - const { packageName, packageJson } = this.options; + const { name, packageName, packageJson } = this.options; if (!packageName) { return { ...this.options, @@ -127,7 +127,7 @@ export abstract class Plugin implements PluginInterface { lastUpdated, file, updatable: file.startsWith(process.env.PLUGIN_STORAGE_PATH), - displayName: packageJson[`displayName.${locale}`] || packageJson.displayName, + displayName: packageJson[`displayName.${locale}`] || packageJson.displayName || name, description: packageJson[`description.${locale}`] || packageJson.description, }; } diff --git a/packages/presets/nocobase/src/server/index.ts b/packages/presets/nocobase/src/server/index.ts index cd48e0952..05e31bdf6 100644 --- a/packages/presets/nocobase/src/server/index.ts +++ b/packages/presets/nocobase/src/server/index.ts @@ -31,21 +31,21 @@ export class PresetNocoBase extends Plugin { ]; localPlugins = [ - 'audit-logs', - 'sample-hello', - 'multi-app-manager', - 'multi-app-share-collection', - 'oidc', - 'saml', - 'cas', - 'map', - 'snapshot-field', - 'graph-collection-manager', - 'mobile-client', - 'api-keys', - 'localization-management', - 'theme-editor', - 'api-doc', + ['audit-logs', '0.7.1-alpha.4'], + ['sample-hello', '0.8.0-alpha.4'], + ['multi-app-manager', '0.7.0-alpha.1'], + ['multi-app-share-collection', '0.9.2-alpha.1'], + ['oidc', '0.9.2-alpha.1'], + ['saml', '0.8.1-alpha.3'], + ['cas', '0.13.0-alpha.5'], + ['map', '0.8.1-alpha.3'], + ['snapshot-field', '0.8.1-alpha.3'], + ['graph-collection-manager', '0.9.0-alpha.1'], + ['mobile-client', '0.10.0-alpha.2'], + ['api-keys', '0.10.1-alpha.1'], + ['localization-management', '0.11.1-alpha.1'], + ['theme-editor', '0.11.1-alpha.1'], + ['api-doc', '0.13.0-alpha.1'], ]; splitNames(name: string) { @@ -61,7 +61,7 @@ export class PresetNocoBase extends Plugin { getLocalPlugins() { const { APPEND_PRESET_LOCAL_PLUGINS } = process.env; - return _.uniq(this.splitNames(APPEND_PRESET_LOCAL_PLUGINS).concat(this.localPlugins)); + return _.uniq(this.splitNames(APPEND_PRESET_LOCAL_PLUGINS).concat(this.localPlugins as any)); } beforeLoad() { @@ -85,7 +85,8 @@ export class PresetNocoBase extends Plugin { return { name, packageName, enabled: true, builtIn: true, version: packageJson.version } as any; }) .concat( - this.getLocalPlugins().map((name) => { + this.getLocalPlugins().map((plugin) => { + const name = typeof plugin === 'string' ? plugin : plugin[0]; const packageName = PluginManager.getPackageName(name); const packageJson = PluginManager.getPackageJson(packageName); return { name, packageName, version: packageJson.version }; @@ -93,11 +94,32 @@ export class PresetNocoBase extends Plugin { ); } + async getPluginToBeUpgraded() { + const plugins = this.getBuiltInPlugins().map((name) => { + const packageName = PluginManager.getPackageName(name); + const packageJson = PluginManager.getPackageJson(packageName); + return { name, packageName, enabled: true, builtIn: true, version: packageJson.version } as any; + }); + for (const plugin of this.getLocalPlugins()) { + if (Array.isArray(plugin)) { + if (await this.app.version.satisfies(`>${plugin[1]}`)) { + continue; + } + const name = plugin[0]; + const packageName = PluginManager.getPackageName(name); + const packageJson = PluginManager.getPackageJson(packageName); + plugins.push({ name, packageName, version: packageJson.version }); + } + } + return plugins; + } + async updateOrCreatePlugins() { const repository = this.app.db.getRepository('applicationPlugins'); + const plugins = await this.getPluginToBeUpgraded(); await this.db.sequelize.transaction((transaction) => { return Promise.all( - this.allPlugins.map((values) => + plugins.map((values) => repository.updateOrCreate({ transaction, values,