mirror of
https://github.com/nestjs/nest.git
synced 2026-02-21 23:11:44 +00:00
feat(core): add lazy module loader class
This commit is contained in:
@@ -59,6 +59,7 @@ export class Module {
|
||||
>();
|
||||
private readonly _exports = new Set<InstanceToken>();
|
||||
private _distance = 0;
|
||||
private _token: string;
|
||||
|
||||
constructor(
|
||||
private readonly _metatype: Type<any>,
|
||||
@@ -72,6 +73,14 @@ export class Module {
|
||||
return this._id;
|
||||
}
|
||||
|
||||
get token(): string {
|
||||
return this._token;
|
||||
}
|
||||
|
||||
set token(token: string) {
|
||||
this._token = token;
|
||||
}
|
||||
|
||||
get providers(): Map<InstanceToken, InstanceWrapper<Injectable>> {
|
||||
return this._providers;
|
||||
}
|
||||
@@ -411,15 +420,13 @@ export class Module {
|
||||
if (this._providers.has(token)) {
|
||||
return token;
|
||||
}
|
||||
const importsArray = [...this._imports.values()];
|
||||
const importsNames = iterate(importsArray)
|
||||
const imports = iterate(this._imports.values())
|
||||
.filter(item => !!item)
|
||||
.map(({ metatype }) => metatype)
|
||||
.filter(metatype => !!metatype)
|
||||
.map(({ name }) => name)
|
||||
.toArray();
|
||||
|
||||
if (!importsNames.includes(token as string)) {
|
||||
if (!imports.includes(token as Type<unknown>)) {
|
||||
const { name } = this.metatype;
|
||||
const providerName = isFunction(token) ? (token as Function).name : token;
|
||||
throw new UnknownExportException(providerName as string, name);
|
||||
|
||||
Reference in New Issue
Block a user