Stack: Detect unused dependencies

Created on 19 May 2015  Â·  9Comments  Â·  Source: commercialhaskell/stack

Would be nice. Based on whatever code we're using to detect dependencies for the setup code, we could use that to detect what's _not_ being used to aid in cleaning up dependencies.

awaiting pull request help wanted enhancement

Most helpful comment

Here's a cool project that does this: https://github.com/afcady/packunused

Perhaps it could be integrated with stack? It does need to be compiled with the version of Cabal used in the user's project, though (whereas stack does not need to be compiled with the same Cabal version).

All 9 comments

About this. One idea that's come to mind is for Setup and possibly other modules keep a listing of all projects that use stack. Then a "garbage collect" could check items in the listing to see if they still exist. The listing could then be used to determine what stays, and everything else goes.

As noted in #1667, it would be good to involve this check in sdist / upload.

Here's a cool project that does this: https://github.com/afcady/packunused

Perhaps it could be integrated with stack? It does need to be compiled with the version of Cabal used in the user's project, though (whereas stack does not need to be compiled with the same Cabal version).

Perhaps it could be integrated with stack? It does need to be compiled with the version of Cabal used in the user's project, though

@mgsloan Is that really the case? It seems to me that you just have to compile with -ddump-minimal-imports and then packunused picks up the (text format) outputs, or am I misunderstanding?

There also does seem to be support for stack, e.g. packunused --help from https://github.com/hvr/packunused/pull/23 prints:

In order to use this tool you should set up the package to be analyzed as
follows, before executing 'packunused':

For stack:  stack clean
            stack build --ghc-options=-ddump-minimal-imports
            packunused

Only problem with GHC 8: https://ghc.haskell.org/trac/ghc/ticket/12474

@mgsloan Is that really the case? It seems to me that you just have to compile with -ddump-minimal-imports and then packunused picks up the (text format) outputs, or am I misunderstanding?

Could be! Worth giving it a try. I just saw that it's using lots of stuff from Cabal, and figured that the versions would need to match

The GHC ticket, and packunused were both fixed.

Trying to move this one along via https://github.com/hvr/packunused/issues/27.

Another option - https://hackage.haskell.org/package/weeder!

Nothing moved along much with the packunused plan. Don't think people had time.

Given that external tooling like weeder addresses this now, let's call this out of scope.

Was this page helpful?
0 / 5 - 0 ratings