question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

nx-enforce-module-boundaries for source project with multiple tags

See original GitHub issue

Prerequisites

I have a workspace that contains some projects with multiple tags likes below nx.json file

{
  "booking-api": {
    "tags": ["type:app", "scope:server", "service:booking"]
  },
  "booking-data-access": {
    "tags": ["service:booking", "scope:server"]
  },
  "booking-api-interfaces": {
    "tags": ["service:booking"]
  }
}

The enforce module boundaries rule is defined in the tslint.json file as below

"nx-enforce-module-boundaries": [
      true,
      {
        "allow": [],
        "depConstraints": [
          {
            "sourceTag": "service:booking",
            "onlyDependOnLibsWithTags": ["service:booking"]
          },
          {
            "sourceTag": "type:app",
            "onlyDependOnLibsWithTags": ["scope:shared", "scope:util"]
          },
          {
            "sourceTag": "scope:server",
            "onlyDependOnLibsWithTags": ["scope:server", "scope:shared", "scope:util"]
          },
          {
            "sourceTag": "scope:util",
            "onlyDependOnLibsWithTags": ["scope:util"]
          }
        ]
      }
    ]

From the booking-api app, I tried to import the data access from the booking-api-interfaces, I am getting an error

A project tagged with "type:app" can only depend on libs tagged with "scope:shared", "scope:util" (nx-enforce-module-boundaries)tslint(1)

Expected Behavior

booking-api and booking-data-access have same tag service:booking so we should allow import without error.

Current Behavior

Lint error that prevents importing. I think right now the link only check the first tag of the source project, so the service tag is ignored.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:22 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
meeroslavcommented, Sep 22, 2021

Nx boundary rules work as AND vertically and OR horizontally. In the following example:

[
  {
    "sourceTag": "scope:first",
    "onlyDependOnLibsWithTags": ["scope:second", "scope:third"]
  },
  {
     "sourceTag": "scope:first",
      "onlyDependOnLibsWithTags": ["type:one", "type:two", "type:three"]
  }
]

each project imported into project marked with scope:first will have to defined in nx.json with:

  • scope:second OR scope:third AND
  • type:one OR type:two OR type:three

At least one tag in the onlyDependOnLibsWithTags has to be satisfied (unless defined as *) and all of the rules apply.

In the original code from @hoang-innomizetech, he defined restriction for all type:app to only import scope:shared or scope:util (same for third rule for scope:server), but then tried to import booking-api-interfaces which included none of these.

If you get stuck, try reducing the tags and plan them carefully (correct naming is half of the work). If the boundaries start to feel too strict, you have probably overdone it.

2reactions
fbaba-nibtravelcommented, Jun 16, 2020

Hi, I’m having a similar issue. I’m trying to setup my project based on this article which is using a similar structure described on the initial issue. But this boundaries are not working as expected on both eslint and tslint.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Enforce Project Boundaries - Nx
Nx comes with a generic mechanism for expressing constraints on project dependencies: tags. First, use your project configuration (in project.json or package.
Read more >
Decomposing a project using Nx - Part 1 - This Dot Labs
2 approaches for decomposing a project ... You can find the source code on my repository. ... This is where Nx tags comes...
Read more >
Enforcing Dependency Constraints Within Service ... - HackMD
In the tslint.json notice, I am defining source tag for sales. Then I am also defining a source tag per project. For example...
Read more >
Fixing Nrwl Nx Monorepo Workspace Dependency Graph Error
“Error: A project without tags cannot depend on any libraries ... "nx-enforce-module-boundaries": [ true, ... There are 2 options.
Read more >
How does nx enforce module boundaries? | by Olavi Sau
The target project is where the imported file is in. It has gathered the constraints for the source project, by comparing each project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found