MCPcopy
hub / github.com/nestjs/nest / replaceModule

Method replaceModule

packages/core/injector/container.ts:129–161  ·  view source on GitHub ↗
(
    metatypeToReplace: ModuleMetatype,
    newMetatype: ModuleMetatype,
    scope: ModuleScope,
  )

Source from the content-addressed store, hash-verified

127 }
128
129 public async replaceModule(
130 metatypeToReplace: ModuleMetatype,
131 newMetatype: ModuleMetatype,
132 scope: ModuleScope,
133 ): Promise<
134 | {
135 moduleRef: Module;
136 inserted: boolean;
137 }
138 | undefined
139 > {
140 // In DependenciesScanner#scanForModules we already check for undefined or invalid modules
141 // We still need to catch the edge-case of `forwardRef(() => undefined)`
142 if (!metatypeToReplace || !newMetatype) {
143 throw new UndefinedForwardRefException(scope);
144 }
145
146 const { token } = await this.moduleCompiler.compile(metatypeToReplace);
147 const { type, dynamicMetadata } =
148 await this.moduleCompiler.compile(newMetatype);
149
150 return {
151 moduleRef: await this.setModule(
152 {
153 token,
154 type,
155 dynamicMetadata,
156 },
157 scope,
158 ),
159 inserted: false,
160 };
161 }
162
163 private async setModule(
164 { token, dynamicMetadata, type }: ModuleFactory,

Callers 2

overrideModuleMethod · 0.80
container.spec.tsFile · 0.80

Calls 2

setModuleMethod · 0.95
compileMethod · 0.45

Tested by

no test coverage detected