Code Monkey home page Code Monkey logo

Comments (7)

fongandrew avatar fongandrew commented on July 28, 2024 1

I tested it out. Works exactly as expected for our use case. Thank you very much!

from dependency-cruiser.

sverweij avatar sverweij commented on July 28, 2024 1

Awesome! I've merged the PR and published it as part of [email protected]

from dependency-cruiser.

sverweij avatar sverweij commented on July 28, 2024

hi @fongandrew thanks for this suggestion - there's currently indeed no elegant way to distinguish dynamic imports in rules, and there should be. Especially when dependency-cruiser will start recognizing dynamic imports with arguments that can only be determined at runtime (which is on the backlog )

They way I'm thinking to do this is to flag dynamic dependencies so they can be used in rules e.g. something like this:

{
  forbidden: [
    {
      name: "no-circular",
      from: {
      },
      to {
        dynamicImport: false, //
        circular: true
      }
  ]

from dependency-cruiser.

fongandrew avatar fongandrew commented on July 28, 2024

Ooh, that rule syntax would be perfect. Looking forward to it!

from dependency-cruiser.

sverweij avatar sverweij commented on July 28, 2024

hi @fongandrew - it's taken some time to address this issue; had to get #142 out the door first...

I've implemented my proposal above. It works, but it I realised it likely won't resolve the issue you have (see below) unless all the dependencies in a circle are dynamic ones (see background below).

The dynamic attribute is probably going to stay because it's useful for other things, but I'm looking into a different solution for this issue (several ideas; including the followDynamic switch you proposed above - will ping you with one(s?) that works out).

background below

Given this dependency-graph...
sample

...with a rule that forbids circular dependencies, except for dynamic ones ...

module.exports = { 
    forbidden: [{
            name: 'no-circular',
            severity: 'warn',
            from: {}, 
            to: {
                circular: true,
                dynamic: false
            }
    }]
}

... the result would be:
sample

Close. No cigar ...

from dependency-cruiser.

fongandrew avatar fongandrew commented on July 28, 2024

Oh, that's unfortunate, but I appreciate you taking the time to figure this out!

from dependency-cruiser.

sverweij avatar sverweij commented on July 28, 2024

hi @fongandrew so here's another stab, that works better in your use case - it excludes all dependencies that are dynamic:

module.exports = {
  forbidden: [{
    name: 'no-circular',
    from: {},
    to: {
      circular: true
    }
  }],
  options: {
    exclude: {
      dynamic: true
    }
  }
}

This now works in [email protected], so if you want to you can give it a spin you can. I'll be interested in your findings!

from dependency-cruiser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.