*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 plugin: Plugin;
|
||||||
|
let pluginPath = paths.shift();
|
||||||
try {
|
try {
|
||||||
plugin = require(paths.shift() as string) as Plugin;
|
plugin = require(pluginPath as string) as Plugin;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug("Loaded plugin %s", moduleName);
|
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}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance as Plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async loadPluginInstance(plugin: Plugin): Promise<Plugin> {
|
public async loadPluginInstance(plugin: Plugin): Promise<Plugin | boolean> {
|
||||||
if ("default" in plugin) {
|
if ("default" in plugin) {
|
||||||
plugin = plugin?.default as Plugin;
|
plugin = plugin?.default as Plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!("name" in plugin)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
plugin.name = sanitizeName(plugin.name);
|
plugin.name = sanitizeName(plugin.name);
|
||||||
|
|
||||||
this.registeredPlugins.set(plugin.name, plugin);
|
this.registeredPlugins.set(plugin.name, plugin);
|
||||||
|
|
Loading…
Reference in New Issue