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.modules = modules;
for (let i = 0; i < modules.length; i++) {
const {$$latus: {hooks}} = modules[i];
const keys = Object.keys(hooks);
for (let j = 0; j < keys.length; j++) {
const key = keys[j];
if (!this.hooks[key]) {
this.hooks[key] = [];
if (modules[i].$$latus) {
const {$$latus: {hooks}} = modules[i];
const keys = Object.keys(hooks);
for (let j = 0; j < keys.length; j++) {
const key = keys[j];
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');
@ -73,7 +75,7 @@ export default class Plugins {
invokePlugin(hook, plugin, ...args) {
if (!this.hooks[hook]) {
return [];
return undefined;
}
return this.hooks[hook]
.find(({plugin: candidate}) => candidate === plugin)