diff --git a/module.ts b/module.ts index 0af4cbb..8830429 100644 --- a/module.ts +++ b/module.ts @@ -271,7 +271,10 @@ export class Module extends ModuleBase { const enabledInstance = this.getEnabledInstance(); await enabledInstance?.transition.block(); - if (instance.isEnabled() || (enabledInstance && !this.canDisable(enabledInstance))) { + if ( + instance.isEnabled() || + (enabledInstance && !this.canDisable(enabledInstance)) + ) { return false; } @@ -373,7 +376,7 @@ export abstract class ModuleInstanceBase< public metadata: Metadata | null, public artifacts: Array, public checksum: string, - ) { } + ) {} // ? public updateMetadata(metadata: Metadata) { @@ -784,9 +787,7 @@ export class ModuleInstance extends ModuleInstanceBase public async onEnable() { if (this.installed) { await this.loadProviders(); - const storeUrl = this.getMetadataURL()!; - const metadata = await fetchJson(storeUrl); - this.updateMetadata(metadata); + await this.ensureMetadata(); } } @@ -925,6 +926,20 @@ export class ModuleInstance extends ModuleInstanceBase this.module.parent = null; } } + public async ensureMetadata() { + if (!this.metadata) { + try { + const storeUrl = this.getMetadataURL()!; + const metadata = await fetchJson(storeUrl); + this.updateMetadata(metadata); + } catch (e) { + throw new Error( + `couldn't load metadata for module '${this.getIdentifier()}'`, + { cause: e }, + ); + } + } + } } export const INTERNAL_MIXIN_LOADER: MixinLoader = {