nx-dotnet / nx-dotnet

A Nx plugin adding support for .NET 5+ (or .net core) projects, featuring full project graph and generator support.
https://www.nx-dotnet.com/
MIT License
260 stars 62 forks source link

[BUG] Generated `-types` project does not uses `nx.json` configured generators values #816

Closed sharky98 closed 1 month ago

sharky98 commented 8 months ago

Current Behavior

When creating a webapi application with skipSwaggerLib=false, a new -types project is created as expected. This project (I think?) is created using the @nx/js:library generator. I have in my nx.json configured to use vitest as the unit test runner. However, in the dry-run I see that files such as jest.config.ts are created, hinting that my configuration to use vitest is not considered.

{
  "generators": {
    "@nx/js": {
      "library": {
        "simpleName": true,
        "linter": "eslint",
        "bundler": "none",
        "unitTestRunner": "vitest",
        "projectNameAndRootFormat": "as-provided"
      }
    }
  }
}

Expected Behavior

The generated project uses my pre-configured vitest as the unit test runner.

Github Repo

No response

Steps to Reproduce

  1. Have a fresh Nx repo with nx-dotnet configured. Make sure that any init run during that setup does not install @nx/jest.
  2. Make sure that the generators for @nx/js:application in nx.json uses "unitTestRunner": "vitest".
  3. Run nx g @nx-dotnet/core:application --name=backend --language=C# --template=webapi --dry-run.

The dry-run output shows that files for jest are created, when they should not be (not also we observe bug #801 in that the generated projects are not under libs or apps).

In Nx 18, generating projects will no longer derive the name and root.
Please provide the exact project name and root in the future.
Example: nx g @nx/js:library generated-backend-types --directory generated/backend-types
CREATE apps/backend/project.json
CREATE apps/backend-test/project.json
CREATE generated/backend-swagger/project.json
CREATE generated/backend-types/tsconfig.json
CREATE generated/backend-types/README.md
CREATE generated/backend-types/src/index.ts
CREATE generated/backend-types/src/lib/generated-backend-types.spec.ts
CREATE generated/backend-types/src/lib/generated-backend-types.ts
CREATE generated/backend-types/tsconfig.lib.json
CREATE generated/backend-types/package.json
CREATE generated/backend-types/project.json
CREATE generated/backend-types/.eslintrc.json
CREATE jest.preset.js
UPDATE nx.json
CREATE jest.config.ts
UPDATE package.json
CREATE generated/backend-types/jest.config.ts
CREATE generated/backend-types/tsconfig.spec.json
UPDATE tsconfig.base.json
CREATE apps/backend/.gitignore

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 20.10.0
   OS     : win32-x64
   pnpm   : 8.14.1

   nx (global)        : 17.2.8
   nx                 : 17.2.8
   @nx/js             : 17.2.8
   @nx/eslint         : 17.2.8
   @nx/workspace      : 17.2.8
   @nx/cypress        : 17.2.8
   @nx/devkit         : 17.2.8
   @nx/eslint-plugin  : 17.2.8
   @nx/plugin         : 17.2.8
   @nx/react          : 17.2.8
   @nrwl/tao          : 17.2.8
   @nx/vite           : 17.2.8
   typescript         : 5.3.3
   ---------------------------------------
   Community plugins:
   @nx-dotnet/core : 2.1.2

nx.json

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "targetDefaults": {
    "build": {
      "cache": true,
      "dependsOn": ["^build"],
      "inputs": ["production", "^production"]
    },
    "lint": {
      "cache": true,
      "inputs": ["default", "{workspaceRoot}/.eslintignore", "{workspaceRoot}/.eslintrc.json"]
    },
    "@nx/vite:test": {
      "cache": true,
      "inputs": ["default", "^production"]
    },
    "e2e": {
      "cache": true,
      "inputs": ["default", "^production"]
    }
  },
  "namedInputs": {
    "default": ["{projectRoot}/**/*", "sharedGlobals"],
    "production": [
      "default",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/.eslintrc.json",
      "!{projectRoot}/cypress/**/*",
      "!{projectRoot}/**/*.cy.[jt]s?(x)",
      "!{projectRoot}/cypress.config.[jt]s"
    ],
    "sharedGlobals": []
  },
  "plugins": ["@nx-dotnet/core"],
  "generators": {
    "@nx/js": {
      "library": {
        "simpleName": true,
        "linter": "eslint",
        "bundler": "none",
        "unitTestRunner": "vitest",
        "projectNameAndRootFormat": "as-provided"
      }
    },
    "@nx/react": {
      "application": {
        "style": "none",
        "linter": "eslint",
        "bundler": "vite",
        "routing": false,
        "simpleName": true,
        "compiler": "swc",
        "e2eTestRunner": "cypress",
        "unitTestRunner": "vitest",
        "projectNameAndRootFormat": "as-provided",
        "babel": true
      },
      "library": {
        "style": "none",
        "linter": "eslint",
        "simpleName": true,
        "compiler": "swc",
        "bundler": "none",
        "unitTestRunner": "vitest",
        "projectNameAndRootFormat": "as-provided"
      },
      "component": {
        "style": "none"
      }
    },
    "@nx-dotnet/core": {
      "application": {
        "solutionFile": "root-dotnet.sln"
      },
      "library": {
        "solutionFile": "root-dotnet.sln"
      }
    }
  }
}

Failure Logs

No response

Additional Information

No response

sharky98 commented 8 months ago

I was wondering if in the meantime, I can use add-swagger-target and swagger-typescript generators to create the swagger and types in a pre-created library project? I am not certain on how the arguments work.

github-actions[bot] commented 1 month ago

:tada: This issue has been resolved in version 2.3.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] commented 3 weeks ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.