1- import 'reflect-metadata' ;
2- import { NestContainer } from './injector/container' ;
3- import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface' ;
4- import { Injectable } from '@nestjs/common/interfaces/injectable.interface' ;
1+ import { DynamicModule } from '@nestjs/common' ;
52import {
6- metadata ,
7- GATEWAY_MIDDLEWARES ,
83 EXCEPTION_FILTERS_METADATA ,
4+ GATEWAY_MIDDLEWARES ,
95 GUARDS_METADATA ,
106 INTERCEPTORS_METADATA ,
7+ metadata ,
118 PIPES_METADATA ,
129 ROUTE_ARGS_METADATA ,
1310} from '@nestjs/common/constants' ;
11+ import { Controller } from '@nestjs/common/interfaces/controllers/controller.interface' ;
12+ import { Injectable } from '@nestjs/common/interfaces/injectable.interface' ;
1413import { Type } from '@nestjs/common/interfaces/type.interface' ;
15- import { MetadataScanner } from '../core/metadata-scanner' ;
16- import { DynamicModule } from '@nestjs/common' ;
17- import { ApplicationConfig } from './application-config' ;
1814import {
15+ isFunction ,
1916 isNil ,
2017 isUndefined ,
21- isFunction ,
2218} from '@nestjs/common/utils/shared.utils' ;
23- import { APP_INTERCEPTOR , APP_PIPE , APP_GUARD , APP_FILTER } from './constants' ;
19+ import 'reflect-metadata' ;
20+ import { MetadataScanner } from '../core/metadata-scanner' ;
21+ import { ApplicationConfig } from './application-config' ;
22+ import { APP_FILTER , APP_GUARD , APP_INTERCEPTOR , APP_PIPE } from './constants' ;
2423import { CircularDependencyException } from './errors/exceptions/circular-dependency.exception' ;
24+ import { NestContainer } from './injector/container' ;
2525
2626interface ApplicationProviderWrapper {
2727 moduleToken : string ;
@@ -36,43 +36,43 @@ export class DependenciesScanner {
3636 private readonly applicationConfig = new ApplicationConfig ( ) ,
3737 ) { }
3838
39- public scan ( module : Type < any > ) {
40- this . scanForModules ( module ) ;
41- this . scanModulesForDependencies ( ) ;
39+ public async scan ( module : Type < any > ) {
40+ await this . scanForModules ( module ) ;
41+ await this . scanModulesForDependencies ( ) ;
4242 this . container . bindGlobalScope ( ) ;
4343 }
4444
45- public scanForModules (
45+ public async scanForModules (
4646 module : Type < any > | DynamicModule ,
4747 scope : Type < any > [ ] = [ ] ,
4848 ) {
49- this . storeModule ( module , scope ) ;
49+ await this . storeModule ( module , scope ) ;
5050
5151 const modules = this . reflectMetadata ( module , metadata . MODULES ) ;
52- modules . map ( innerModule => {
53- this . scanForModules ( innerModule , [ ] . concat ( scope , module ) ) ;
54- } ) ;
52+ for ( const innerModule of modules ) {
53+ await this . scanForModules ( innerModule , [ ] . concat ( scope , module ) ) ;
54+ }
5555 }
5656
57- public storeModule ( module : any , scope : Type < any > [ ] ) {
57+ public async storeModule ( module : any , scope : Type < any > [ ] ) {
5858 if ( module && module . forwardRef ) {
59- return this . container . addModule ( module . forwardRef ( ) , scope ) ;
59+ return await this . container . addModule ( module . forwardRef ( ) , scope ) ;
6060 }
61- this . container . addModule ( module , scope ) ;
61+ await this . container . addModule ( module , scope ) ;
6262 }
6363
64- public scanModulesForDependencies ( ) {
64+ public async scanModulesForDependencies ( ) {
6565 const modules = this . container . getModules ( ) ;
6666
67- modules . forEach ( ( { metatype } , token ) => {
68- this . reflectRelatedModules ( metatype , token , metatype . name ) ;
67+ for ( const [ token , { metatype } ] of modules ) {
68+ await this . reflectRelatedModules ( metatype , token , metatype . name ) ;
6969 this . reflectComponents ( metatype , token ) ;
7070 this . reflectControllers ( metatype , token ) ;
7171 this . reflectExports ( metatype , token ) ;
72- } ) ;
72+ }
7373 }
7474
75- public reflectRelatedModules (
75+ public async reflectRelatedModules (
7676 module : Type < any > ,
7777 token : string ,
7878 context : string ,
@@ -88,7 +88,9 @@ export class DependenciesScanner {
8888 metadata . IMPORTS as 'imports' ,
8989 ) ,
9090 ] ;
91- modules . map ( related => this . storeRelatedModule ( related , token , context ) ) ;
91+ for ( const related of modules ) {
92+ await this . storeRelatedModule ( related , token , context ) ;
93+ }
9294 }
9395
9496 public reflectComponents ( module : Type < any > , token : string ) {
@@ -214,14 +216,18 @@ export class DependenciesScanner {
214216 return descriptor ? Reflect . getMetadata ( key , descriptor . value ) : undefined ;
215217 }
216218
217- public storeRelatedModule ( related : any , token : string , context : string ) {
219+ public async storeRelatedModule (
220+ related : any ,
221+ token : string ,
222+ context : string ,
223+ ) {
218224 if ( isUndefined ( related ) ) {
219225 throw new CircularDependencyException ( context ) ;
220226 }
221227 if ( related && related . forwardRef ) {
222- return this . container . addRelatedModule ( related . forwardRef ( ) , token ) ;
228+ return await this . container . addRelatedModule ( related . forwardRef ( ) , token ) ;
223229 }
224- this . container . addRelatedModule ( related , token ) ;
230+ await this . container . addRelatedModule ( related , token ) ;
225231 }
226232
227233 public storeComponent ( component , token : string ) {
0 commit comments