dfithian / prune-juice

Prune unused Haskell dependencies.
MIT License
48 stars 4 forks source link

Apply the detected changes #12

Closed dfithian closed 2 years ago

dfithian commented 3 years ago

Fixes #6

Apply the proposed changes.

If you specify --apply, it will ask for confirmation after printing the results for every target. If you also specify --no-verify, it will apply the changes without confirmation. Haven't actually tested this part yet, but that's the way it should work.

One caveat here is that the pretty printing of the package description is different than the input file in a lot of cases, so it will mess up the .cabal file in question. Also I made it ignore package.yaml files. Maybe both of those things should be warnings.

Checklist:

dfithian commented 2 years ago

As of the last commit, I tested it like this:

  1. add transformers as a dependency to prune-juice.cabal
  2. run stack run -- prune-juice --apply apply-no-verify --apply-strategy smart
  3. ~it correctly removed the dependency from the file, however it slightly changed the format Screen Shot 2021-11-08 at 2 01 29 PM~ EDIT this is no longer true.
dfithian commented 2 years ago

@mirko-plowtech do you think this fixes your issue? You can test it out by running the following:

stack run -- prune-juice --apply

If you don't want it to prompt before applying, run

stack run -- prune-juice --no-verify

If it messes up your .cabal file, you can try running in "safe" mode with

stack run -- prune-juice --apply --apply-strategy safe
dfithian commented 2 years ago

I attempted this on my company's cabal files, which use common stanzas, and it didn't apply any of the changes. So I'll try to parse the common stanzas.

mirko-plowtech commented 2 years ago

@mirko-plowtech do you think this fixes your issue? You can test it out by running the following:

stack run -- prune-juice --apply

If you don't want it to prompt before applying, run

stack run -- prune-juice --no-verify

If it messes up your .cabal file, you can try running in "safe" mode with

stack run -- prune-juice --apply-strategy safe

Sorry the delay, I will try to test it this weekend =)

dfithian commented 2 years ago

I'm going to merge this so that some other contributions can be merged on top of it.