Update version to 5.1.1 and add support for synchronous and asynchronous plugin functions

This commit is contained in:
Harvey Zack committed 2024-01-11 10:40:55 +08:00
1 parent a1063c20ed
commit 3aa30de771
11 files changed
+44 -24

No files matched your search

+10 -2
View File
@@ -37,9 +37,17 @@ export default class Plugins {
}
}
async add(plugin) {
add(plugin) {
this.id += 1;
const result = await plugin.call(this.art, this.art);
const result = plugin.call(this.art, this.art);
if (result instanceof Promise) {
return result.then((res) => this.next(plugin, res));
} else {
return this.next(plugin, result);
}
}
next(plugin, result) {
const pluginName = (result && result.name) || plugin.name || `plugin${this.id}`;
errorHandle(!has(this, pluginName), `Cannot add a plugin that already has the same name: ${pluginName}`);
def(this, pluginName, {