fix: guard plugins
This commit is contained in:
parent
7883672ff7
commit
61679add14
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user