Skip to content

fix(generate): use selected project name for specFileSuffix lookup#3325

Open
yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/generate-action-spec-file-suffix-project-name
Open

fix(generate): use selected project name for specFileSuffix lookup#3325
yogeshwaran-c wants to merge 1 commit intonestjs:masterfrom
yogeshwaran-c:fix/generate-action-spec-file-suffix-project-name

Conversation

@yogeshwaran-c
Copy link
Copy Markdown

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

When a user runs nest generate in a monorepo project and is prompted to select a project (because no --project flag was provided), the getSpecFileSuffix call incorrectly uses appName (the original CLI input, which is empty/falsy at this point) instead of selectedProjectName (the project the user just selected from the interactive prompt).

This means that per-project specFileSuffix configuration in nest-cli.json is silently ignored when a project is interactively selected, and the global default is used instead.

Example config where this matters:

{
  "projects": {
    "my-app": {
      "sourceRoot": "apps/my-app/src",
      "generateOptions": {
        "specFileSuffix": "test"
      }
    }
  }
}

Running nest generate service foo and selecting my-app from the prompt would generate foo.spec.ts instead of the expected foo.test.ts.

What is the new behavior?

getSpecFileSuffix now receives selectedProjectName — consistent with the adjacent shouldGenerateSpec and shouldGenerateFlat calls that already correctly use selectedProjectName.

The one-line fix (line 123 of actions/generate.action.ts):

-        appName,
+        selectedProjectName,

Additional context

This bug was introduced in #1968 when the specFileSuffix feature was added. The shouldGenerateSpec and shouldGenerateFlat calls were already using selectedProjectName, but getSpecFileSuffix was mistakenly wired to appName.

When a non-default project is selected during `nest generate`, the
`getSpecFileSuffix` call was incorrectly using `appName` (the original
CLI input) instead of `selectedProjectName` (the user's interactive
selection). This caused per-project `specFileSuffix` configuration to
be ignored, falling back to global config instead.

The adjacent `shouldGenerateSpec` and `shouldGenerateFlat` calls both
correctly use `selectedProjectName` -- this aligns `getSpecFileSuffix`
with the same pattern.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant