From d34148adc35167e277d06fb0c78f1d82c4bc4cfb Mon Sep 17 00:00:00 2001
From: cgeek <cem.moreau@gmail.com>
Date: Wed, 31 May 2017 14:31:50 +0200
Subject: [PATCH] [enh] #918 Also inject local plugin if it exists

---
 index.js                    | 13 +++++++++++++
 server/controller/webmin.js |  9 +++++++--
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/index.js b/index.js
index d9719ae..2844ffa 100644
--- a/index.js
+++ b/index.js
@@ -190,5 +190,18 @@ function listPlugins(conditionTest) {
       }
     } catch (e) {}
   }
+  // Special: self dependency (if local package is also a module)
+  if (pkgJSON.main) {
+    const dep = pkgJSON.name
+    const required = require(path.resolve('./' + pkgJSON.main))
+    if (required && conditionTest(required)) {
+      uiDependencies.push({
+        name: dep,
+        version: 'local',
+        locked: true,
+        required
+      })
+    }
+  }
   return uiDependencies
 }
diff --git a/server/controller/webmin.js b/server/controller/webmin.js
index 0f29e2d..268bf23 100644
--- a/server/controller/webmin.js
+++ b/server/controller/webmin.js
@@ -580,8 +580,13 @@ function WebAdmin (duniterServer, startServices, stopServices, listDuniterUIPlug
 
   this.plugUiModulesGetInjection = (req) => co(function*() {
     const module = req.params.package
-    const required = require(module)
-    return required.duniterUI.inject || {}
+    const plugins = listDuniterUIPlugins()
+    for (const plugin of plugins) {
+      if (plugin.name === module) {
+        return plugin.required.duniterUI.inject || {}
+      }
+    }
+    return {}
   })
 
   this.plugCheckAccess = (req) => requirePlugin().duniter.methods.canWrite()
-- 
GitLab