MCPcopy
hub / github.com/element-hq/element-web / ModuleLoader

Class ModuleLoader

packages/module-api/src/loader.ts:26–55  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 * @public
25 */
26export class ModuleLoader {
27 private modules: Module[] = [];
28 private started = false;
29
30 public constructor(private api: Api) {}
31
32 public async load(moduleExport: ModuleExport): Promise<void> {
33 if (this.started) {
34 throw new Error("PluginEngine.start() has already been called");
35 }
36
37 if (!isModule(moduleExport)) {
38 throw new Error("Invalid plugin");
39 }
40 if (!satisfies(__VERSION__, moduleExport.default.moduleApiVersion)) {
41 throw new ModuleIncompatibleError(moduleExport.default.moduleApiVersion);
42 }
43 const { default: Module } = moduleExport;
44 this.modules.push(new Module(this.api));
45 }
46
47 public async start(): Promise<void> {
48 if (this.started) {
49 throw new Error("PluginEngine.start() has already been called");
50 }
51 this.started = true;
52
53 await Promise.all(this.modules.map((plugin) => plugin.load()));
54 }
55}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected