From 86aacf1a1fdcaaedb31afe78f8375796a9cbe906 Mon Sep 17 00:00:00 2001 From: MiaoWoo Date: Wed, 11 May 2022 10:56:47 +0800 Subject: [PATCH] feat: optimize ioc loader Signed-off-by: MiaoWoo --- package.json | 1 - packages/plugin/package.json | 1 + packages/plugin/src/config/config.ts | 3 +++ packages/plugin/src/config/loader/index.ts | 2 ++ packages/plugin/src/index.ts | 3 ++- packages/plugin/src/loader/ioc-loader.ts | 4 ++-- 6 files changed, 10 insertions(+), 4 deletions(-) create mode 100644 packages/plugin/src/config/config.ts create mode 100644 packages/plugin/src/config/loader/index.ts diff --git a/package.json b/package.json index 7b498248..662192d7 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "packages/*" ], "devDependencies": { - "@ccms/nashorn": "file:../nashorn", "@javatypes/amqp-client": "^0.0.3", "@javatypes/bungee-api": "^0.0.3", "@javatypes/jdk": "^0.0.3", diff --git a/packages/plugin/package.json b/packages/plugin/package.json index 3bbe29ab..b7fcbe17 100644 --- a/packages/plugin/package.json +++ b/packages/plugin/package.json @@ -23,6 +23,7 @@ "@ccms/common": "file:../common", "@ccms/container": "file:../container", "@ccms/i18n": "file:../i18n", + "@ccms/verify": "file:../verify", "crypto-js": "^4.1.1", "js-yaml": "^4.1.0" } diff --git a/packages/plugin/src/config/config.ts b/packages/plugin/src/config/config.ts new file mode 100644 index 00000000..8e2e1c71 --- /dev/null +++ b/packages/plugin/src/config/config.ts @@ -0,0 +1,3 @@ +export * from "./loader" +export * from "./interfaces" +export * from "./file-config" diff --git a/packages/plugin/src/config/loader/index.ts b/packages/plugin/src/config/loader/index.ts new file mode 100644 index 00000000..22a1ecb9 --- /dev/null +++ b/packages/plugin/src/config/loader/index.ts @@ -0,0 +1,2 @@ +export * from './json-loader' +export * from './yaml-loader' diff --git a/packages/plugin/src/index.ts b/packages/plugin/src/index.ts index 8b98ca6a..6b8993d0 100644 --- a/packages/plugin/src/index.ts +++ b/packages/plugin/src/index.ts @@ -1,10 +1,11 @@ -import './scanner/ms-scanner' +import '@ccms/verify' import './scanner/js-scanner' import './loader/ioc-loader' import './loader/basic-loader' export * from './config' +export * from './config/config' export * from './manager' export * from './decorators' export * from './interfaces' diff --git a/packages/plugin/src/loader/ioc-loader.ts b/packages/plugin/src/loader/ioc-loader.ts index bb5ff234..9909bab4 100644 --- a/packages/plugin/src/loader/ioc-loader.ts +++ b/packages/plugin/src/loader/ioc-loader.ts @@ -63,13 +63,13 @@ export class IocLoader implements plugin.PluginLoader { } private bindPlugin(metadata: plugin.PluginMetadata) { - try { + if (this.container.isBoundNamed(plugin.Plugin, metadata.name)) { let pluginInstance = this.container.getNamed(plugin.Plugin, metadata.name) if (pluginInstance.description.source + '' !== metadata.source + '') { console.i18n('ms.plugin.manager.build.duplicate', { exists: pluginInstance.description.source, source: metadata.source }) } this.container.rebind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name) - } catch { + } else { this.container.bind(plugin.Plugin).to(metadata.target).inSingletonScope().whenTargetNamed(metadata.name) } }