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.

enforce-module-boundaries - Support secondary entry points in workspace libraries

See original GitHub issue

Description

Currently the enforce-module-boundaries only looks at project level and not at the entry points for workspace libraries. This means that when using secondary entry points and importing between libraries can result in a circular dependency between projects.

Using the following library structure:

   .
   ├── ...
   ├── libs
   │   ├── api
   │   |   └── src/lib
   |   │     └── services
   |   └── util
   │       └── src/lib
   │          ├── logging
   │          └── validation
   ├── ...

With the following paths in TSConfig.base:

"paths": {
   "@api/service": ["libs/api/src/lib/service"],
   "@util/logging": ["libs/util/src/lib/logging"],
   "@util/validation": ["libs/util/src/lib/validation"]
 }

Using the logging module in service while using the service module in validation results in a circular dependency between projects. Error:

 Circular dependency between "util" and "api" detected: util -> api -> util
 
 Circular file chain:
 - libs/util/src/lib/validation/validator.ts
 - [
    libs/api/src/lib/services/reference/reference-service.ts
   ]

Motivation

Normally this would be correct, but since I am using secondary entrypoints in my libraries (index.ts in each separate folder with a TSConfig path pointing to it) I do not reference the whole project, what should mean there is no circular dependency. The linting rule should not throw a Circular dependency detected error.

Suggested Implementation

Since the current implementation of a creating a secondary entry point for a library only works with buildable & publishable libraries (it requires a package.json in the library itself), the feature should be extended to also support workspace libraries.

Alternate Implementations

An alternative option would be to be able to configure the linting rule to check for the actual import instead of only looking at projects. The only catch is that this should be configurable per project, since not all projects within the monorepo will use the secondary entry points.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RobinvanTienhovencommented, Jun 20, 2022

My apologies for the late response. I think you are right about ‘making the linter understand’ is not the right thing to do and that our implementation is wrong. We’ve decided to further look into this and restructure our libraries to fix this issue the correct way.

Thank you for the help!

0reactions
meeroslavcommented, Jun 21, 2022

Thank you @RobinvanTienhoven for follow-up. I will therefore close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Secondary entry points in an Angular Nx library - Olof Enström
This post will show you how to leverage the power of secondary entry points, described by Google developer expert Tomas Trajan as “The...
Read more >
Enforce Project Boundaries - Nx
Nx provides an enforce-module-boundaries eslint rule that enforces the public API of projects in the repo. Each project defines its public API in...
Read more >
Starting Angular Projects With Nx - Offering Solutions Software
In this blog post I want to write down one possible way to start and architecture Angular projects using the nx. I know...
Read more >
nrwl-nx/community - Gitter
Hello, I have nx workspace with 4 applications and 2 publishable libraries. I'm struggling with configuring the continuous deployment. I'm using Github Actions ......
Read more >
Effective React Development with Nx
In chapter 2 we build new libraries to support a book listing feature. ... entry for @nrwl/nx/enforce-module-boundaries as follows.
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