From 61192b998a7088a8f446fd224cc242def462a79b Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Tue, 20 Jan 2026 11:52:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=8F=92=E4=BB=B6?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8D=E5=AD=97=E5=92=8C=E5=88=A0=E9=99=A4?= =?UTF-8?q?=E5=90=8E=E6=B2=A1=E6=9C=89=E6=B3=A8=E9=94=80=E6=B3=A8=E5=86=8C?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/pipeline/src/plugin/registry.ts | 13 ++++++++++++- packages/core/pipeline/src/registry/registry.ts | 15 ++++++++++++--- .../src/modules/plugin/service/plugin-service.ts | 7 ++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/core/pipeline/src/plugin/registry.ts b/packages/core/pipeline/src/plugin/registry.ts index b2fcac603..2fbcd239c 100644 --- a/packages/core/pipeline/src/plugin/registry.ts +++ b/packages/core/pipeline/src/plugin/registry.ts @@ -22,4 +22,15 @@ const onRegister = ({ key, value }: OnRegisterContext) => { } pluginGroups.other.plugins.push(value.define); }; -export const pluginRegistry = createRegistry("plugin", onRegister); + +const onUnRegister = ({ key }: OnRegisterContext) => { + for (const group of Object.values(pluginGroups)) { + const index = group.plugins.findIndex(plugin => plugin.name === key); + if (index > -1) { + group.plugins.splice(index, 1); + return; + } + } +}; + +export const pluginRegistry = createRegistry("plugin", onRegister, onUnRegister); diff --git a/packages/core/pipeline/src/registry/registry.ts b/packages/core/pipeline/src/registry/registry.ts index 3322d7080..cdd1ff92c 100644 --- a/packages/core/pipeline/src/registry/registry.ts +++ b/packages/core/pipeline/src/registry/registry.ts @@ -27,10 +27,12 @@ export class Registry { } = {}; onRegister?: OnRegister; + onUnRegister?: OnRegister; - constructor(type: string, onRegister?: OnRegister) { + constructor(type: string, onRegister?: OnRegister, onUnRegister?: OnRegister) { this.type = type; this.onRegister = onRegister; + this.onUnRegister = onUnRegister; } register(key: string, value: RegistryItem) { @@ -49,6 +51,13 @@ export class Registry { } unRegister(key: string) { + if (this.onUnRegister) { + this.onUnRegister({ + registry: this, + key, + value: this.storage[key], + }); + } delete this.storage[key]; logger.info(`反注册插件:${this.type}:${key}`); } @@ -108,7 +117,7 @@ export class Registry { } } -export function createRegistry(type: string, onRegister?: OnRegister): Registry { +export function createRegistry(type: string, onRegister?: OnRegister, onUnRegister?: OnRegister): Registry { const pipelineregistrycacheKey = "PIPELINE_REGISTRY_CACHE"; // @ts-ignore let cached: any = global[pipelineregistrycacheKey]; @@ -121,7 +130,7 @@ export function createRegistry(type: string, onRegister?: OnRegister): Reg if (cached[type]) { return cached[type]; } - const newRegistry = new Registry(type, onRegister); + const newRegistry = new Registry(type, onRegister, onUnRegister); cached[type] = newRegistry; return newRegistry; } diff --git a/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts b/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts index 9bfb5953e..3c453e959 100644 --- a/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts +++ b/packages/ui/certd-server/src/modules/plugin/service/plugin-service.ts @@ -305,7 +305,7 @@ export class PluginService extends BaseService { throw new Error(`插件${param.author}/${param.name}已存在`); } - + await this.unRegisterById(param.id); const res = await super.update(param); await this.registerById(param.id); @@ -413,7 +413,7 @@ export class PluginService extends BaseService { delete item.metadata; delete item.content; delete item.extra; - if (item.author) { + if (item.author && !item.name.startsWith(`${item.author}/`)) { item.name = item.author + "/" + item.name; } let name = item.name @@ -527,10 +527,11 @@ export class PluginService extends BaseService { async deleteByIds(ids: any[]) { - await super.delete(ids); for (const id of ids) { await this.unRegisterById(id) + await this.delete(id); } + }