Skip to content

Commit 04e8376

Browse files
committed
fix(utils): when updating a non-existing nestjs module
1 parent 79ba067 commit 04e8376

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/utils/metadata.manager.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,18 @@ export class MetadataManager {
2424
metadata: string,
2525
symbol: string,
2626
staticOptions?: DeclarationOptions['staticOptions'],
27-
): string {
27+
): string | undefined {
2828
const source: SourceFile = createSourceFile(
2929
'filename.ts',
3030
this.content,
3131
ScriptTarget.ES2017,
3232
);
3333
const decoratorNodes: Node[] = this.getDecoratorMetadata(source, '@Module');
3434
const node: Node = decoratorNodes[0];
35+
// If there is no occurrence of `@Module` decorator, nothing will be inserted
36+
if (!node) {
37+
return;
38+
}
3539
const matchingProperties: ObjectLiteralElement[] = (
3640
node as ObjectLiteralExpression
3741
).properties

src/utils/module-metadata.declarator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ export class ModuleMetadataDeclarator {
99
options.symbol,
1010
options.staticOptions,
1111
);
12-
return inserted;
12+
return inserted ?? content;
1313
}
1414
}

0 commit comments

Comments
 (0)