| 24 | * @public |
| 25 | */ |
| 26 | export 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected