0

When I update project tags in nx.json, TSLint seems unaware that the tags have changed, and lints and builds the project even though the dependencies are violated.

Example

Currently my nx.json file looks like

{
  "npmScope": "patient-engagement",
  "implicitDependencies": {
    "package.json": "*",
    "tsconfig.json": "*",
    "nx.json": "*"
  },
  "projects": {
    "hep": {
      "tags": ["scope:hep", "compatibility:ie10"],
      "implicitDependencies": []
    },
    "mb-ui": {
      "tags": ["scope:shared", "compatibility:ie10"],
      "implicitDependencies": []
    },
    "utils": {
      "tags": ["scope:shared", "compatibility:ie10"],
      "implicitDependencies": []
    }
  }
}

And my root tslint.json includes:

"nx-enforce-module-boundaries": [
      true,
      {
        "enforceBuildableLibDependency": true,
        "allow": [],
        "depConstraints": [
          {
            "sourceTag": "scope:hep",
            "onlyDependOnLibsWithTags": [
              "scope:hep",
              "scope:shared"
            ]
          },
          {
            "sourceTag": "compatibility:ie10",
            "onlyDependOnLibsWithTags": [
              "compatibility:ie10"
            ]
          },
          {
            "sourceTag": "scope:shared",
            "onlyDependOnLibsWithTags": [
              "scope:shared"
            ]
          }
        ]
      }
    ],

This passes linting as expected when I run ng lint hep.

However, if I edit the tags in nx.json, the linter does not show any errors. For example, if I modify nx.json to look like this (removing tags from the libraries), it still lints and builds without any errors.

{
  "npmScope": "patient-engagement",
  "implicitDependencies": {
    "package.json": "*",
    "tsconfig.json": "*",
    "nx.json": "*"
  },
  "projects": {
    "hep": {
      "tags": ["scope:hep", "compatibility:ie10"],
      "implicitDependencies": []
    },
    "mb-ui": {
      "tags": [],
      "implicitDependencies": []
    },
    "utils": {
      "tags": [],
      "implicitDependencies": []
    }
  }
}

If it's useful, when I update the rules in tslint.json, the linter DOES throw errors, but I would like it to also acknowledge changes to nx.json.

Is there a way I can get the linter to show errors when tags in nx.json are updated?

Dave Molinero
  • 474
  • 1
  • 4
  • 13

3 Answers3

1

Nx caches a bunch of information concerning dependencies in generated file: /dist/nxdeps.json

You can simply delete this file to immediately see changes to nx.json.

Dave Molinero
  • 474
  • 1
  • 4
  • 13
1

It could also be VS Code's caching causing problems

You might need to restart the Typescript service before changes to tslint.json or tsconfig.json files go through.

ctrl + shift + p and then Typescript: Restart TS Server

Leon Radley
  • 7,596
  • 5
  • 35
  • 54
  • 1
    Thanks, that is helpful. For me it doesn't bust the cache Nx creates, but does get VS code to understand the updates, which is great as deleting the Nx cache did not. The combination of this answer and the last one take care of everything. – Dave Molinero Feb 21 '20 at 21:35
0

In Webstorm, restarting the typescript service does not help but restarting IDE helps (looks like indexing files).

In my case, I am doing steps like this when editing nx.json:

  1. Remove dir node_modules/.cache/nx
  2. Run nx lint (will generate new cache)
  3. Restart IDE