Support named canonical exports

This commit is contained in:
Garrett Mills 2021-03-06 11:44:32 -06:00
parent be1f615858
commit cd387af2c6
Signed by: garrettmills
GPG Key ID: D2BF5FBA8298F246
3 changed files with 9 additions and 1 deletions

View File

@ -105,7 +105,7 @@ export abstract class Canonical<T> extends Unit {
}
public async initCanonicalItem(definition: CanonicalDefinition): Promise<T> {
return definition.imported.default
return definition.imported.default ?? definition.imported[definition.canonicalName]
}
protected async buildCanonicalDefinition(filePath: string): Promise<CanonicalDefinition> {

View File

@ -17,6 +17,10 @@ export class CanonicalInstantiable<T> extends Canonical<Instantiable<T>> {
return this.app().make(definition.imported.default)
}
if ( isInstantiable(definition.imported[definition.canonicalName]) ) {
return this.app().make(definition.imported[definition.canonicalName])
}
throw new InvalidCanonicalExportError(definition.originalName)
}
}

View File

@ -8,6 +8,10 @@ export class CanonicalStatic<T, T2> extends Canonical<StaticClass<T, T2>> {
return definition.imported.default
}
if ( isStaticClass(definition.imported[definition.canonicalName]) ) {
return definition.imported[definition.canonicalName]
}
throw new InvalidCanonicalExportError(definition.originalName)
}
}