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

Matching against transitive dependencies (enhance reachable rules) #763

Open
billiegoose opened this issue Mar 22, 2023 · 2 comments
Open
Labels
enhancement this will make dependency-cruiser sweeter

Comments

@billiegoose
Copy link

billiegoose commented Mar 22, 2023

Context

I am trying to figure out where my application is importing a very heavy npm module that should only imported by code that is behind a dynamic import and React.lazy, but for some reason it's getting bundled into the main index.js bundle.

Now eventually I'll find it, but I'd love to declare a rule to prevent this from happening again. I can catch if it is directly imported:

{
      from: {
        path: '^app',
      },
      to: {
        path: '^node_modules/big-heavy-library',
        dynamic: false,
      }
}

and I can catch when it is loaded transitively:

{
      from: {
        path: '^app',
      },
      to: {
        path: '^node_modules/big-heavy-library',
        reachable: true,
      }
}

but I cannot use reachable: true in combination with dynamic: false or with other qualifiers. (And it's not clear how dynamic: false would be interpreted unless combined with a qualifier like "all modules in the via chain", "some modules in the via chain", "no modules in the via chain")

Expected Behavior

I'd like to be able to match against the via modules, like:

{
      comment: "big-heavy-library must be behind a dynamic import",
      from: {
        path: '^app,
      },
      // none of the links in the chain are dynamic imports
      viaNot: {
        dynamic: true
      },
      to: {
        path: '^node_modules/big-heavy-library',
        reachable: true,
      }
}

Current Behavior

I can either catch transitive imports or static imports, but not static transitive imports.

Possible Solution

Considered alternatives

Make all transitive imports forbidden and use ignore-known... but first I gotta catch the one that's already in my app.

@github-actions
Copy link

github-actions bot commented Apr 1, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Apr 1, 2023
@sverweij sverweij removed the stale label Apr 3, 2023
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale label Apr 13, 2023
@sverweij sverweij added enhancement this will make dependency-cruiser sweeter and removed stale labels Apr 16, 2023
sverweij added a commit that referenced this issue Dec 25, 2023
…BREAKING for API users) (#895)

## Description

- Same as #888, but for the path detection algorithm underlying
'reaches' and 'reachable' rules

The addition to the _rule_ will be in a separate PR

## Motivation and Context

- fixing #763 - this PR is a prerequisite to implement the feature
requested in there
- feature parity with similar restrictions on cycles

## How Has This Been Tested?

- [x] green ci
- [x] updated automated regression tests
- [x] dog-fooding on dependency-cruiser

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [x] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing
functionality to change) => for API only

## Checklist

- [x] 📖

  - My change doesn't require a documentation update, or ...
  - it _does_ and I have updated it

- [x] ⚖️
- The contribution will be subject to [The MIT
license](https://github.com/sverweij/dependency-cruiser/blob/main/LICENSE),
and I'm OK with that.
  - The contribution is my own original work.
- I am ok with the stuff in
[**CONTRIBUTING.md**](https://github.com/sverweij/dependency-cruiser/blob/main/.github/CONTRIBUTING.md).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement this will make dependency-cruiser sweeter
Projects
None yet
Development

No branches or pull requests

2 participants