nestjs / schematics

Nest architecture element generation based on Angular schematics 🎬
https://nestjs.com
MIT License
386 stars 206 forks source link

fix: when finding the `@Module()` decorator occurrence #1808

Closed micalevisk closed 4 months ago

micalevisk commented 4 months ago

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

What is the current behavior?

when running nest generate controller when our app.module.ts has any decorator factory before @Module(), the wrong decorator is being changed

import { Injectable, Module, Scope } from '@nestjs/common'

@Injectable({}) // BUG: this will receive the `controllers` prop after nest generate
class Service {}

@Module({
  imports: [],
  providers: [Service],
  controllers: [],
})
export class 

demo-issue-nestjs-cli.webm

What is the new behavior?

  1. we can now have any sort of decorators on .module.ts files but only the first @Module({}) occurrence will be update (if found)
  2. minor optimization regarding the @Module() decorator look up to use a find-first approach instead of find-many

note that we still don't support import aliases such as
import { Module as M } from "@nestjs/core"

Does this PR introduce a breaking change?

kamilmysliwiec commented 4 months ago

lgtm