*refactor to handle invalid plugins
This commit is contained in:
parent
21887df639
commit
a0504443e6
|
@ -147,22 +147,33 @@ export class PluginAPIManager {
|
|||
}
|
||||
|
||||
let plugin: Plugin;
|
||||
let pluginPath = paths.shift();
|
||||
try {
|
||||
plugin = require(paths.shift() as string) as Plugin;
|
||||
plugin = require(pluginPath as string) as Plugin;
|
||||
} catch (e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
log.debug("Loaded plugin %s", moduleName);
|
||||
|
||||
return this.loadPluginInstance(plugin);
|
||||
const instance = await this.loadPluginInstance(plugin);
|
||||
|
||||
if (!instance) {
|
||||
throw new Error(`Corrupt plugin found at ${pluginPath}`);
|
||||
}
|
||||
|
||||
public async loadPluginInstance(plugin: Plugin): Promise<Plugin> {
|
||||
return instance as Plugin;
|
||||
}
|
||||
|
||||
public async loadPluginInstance(plugin: Plugin): Promise<Plugin | boolean> {
|
||||
if ("default" in plugin) {
|
||||
plugin = plugin?.default as Plugin;
|
||||
}
|
||||
|
||||
if (!("name" in plugin)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.name = sanitizeName(plugin.name);
|
||||
|
||||
this.registeredPlugins.set(plugin.name, plugin);
|
||||
|
|
Loading…
Reference in New Issue