-
Notifications
You must be signed in to change notification settings - Fork 843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stack install package --save to add a dependency to the cabal file #1933
Comments
The main issue is that there isn't currently a good way to refactor cabal files, as far as I know. Perhaps some heuristics could do a decent job. One reason I'm excited about hpack is that since it generates cabal files, this would be a great time to add in the version constraints - sol/hpack#61 . Alternatively, this could be done as a refactoring on the hpack yaml file, which seems like an easier format to automatically manipulate. I'm totally in favor of being able to automatically add constraints to cabal files, but someone would need to either write a munger that does this correctly or write a more generic system for automatic changes to cabal files. |
Hpack is great! It would resolve my use case if stack could automatically add deps to hpack's package.yaml, and then automatically regenerate the cabal file. I just really dislike having to manually edit configuration files :) |
I'm the most pumped about just omitting most version constraints from the package.yaml. This will helpfully call out which dependencies are manual constraints that have some particular reason for existing. Adding constraints while generating the cabal file would be consistent with some of hpack's other magic, such as inferring other-modules / exposed-modules / extra-source-files. We can also check in the cabal file, letting us know when the automatically generated constraints change. |
Here's another (+1) for this from the IRC channel:
…and my personal support. Editing and then building when I could've just told it "add this and build it" would be nicer. |
+1 it's a common feature in many package manager of other languages, and it was surprising to discover it's not implemented |
+1 |
I am new to stack and googled this exact functionality. Coming from the JS world, it is pretty common to use "npm install --save" to install libraries. It does save a lot of time. |
Big 👍 here as well |
Would love this as well. |
Suggest that what version bounds are added is determined with a flag such as If |
How would this interact with global-project? Would it save to global-project/stack.yaml or some global-project cabal file? |
Yep - it should be the same behaviour. |
+1 |
If someone wants to implement this, my suggestion would be to first implement the following:
Having this feature, but not as a proper refactoring, might motivate someone to do the full on support for yaml refactoring, which would require a parser that knows about layout and comments, and a exactprint implementation. Not trivial. Implementing just the proper refactoring would be less work than doing both, but it's a bit tricky, certainly a fair bit of code would need to be written. |
+1 to this, I'm new and was looking for a |
+1 |
needed |
It would be nice to have a way for stack to automatically add a package dependency to the cabal file using version bounds (in accordance to some accepted package versioning policy) which accept the current version of the package in the snapshot being used.
NPM provides such a functionality with
npm install --save <package>
which adds the dependency to the local package.json. So one possible command could bestack install --save <package>
.For example, if I want to use the
bound
package, and the current version in the snapshot is1.0.7
, then runningstack install --save bound
in the local package directory would addbound >= 1.0 && < 1.1
to the project cabal file (or something else, as long as it's consistent, and admits v1.0.7). The user is free to manually modify the version range in the cabal file later.If there are multiple sections in the cabal file where the dependency could be added, then perhaps the user can be prompted for each one with an
Add package 'bound >= 1.0 && < 1.1' to the dependency list for this section?
.The text was updated successfully, but these errors were encountered: