Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

micalevisk
Copy link
Member

@micalevisk micalevisk commented Jun 28, 2024

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

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?

  • Yes
  • No

@micalevisk micalevisk changed the title fix(utils): when finding the @Module decorator occurrence fix(utils): when finding the @Module() decorator occurrence Jun 28, 2024
@micalevisk micalevisk changed the title fix(utils): when finding the @Module() decorator occurrence fix: when finding the @Module() decorator occurrence Jul 1, 2024
@kamilmysliwiec kamilmysliwiec added the bug Something isn't working label Jul 2, 2024
@kamilmysliwiec kamilmysliwiec merged commit c45d85e into nestjs:master Jul 2, 2024
1 check passed
@kamilmysliwiec
Copy link
Member

lgtm

@micalevisk micalevisk deleted the fix-controller-generator-edge-case branch July 2, 2024 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants