Repository: artusjs/core
Pull request #38 (2022-04-21 10:38:33)

fix(plugin): disabled plugin need be removed from sorted-list


Patch:
diff --git a/src/plugin/factory.ts b/src/plugin/factory.ts
index 57e1ec5..cf1229a 100644
--- a/src/plugin/factory.ts
+++ b/src/plugin/factory.ts
@@ -14,7 +14,9 @@ export class PluginFactory {
     const pluginInstanceMap: Map<string, BasePlugin> = new Map();
     for (const [name, item] of Object.entries(config)) {
       const pluginInstance = await PluginFactory.create(name, item);
-      pluginInstanceMap.set(name, pluginInstance);
+      if (pluginInstance.enable) {
+        pluginInstanceMap.set(name, pluginInstance);
+      }
     }
     let pluginDepEdgeList: [string, string][] = [];
     // Topological sort plugins
diff --git a/src/plugin/impl.ts b/src/plugin/impl.ts
index cf6e9e4..0648430 100644
--- a/src/plugin/impl.ts
+++ b/src/plugin/impl.ts
@@ -4,9 +4,6 @@ import { loadMetaFile } from '../utils/load-meta-file';
 
 export class ArtusPlugin extends BasePlugin {
   async init() {
-    if (!this.enable) {
-      return;
-    }
     await this.checkAndLoadMetadata();
     if (!this.metadata) {
       throw new Error(`${this.name} is not have metadata.`);


Test patch:
diff --git a/test/fixtures/app-koa-with-ts/src/config/plugin.default.ts b/test/fixtures/app-koa-with-ts/src/config/plugin.default.ts
index 922124c..d69d2bf 100644
--- a/test/fixtures/app-koa-with-ts/src/config/plugin.default.ts
+++ b/test/fixtures/app-koa-with-ts/src/config/plugin.default.ts
@@ -5,4 +5,8 @@ export default {
     enable: true,
     path: path.resolve(__dirname, '../redis-plugin')
   },
+  mysql: {
+    enable: false,
+    path: path.resolve(__dirname, '../mysql-plugin')
+  },
 };
diff --git a/test/fixtures/app-koa-with-ts/src/mysql-plugin/app.ts b/test/fixtures/app-koa-with-ts/src/mysql-plugin/app.ts
new file mode 100644
index 0000000..aeed69d
--- /dev/null
+++ b/test/fixtures/app-koa-with-ts/src/mysql-plugin/app.ts
@@ -0,0 +1,9 @@
+import { ApplicationExtension, ApplicationHook } from '../../../../../src/decorator';
+
+@ApplicationExtension()
+export default class Hook {
+  @ApplicationHook()
+  async willReady() {
+    console.log('MySQL Plugin will ready');
+  }
+}
diff --git a/test/fixtures/app-koa-with-ts/src/mysql-plugin/meta.yaml b/test/fixtures/app-koa-with-ts/src/mysql-plugin/meta.yaml
new file mode 100644
index 0000000..2fff827
--- /dev/null
+++ b/test/fixtures/app-koa-with-ts/src/mysql-plugin/meta.yaml
@@ -0,0 +1,1 @@
+name: mysql
diff --git a/test/fixtures/app-koa-with-ts/src/redis-plugin/app.ts b/test/fixtures/app-koa-with-ts/src/redis-plugin/app.ts
index 6215eb8..602a522 100644
--- a/test/fixtures/app-koa-with-ts/src/redis-plugin/app.ts
+++ b/test/fixtures/app-koa-with-ts/src/redis-plugin/app.ts
@@ -1,6 +1,9 @@
+import { ApplicationExtension, ApplicationHook } from '../../../../../src/decorator';
 
-
+@ApplicationExtension()
 export default class Hook {
-    async willReady() {
-    }
-}
\ No newline at end of file
+  @ApplicationHook()
+  async willReady() {
+    console.log('Redis Plugin will ready');
+  }
+}
diff --git a/test/scanner.test.ts b/test/scanner.test.ts
index 8f6bbac..598de23 100644
--- a/test/scanner.test.ts
+++ b/test/scanner.test.ts
@@ -18,6 +18,7 @@ describe('test/scanner.test.ts', () => {
         expect(manifest.items.filter(item => item.loader === 'module').length).toBe(5);
 
         expect(manifest.items.filter(item => item.source === 'redis').length).toBe(2);
+        expect(manifest.items.filter(item => item.source === 'mysql').length).toBe(0);
         expect(manifest.items.filter(item => item.source === 'app').length).toBe(9);
     });
 });
\ No newline at end of file