boundaries

Experimental

Boundaries 通过检查包管理器工作区违规来确保 Turborepo 功能正常工作。

¥Boundaries ensure that Turborepo features work correctly by checking for package manager Workspace violations.

Terminal
turbo boundaries

Boundaries RFC

此功能尚处于实验阶段,我们期待你对 边界 RFC 的反馈。

¥This feature is experimental, and we're looking for your feedback on the Boundaries RFC.

此命令将针对两种类型的违规触发通知:

¥This command will notify for two types of violations:

  • 导入包目录之外的文件

    ¥Importing a file outside of the package's directory

  • 导入包的 package.json 中未指定为依赖的包

    ¥Importing a package that is not specified as a dependency in the package's package.json

标签

¥Tags

Boundaries 还具有一项功能,可让你为包添加标签。这些标签可用于创建边界检查规则。例如,你可以将 internal 标签添加到你的 UI 包中:

¥Boundaries also has a feature that lets you add tags to packages. These tags can be used to create rules for Boundaries to check. For example, you can add an internal tag to your UI package:

Turborepo logo
./packages/ui/turbo.json
{
  "tags": ["internal"]
}

然后声明一条规则,规定带有 public 标签的包不能依赖于带有 internal 标签的包:

¥And then declare a rule that packages with a public tag cannot depend on packages with an internal tag:

Turborepo logo
./turbo.json
{
  "boundaries": {
    "tags": {
      "public": {
        "dependencies": {
          "deny": ["internal"]
        }
      }
    }
  }
}

或者,你可能希望 public 软件包仅依赖于其他 public 软件包:

¥Alternatively, you may want public packages to only depend on other public packages:

Turborepo logo
turbo.json
{
  "boundaries": {
    "tags": {
      "public": {
        "dependencies": {
          "allow": ["public"]
        }
      }
    }
  }
}

同样,你可以为标签的依赖(即导入带有该标签的包的包)添加限制。

¥Likewise, you can add restrictions for a tag's dependents, i.e. packages that import packages with the tag.

Turborepo logo
turbo.json
{
  "boundaries": {
    "tags": {
      "private": {
        "dependents": {
          "deny": ["public"]
        }
      }
    }
  }
}

软件包名称也可以在允许和拒绝列表中代替标签。

¥Package names can also be used in place of a tag in allow and deny lists.

Turborepo logo
turbo.json
{
  "boundaries": {
    "tags": {
      "private": {
        "dependents": {
          "deny": ["@repo/my-pkg"]
        }
      }
    }
  }
}

标签允许你确保不会在图表中的某个位置导入错误的包。这些规则甚至适用于依赖的依赖,因此如果你导入一个包,而该包又导入了另一个带有拒绝标签的包,你仍然会遇到规则违规。

¥Tags allow you to ensure that the wrong package isn't getting imported somewhere in your graph. These rules are applied even for dependencies of dependencies, so if you import a package that in turn imports another package with a denied tag, you will still get a rule violation.