Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: add rule nx enforce-module-boundaries #1325

Merged
merged 3 commits into from Dec 20, 2023
Merged

Conversation

derschnee68
Copy link
Collaborator

resolves DEV-

Copy link
Contributor

@irmastnt irmastnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of relative paths, hope it will not give as problems with webpack in the future. Merge it according to the best of your knowledge.

BTW, tried to ask chat GPT, this is what I've got:

In an Nx workspace, enforcing module boundaries is a helpful practice for maintaining a clean and scalable codebase. However, there might be cases where you need to use absolute paths without triggering the Nx rule enforce-module-boundaries. To achieve this, you can follow these steps:

1. Configure tsconfig.base.json:

In your Nx workspace, you have a tsconfig.base.json file. Configure the compilerOptions section to include the "baseUrl" and "paths" options. Here's an example:

{
  "compilerOptions": {
    // other options...

    "baseUrl": "./src",
    "paths": {
      "@your-app/*": ["app/*"]
      // Add more path aliases as needed
    }
  }
}

This configuration sets up a base URL for your TypeScript compiler and defines a path alias (@your-app/*) that maps to the app/* directory. Adjust the alias and paths according to your project structure.

2. Use the Aliases in Imports:

Now, you can use these aliases in your import statements. For example:

// Before
// import { SomeComponent } from '../../../path-to-component';

// After
import { SomeComponent } from '@your-app/some-component-path';

3. Configure Nx Workspace Rules:

In your nx.json file, configure the implicitDependencies section to explicitly define module boundaries:

{
  // other options...
  
  "projects": {
    "your-app": {
      // other options...

      "implicitDependencies": {
        // Define module boundaries explicitly
        "tsconfig.base.json": ["!**"]
      }
    }
  }
}

This configuration tells Nx not to enforce module boundaries based on tsconfig.base.json. Adjust the project name (your-app) and the rules according to your project structure.

4. Run Nx Commands:

Now, you should be able to use absolute paths without triggering the enforce-module-boundaries rule. When running Nx commands, such as nx lint or nx build, Nx will respect the configured module boundaries.

Keep in mind that bypassing module boundaries should be done cautiously, as enforcing them helps maintain a well-organized codebase. Only use this approach when necessary, and make sure to communicate any deviations from the standard practices with your team.

@derschnee68 derschnee68 changed the title refactor: remove rule nx enforce-module-boundaries for now refactor: add rule nx enforce-module-boundaries Dec 20, 2023
@derschnee68 derschnee68 merged commit 1b1fd77 into main Dec 20, 2023
14 checks passed
@derschnee68 derschnee68 deleted the julien/eslint branch December 20, 2023 08:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants