| 90 | } |
| 91 | |
| 92 | public async addModule( |
| 93 | metatype: ModuleMetatype, |
| 94 | scope: ModuleScope, |
| 95 | ): Promise< |
| 96 | | { |
| 97 | moduleRef: Module; |
| 98 | inserted: boolean; |
| 99 | } |
| 100 | | undefined |
| 101 | > { |
| 102 | // In DependenciesScanner#scanForModules we already check for undefined or invalid modules |
| 103 | // We still need to catch the edge-case of `forwardRef(() => undefined)` |
| 104 | if (!metatype) { |
| 105 | throw new UndefinedForwardRefException(scope); |
| 106 | } |
| 107 | const { type, dynamicMetadata, token } = |
| 108 | await this.moduleCompiler.compile(metatype); |
| 109 | if (this.modules.has(token)) { |
| 110 | return { |
| 111 | moduleRef: this.modules.get(token)!, |
| 112 | inserted: true, |
| 113 | }; |
| 114 | } |
| 115 | |
| 116 | return { |
| 117 | moduleRef: await this.setModule( |
| 118 | { |
| 119 | token, |
| 120 | type, |
| 121 | dynamicMetadata, |
| 122 | }, |
| 123 | scope, |
| 124 | ), |
| 125 | inserted: true, |
| 126 | }; |
| 127 | } |
| 128 | |
| 129 | public async replaceModule( |
| 130 | metatypeToReplace: ModuleMetatype, |