Commit 69dc20c646b477c874cb1f6eb145f9cd1016b04c
check name on both kinds of plugins
Henry committed on 12/17/2018, 11:57:50 AMParent: 36398834f84909b2c6a69f085596dd58efc6ca7b
Files changed
plugins/plugins.js | changed |
plugins/plugins.js | ||
---|---|---|
@@ -184,25 +184,26 @@ | ||
184 | 184 … | // iterate all modules |
185 | 185 … | var nodeModulesPath = path.join(config.path, 'node_modules') |
186 | 186 … | //instead of testing all plugins, only load things explicitly |
187 | 187 … | //enabled in the config |
188 | - for(var module_name in config.plugins) { | |
188 … | + for (var module_name in config.plugins) { | |
189 | 189 … | const configv = config.plugins[module_name] |
190 | - if(configv) { | |
190 … | + if (configv) { | |
191 | 191 … | const name = /^ssb-/.test(module_name) ? module_name.substring(4) : module_name |
192 | 192 … | |
193 | 193 … | if (createSbot.plugins.some(plug => plug.name === name)) |
194 | 194 … | throw new Error('already loaded plugin named:'+name) |
195 | 195 … | |
196 | 196 … | let plugin = null |
197 | - if (typeof configv === 'object') { | |
197 … | + if (typeof configv === 'object') { // out-of-process plugin | |
198 | 198 … | plugin = require('ssb-plugins2/load')(configv.location) |
199 | - plugin.name = name | |
200 | 199 … | } else if (typeof configv === 'boolean') { |
201 | 200 … | plugin = require(path.join(nodeModulesPath, module_name)) |
202 | - if(!plugin || plugin.name !== name) | |
203 | - throw new Error('plugin at:'+module_name+' expected name:'+name+' but had:'+(plugin||{}).name) | |
204 | 201 … | } |
202 … | + | |
203 … | + if (!plugin || plugin.name !== name) | |
204 … | + throw new Error(`plugin at:${module_name} expected name:${name} but had:${(plugin||{}).name}`) | |
205 … | + | |
205 | 206 … | assertSbotPlugin(plugin) |
206 | 207 … | createSbot.use(plugin) |
207 | 208 … | } |
208 | 209 … | } |
Built with git-ssb-web