fix: providers

This commit is contained in:
cha0s 2021-03-25 04:14:27 -05:00
parent 147c42fc4a
commit 7073706e7c
2 changed files with 24 additions and 3 deletions

View File

@ -188,10 +188,31 @@ export default class Latus {
const parts = hook.split('/');
const key = parts.pop();
const plugins = this.config[parts.join('/')][key].concat();
if (!plugins) {
return [];
}
let finalPlugins = [];
const index = plugins.findIndex((plugin) => '...' === plugin);
if (-1 !== index) {
const before = plugins.slice(0, index);
const after = plugins.slice(index + 1);
const rest = without(
this.hooks[hook].map(({plugin}) => plugin),
...before.concat(after),
);
finalPlugins = [
...before,
...rest,
...after,
];
}
else {
finalPlugins = plugins;
}
const promises = [];
while (plugins.length > 0) {
while (finalPlugins.length > 0) {
// eslint-disable-next-line no-await-in-loop
promises.push(this.invokePlugin(hook, plugins.shift(), ...(args.concat(this))));
promises.push(this.invokePlugin(hook, finalPlugins.shift(), ...(args.concat(this))));
}
return Promise.all(promises);
}

View File

@ -12,7 +12,7 @@ export {default as usePrevious} from './hooks/use-previous';
export default {
hooks: {
'@latus/core/config': () => ({
providers: [],
providers: ['...'],
}),
},
};