Giter Site home page Giter Site logo

Comments (7)

aackerman avatar aackerman commented on June 20, 2024 2

onDetected is for advanced usage, you're on your own for everything aside from detection. It's very easy to exclude modules you don't want to see.

new CircularDependencyPlugin({
  onDetected({ module: webpackModuleRecord, paths, compilation }) {
    if (!/(node_modules|bower_components)/.test(webpackModuleRecord.resource)) {
      compilation.errors.push(new Error(paths.join(' -> ')));
    }
  }
})

from circular-dependency-plugin.

j3tan avatar j3tan commented on June 20, 2024 1

Whoops, just realized it is commented in the example. Maybe have separate examples?

from circular-dependency-plugin.

aackerman avatar aackerman commented on June 20, 2024 1

I went ahead and split this up in 4.2.1 to make it even more clear

from circular-dependency-plugin.

oomathias avatar oomathias commented on June 20, 2024

Same here, I got confused when defining onDetected.
2 distinct examples would be better for those, like me, who didn't read everything 🤦‍♂️

from circular-dependency-plugin.

vikasraj789 avatar vikasraj789 commented on June 20, 2024

@aackerman
version: 4.4.0
The issue of exclude option not being honoured when onDetected is available still exists.
Below is the configuration:

new CircularDependencyPlugin({
        exclude: /(node_modules|bower_components)/,
        // `onDetected` is called for each module that is cyclical
        onDetected({ module: webpackModuleRecord, paths, compilation }) {
          // `paths` will be an Array of the relative module paths that make up the cycle
          // `module` will be the module record generated by webpack that caused the cycle
          compilation.errors.push(new Error(paths.join(' -> ')));
        }
      }),

from circular-dependency-plugin.

LoicGombeaud avatar LoicGombeaud commented on June 20, 2024

First of all, thanks a lot for this module!
Regarding the exclude / onDetected confusion: is there any chance you could also put the exclude logic before onDetected gets fired on version 4 of the module? I know I can do the exclusion manually in onDetected, but it would save a few lines and be cleaner if it was in the dedicated exclude option instead.

from circular-dependency-plugin.

abirmingham avatar abirmingham commented on June 20, 2024

For posterity - it appears that exclude logic is now executed prior to firing onDetected. I am using [email protected] and saw a reduction in detections by adding exclude: /node_modules/, to the following configuration:

Configuration

        new CircularDependencyPlugin({
            failOnError: true,
            onStart({ compilation }) {
                circularDepCycles = [];
            },
            onDetected({ module: webpackModuleRecord, paths, compilation }) {
                circularDepCycles.push(
                    new Error(
                        `Circular dependency detected:\n${paths.join(' -> ')}`,
                    ),
                );
            },
            onEnd({ compilation }) {
                const count = circularDepCycles.length;
                if (count > MAX_CIRCULAR_DEP_CYCLES) {
                    circularDepCycles
                        .slice(MAX_CIRCULAR_DEP_CYCLES)
                        .forEach(error => {
                            compilation.errors.push(error);
                        });
                    compilation.warnings.push(
                        new Error(
                            `Circular dependency count exceeds allowed ` +
                                `threshold ` +
                                `(${count} > ${MAX_CIRCULAR_DEP_CYCLES})`,
                        ),
                    );
                }
            },
        }),

(Note that I believe that failOnError is ignored here due to the presence of onDetected - it just so happened to be set when I ran these tests)

from circular-dependency-plugin.

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.