0

当我更新 nx.json 中的项目标签时,TSLint 似乎没有意识到标签已更改,并且即使违反了依赖项,也会检查并构建项目。

例子

目前我的 nx.json 文件看起来像

{
  "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": []
    }
  }
}

我的根 tslint.json 包括:

"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"
            ]
          }
        ]
      }
    ],

当我运行时,这会按预期通过 linting ng lint hep

但是,如果我编辑 nx.json 中的标签,则 linter 不会显示任何错误。例如,如果我将 nx.json 修改为如下所示(从库中删除标签),它仍然会 lints 并构建而不会出现任何错误。

{
  "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": []
    }
  }
}

如果它有用,当我更新 tslint.json 中的规则时,linter 确实会抛出错误,但我希望它也能确认对 nx.json 的更改。

有没有办法让 linter 在更新 nx.json 中的标签时显示错误?

4

3 回答 3

1

也可能是 VS Code 的缓存导致问题

在对 tslint.json 或 tsconfig.json 文件进行更改之前,您可能需要重新启动 Typescript 服务。

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

于 2020-02-21T06:43:19.443 回答
0

Nx 在生成的文件中缓存了一堆有关依赖项的信息:/dist/nxdeps.json

您只需删除此文件即可立即查看对 nx.json 的更改。

于 2020-02-18T23:29:40.573 回答
0

在 Webstorm 中,重新启动 typescript 服务没有帮助,但重新启动 IDE 会有所帮助(看起来像索引文件)。

就我而言,我在编辑 nx.json 时正在执行以下步骤:

  1. 删除目录node_modules/.cache/nx
  2. 运行nx lint(将生成新的缓存)
  3. 重启IDE
于 2021-12-15T14:04:07.460 回答