feat: allow constructable modules (#133)

* Update readFile.ts

* Update userDefinedEventsHandling.ts

* Update readyHandler.ts

* fix: ts error

Co-authored-by: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com>
Co-authored-by: xxDeveloper <77380166+Murtatrxx@users.noreply.github.com>
This commit is contained in:
Arcs
2022-09-13 13:46:06 -05:00
committed by GitHub
parent c4019f7a08
commit 03936eb2ea
3 changed files with 7 additions and 2 deletions

View File

@@ -87,7 +87,7 @@ export default class ReadyHandler extends EventsHandler<{
type: PluginType.Command;
}[];
}) {
if (mod.plugins.length === 0) {
if ((mod.plugins || []).length === 0) {
return of({ mod, pluginRes: [] });
}
// modules with no event plugins are ignored in the previous

View File

@@ -25,7 +25,7 @@ export function processCommandPlugins<T extends DefinedCommandModule>(
wrapper: Wrapper,
payload: { mod: T; absPath: string },
) {
return payload.mod.plugins.map(plug => ({
return (payload.mod.plugins || []).map(plug => ({
...plug,
name: plug?.name ?? 'Unnamed Plugin',
description: plug?.description ?? '...',

View File

@@ -73,6 +73,11 @@ export function buildData<T>(commandDir: string): Observable<
} catch {
mod = (await import(`file:///` + absPath)).default;
}
try {
mod = new (mod as unknown as new (...args: unknown[]) => T)();
} catch {}
if (mod !== undefined) {
return Ok({ mod, absPath });
} else return Err(SernError.UndefinedModule);