【问题标题】:How can I force nrwl nx to respect tag updates?如何强制 nrwl nx 尊重标签更新?
【发布时间】:2020-06-02 19:42:40
【问题描述】:

当我更新 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"
            ]
          }
        ]
      }
    ],

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

但是,如果我编辑 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 中的标签时显示错误?

【问题讨论】:

    标签: tslint nrwl nrwl-nx


    【解决方案1】:

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

    就我而言,我在编辑 nx.json 时正在执行这样的步骤:

    1. 删除目录node_modules/.cache/nx
    2. 运行nx lint(将生成新缓存)
    3. 重启IDE

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

      • 谢谢,这很有帮助。对我来说,它不会破坏 Nx 创建的缓存,但确实可以让 VS 代码理解更新,这与删除 Nx 缓存没有效果一样棒。这个答案和最后一个答案的组合可以解决所有问题。
      【解决方案3】:

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

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

      【讨论】:

        猜你喜欢
        • 2019-12-14
        • 2022-08-14
        • 2018-05-26
        • 2018-08-25
        • 2020-02-02
        • 1970-01-01
        • 2022-01-21
        • 2018-10-30
        • 2020-02-05
        相关资源
        最近更新 更多