One thing to keep in mind: packwerk doesn’t do any analyses of dependencies within accepted dependencies. If it did that (memory prohibitive maybe)… or that could be activated, there are some other ideas as to what one could do:
• Generate a report showing how much two packages co-depend (count usages on one side and violations on the other) - might lead devs to flip dependency direction
• Use usage count + violation count as edge weights in a graph visualization
• Show a list of top 10 dependencies that could be removed via dep injection
I would imagine Packwerk would already have a lot of the code required to build such a feature. It already does stale dependency checks at the class level, so a stale check at the package level seems obvious - at least from afar
This has come up a couple of times in various forums… I can definitely see why we’d want it. It’s a bit tough architecturally in packwerk, because we only know what a package doesn’t need by doing a full scan, but packwerk checkers can only create violations/affect behavior for individual references.
It would be interesting if packwerk could call a method on each checker when the scan is finished, so checkers can spit out some warning/validation error of some kind.
Delete all dependencies from all packages (ParsePackwerk.all.each{|p| ParsePackwerk.write_package_yml!(p.with(dependencies: [], config: p.config.merge(dependencies: [])))})
bin/packwerk update
Get the dependency violations again, diff them to see what dependencies you need, rewrite them using similar command as in (2)
I can think of one way to automate this using existing tools.
Create a custom Packwerk::Checker. It never registers a violation – all it ever does is modify a file tmp/packwerk/references.yml that lists out the unique pack A => pack B references.
Create a custom Packwerk::Validator. It reads tmp/packwerk/references.yml and diffs pack A => pack B links with the stated dependencies. It raises a helpful error with what dependencies to remove when there is an unnecessary dependency listed.
Then, bin/packwerk check and bin/packwerk validate in sequence could automate this process in CI for you.