From 61679add14c292c881cfc28f06cd2530c8c5f47d Mon Sep 17 00:00:00 2001 From: cha0s Date: Wed, 2 Dec 2020 17:23:15 -0600 Subject: [PATCH] fix: guard plugins --- packages/core/src/plugins.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/core/src/plugins.js b/packages/core/src/plugins.js index d48c2f0..e33fbce 100644 --- a/packages/core/src/plugins.js +++ b/packages/core/src/plugins.js @@ -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)