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

[BUG] import projects generator incorrectly checks for new projects #685

Closed
Take-Limeship opened this issue Apr 25, 2023 · 2 comments · Fixed by #687
Closed

[BUG] import projects generator incorrectly checks for new projects #685

Take-Limeship opened this issue Apr 25, 2023 · 2 comments · Fixed by #687
Labels
bug Something isn't working outdated scope: core

Comments

@Take-Limeship
Copy link
Contributor

Take-Limeship commented Apr 25, 2023

Current Behavior

Currently, the import-projects generator checks if it is a new project by using the method

if ( !existingProjectJsonDirectories.some((x) => projectFile.startsWith(x)) )

However, because the filtering uses startsWith(), new projects with a path beginning the same way as an already imported project but differentiating at the end of the name are also counted as an existing project.

eg.:
We have a csproj already containing a project.json in the directory 'apps/example-app'
We create a new C# project in the directory 'apps/example-app-tests'

According to this logic:
https://github.com/nx-dotnet/nx-dotnet/blob/master/packages/core/src/generators/import-projects/generator.ts#L47
running the import-projects generator, 'apps/example-app-tests' would match the existingProjectJsonDirectories array as it starts the same as 'apps/example-app'

The same logic is also used to check if a library is new.

Expected Behavior

It is expected that the generator checks for the exact path to determine if it is an already existing project or not.
Our current solution is adding a forward slash to the end of the startsWith parameter:

if (!existingProjectJsonDirectories.some((x) => projectFile.startsWith(x + '/')))

Github Repo

No response

Steps to Reproduce

  1. import a new project in the directory 'apps/example-app'
  2. run the import-projects generator so that 'app/example-app' contains a project.json
  3. import another project in the directory 'apps/example-app-test'
  4. run the import-projects generator
  5. the 'apps/example-app-test' project has no project.json

Nx Report

Node : 16.0.0
   OS   : win32 x64
   npm  : 9.6.0

   nx                      : 15.9.2
   @nrwl/js                : 15.9.2
   @nrwl/nx-plugin         : 15.9.2
   @nrwl/tao               : 15.9.2
   @nrwl/webpack           : 15.9.2
   typescript              : 4.9.5
   ---------------------------------------
   Community plugins:
   @nx-dotnet/core        : 1.22.0
   @nx-tools/nx-container : 4.0.3
   ---------------------------------------
   Local workspace plugins:
         @asw/tools

nx.json

{
  "$schema": "./node_modules/nx/schemas/nx-schema.json",
  "npmScope": "asw",
  "affected": {
    "defaultBase": "main"
  },
  "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": [
          "build",
          "lint",
          "test",
          "e2e"
        ]
      }
    }
  },
  "targetDefaults": {
    "build": {
      "dependsOn": [
        "^build",
        "generate-dotnet-sources",
        "generate-angular-sources"
      ],
      "inputs": [
        "production",
        "^production"
      ],
      "outputs": [
        "{workspaceRoot}/dist/{projectRoot}"
      ]
    },
    "test": {
      "inputs": [
        "default",
        "^production",
        "{workspaceRoot}/jest.preset.js"
      ]
    },
    "unit-test": {
      "dependsOn": [
        "build"
      ]
    },
    "docker": {
      "dependsOn": [
        "build"
      ]
    },
    "pack": {
      "dependsOn": [
        "build"
      ]
    },
    "run": {
      "dependsOn": [
        "build"
      ]
    },
    "e2e": {
      "inputs": [
        "default",
        "^production"
      ]
    },
    "lint": {
      "inputs": [
        "default",
        "{workspaceRoot}/.eslintrc.json"
      ]
    },
    "generate-dotnet-sources": {
      "executor": "@asw/tools:dotnet-api-to-dotnet-sources",
      "outputs": [
        "{projectRoot}/**/*"
      ],
      "dependsOn": [
        "^build"
      ]
    },
    "generate-angular-sources": {
      "executor": "@asw/tools:dotnet-api-to-angular-sources",
      "outputs": [
        "{projectRoot}/src/lib/*"
      ],
      "dependsOn": [
        "^build"
      ]
    }
  },
  "namedInputs": {
    "default": [
      "{projectRoot}/**/*",
      "sharedGlobals"
    ],
    "production": [
      "default",
      "!{projectRoot}/**/?(*.)+(spec|test).[jt]s?(x)?(.snap)",
      "!{projectRoot}/tsconfig.spec.json",
      "!{projectRoot}/jest.config.[jt]s",
      "!{projectRoot}/.eslintrc.json"
    ],
    "sharedGlobals": []
  },
  "workspaceLayout": {
    "appsDir": "apps",
    "libsDir": "libs"
  },
  "cli": {
    "packageManager": "npm"
  },
  "generators": {
    "@nrwl/angular": {
      "application": {
        "linter": "eslint"
      },
      "library": {
        "linter": "eslint"
      },
      "storybook-configuration": {
        "linter": "eslint"
      }
    },
    "@nrwl/angular:application": {
      "style": "scss",
      "linter": "eslint",
      "unitTestRunner": "jest",
      "e2eTestRunner": "cypress"
    },
    "@nrwl/angular:library": {
      "linter": "eslint",
      "unitTestRunner": "jest"
    },
    "@nrwl/angular:component": {
      "style": "scss"
    }
  },
  "plugins": [
    "@nx-dotnet/core",
    "@asw/tools"
  ],
  "defaultProject": "cicd-runtime-ui"
}

Failure Logs

No response

Additional Information

No response

@Take-Limeship Take-Limeship added bug Something isn't working needs-triage This issue has yet to be looked over by a core team member labels Apr 25, 2023
@AgentEnder
Copy link
Member

I'm fine with just adding the / to the end, can you open a PR?

@AgentEnder AgentEnder added scope: core and removed needs-triage This issue has yet to be looked over by a core team member labels Apr 25, 2023
Take-Limeship pushed a commit to Take-Limeship/nx-dotnet that referenced this issue Apr 26, 2023
AgentEnder pushed a commit that referenced this issue Apr 26, 2023
Co-authored-by: Takeru Yamazaki <takeru.yamazaki@admiral.at>
@github-actions
Copy link
Contributor

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working outdated scope: core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants