aackerman / circular-dependency-plugin

Detect circular dependencies in modules compiled with Webpack
https://www.npmjs.com/package/circular-dependency-plugin
ISC License
914 stars 46 forks source link

Log to file? #78

Open Nantris opened 3 years ago

Nantris commented 3 years ago

We tried wiring things up to have a file generated at startup, but unfortunately we can't find a way to prevent the plugin from constantly re-creating the files when the project is refreshed. If we try something like setting isCompleted = true inside of onEnd() - but isCompleted ends up being set to true before we'd expect and so no report files are generated. I looked at the code but can't figure out what might cause this. Maybe there's something I don't understand about how Webpack runs plugins?

Nantris commented 3 years ago

Hard to guess... But logging to a file I found that the order of operations looks like this on startup:

  1. onStart <<< What's going on here?
  2. onEnd <<< What's going on here?
  3. onStart
  4. onDetected (however many times a circular dependency is detected
  5. onEnd

Anybody have any insights?

I was guessing maybe this has to do with multiple entry points, but we have three entry points and only two instances of onStart and onEnd.

Nantris commented 3 years ago

The only workaround we can find is to do this in onEnd

if (numCyclesDetected) isCompleted = true;

When we do this, we avoid the false instant-completion from the initial onStart/onEnd runs. I have no idea what might cause this, but the workaround works, at least somewhat.