fix: guard plugins

This commit is contained in:
cha0s 2020-12-02 17:23:15 -06:00
parent 7883672ff7
commit 61679add14

View File

@ -8,17 +8,19 @@ export default class Plugins {
this.hooks = {}; this.hooks = {};
this.modules = modules; this.modules = modules;
for (let i = 0; i < modules.length; i++) { for (let i = 0; i < modules.length; i++) {
const {$$latus: {hooks}} = modules[i]; if (modules[i].$$latus) {
const keys = Object.keys(hooks); const {$$latus: {hooks}} = modules[i];
for (let j = 0; j < keys.length; j++) { const keys = Object.keys(hooks);
const key = keys[j]; for (let j = 0; j < keys.length; j++) {
if (!this.hooks[key]) { const key = keys[j];
this.hooks[key] = []; if (!this.hooks[key]) {
this.hooks[key] = [];
}
this.hooks[key].push({
plugin: paths[i],
fn: hooks[key],
});
} }
this.hooks[key].push({
plugin: paths[i],
fn: hooks[key],
});
} }
} }
const defaultConfig = this.invoke('@latus/core/config'); const defaultConfig = this.invoke('@latus/core/config');
@ -73,7 +75,7 @@ export default class Plugins {
invokePlugin(hook, plugin, ...args) { invokePlugin(hook, plugin, ...args) {
if (!this.hooks[hook]) { if (!this.hooks[hook]) {
return []; return undefined;
} }
return this.hooks[hook] return this.hooks[hook]
.find(({plugin: candidate}) => candidate === plugin) .find(({plugin: candidate}) => candidate === plugin)