Skip to content

Commit

Permalink
docs(nx): 📝 add "multi-dimensional constraints" section
Browse files Browse the repository at this point in the history
  • Loading branch information
yjaaidi committed May 31, 2024
1 parent 651496c commit c7e0ace
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
5 changes: 3 additions & 2 deletions apps/cookbook/docs/nx/03-scaling/02-organize-libs.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,9 @@ or afterwards by updating the `tags` property in the `project.json` file:
Tags can be used to categorize libraries based on different criteria. They are useful for:

- [enforcing boundaries and architectural rules](./03-boundaries.md),
- or simply running tasks on specific categories of apps and libraries
_(e.g. `nx run-many -t test --projects=tag:my-category`)_,
- or simply running tasks on specific categories of apps and libraries _(e.g. `nx run-many -t test --projects=tag:my-category`)_.

These tags can be used to categorize libraries on different dimensions.

### Type Categories Dimension

Expand Down
23 changes: 22 additions & 1 deletion apps/cookbook/docs/nx/03-scaling/03-boundaries.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ The `depConstraints` option is a list of constraints that define which projects

### Defining a Constraint

The following constraint will allow libraries with the `type:ui` tag to **only** depend on libraries with either the `type:ui` or `type:model` tags:
Let's start with a constraint example. The following constraint will allow libraries with the `type:ui` tag to **only** depend on libraries with either the `type:ui` or `type:model` tags:

```json
"depConstraints": [
Expand Down Expand Up @@ -54,3 +54,24 @@ Note that if a project doesn't match any constraint _(i.e. `sourceTag`)_, the de

While this behavior can be overriden by adding a passthrough constraint: `{"sourceTag": "*", "onlyDependOnLibsWithTags": ["*"]}`, we do not recommend it as it could hide both configuration errors and constraints violations.
:::

### Multi-Dimensional Constraints

As presented in the [previous chapter](./02-organize-libs.md#tags-and-categories), it is possible to assign multiple tags to a library, each representing a different dimension _(e.g. `scope:catalog`, `type:ui`)_.

As **the eslint rule will check that all constraints matching the `sourceTag` are met**, you can define multi-dimensional constraints by adding multiple constraints with the `sourceTag` for each dimension.

As an example, the following constraints will allow libraries with the `type:ui` tag to only depend on libraries with either the `type:ui` or `type:model` tags, and libraries with the `scope:catalog` tag to only depend on libraries with either the `scope:catalog` or `scope:shared` tags:

```json
"depConstraints": [
{
"sourceTag": "scope:catalog",
"onlyDependOnLibsWithTags": ["scope:catalog", "scope:shared"]
},
{
"sourceTag": "type:ui",
"onlyDependOnLibsWithTags": ["type:ui", "type:model"]
}
],
```

0 comments on commit c7e0ace

Please sign in to comment.