-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add mix deps.add
task
#10291
Add mix deps.add
task
#10291
Conversation
The only problem I see there is that such util will be very Hex-centric. Maybe it should be moved to the Hex itself? So it would be |
Hi @TheFirstAvenger, can you please send to for discussion to the mailing list? I believe it also has been discussed before. I personally worried about going the string matching route. There are just too many things that can go wrong. For example, someone can even define all deps inline such as |
I would lean towards |
Closing per the above, thank you! |
Just following my comment there: @TheFirstAvenger what about private repos? Or custom repos? What about other SCMs like Git? Or even custom ones? In current form |
If we were to support it, I think the usage could be similar to archive.install/escript.install, that is:
On the implementation side, we'd probably add a new callback to https://hexdocs.pm/mix/Mix.SCM.html. Usage aside, by far the biggest problem to solve is manipulating the mix.exs file, instead of working on strings we want to somehow work on code. As José alluded to, the most viable option seems to somehow plug into the formatter engine, we read some code, manipulate it, format it, and write it back. I have a proof of concept for such solution here: https://github.com/wojtekmach/fix (and deps.add "backend" here: wojtekmach/fix@895c76b). As again José mentioned the complexity with the formatter engine is it has a custom AST (a "formatter AST" if you will) that is private and can change any time so it's not a stable foundation to built upon. What I'm exploring next is a higher level tool, along the lines of https://engineering.fb.com/open-source/retrie/. Worth mentioning that even if we have a tool that can automatically rewrite AST, we won't be able to support all use cases for adding deps. Someone could have:
and the tool couldn't handle that, but that's probably OK to error in that case. Vast majority of cases would use "regular" deps. |
What problem is this feature trying to address? If this is about querying Hex then something like |
@stefanchrobot there is |
To answer "What problem is this feature trying to address?", I am picturing Elixir tutorials being more approachable by being able to say something like:
and get new users into writing code faster with less friction or possible confusion by having to parse through a mix.exs file before being able to do anything. For more advanced users, personally, I add things like Keying off what @stefanchrobot mentioned about simply outputting the lines to be added, I updated the branch to do this in cases where mix.exs is not formatted or the deps function could not be identified. I think this would mitigate the concern about the current string parsing method, and would allow us to add this feature sooner, and then in the future improve the detection based on work like what @wojtekmach mentioned he is pursuing if/when it is available. @hauleth On the idea that this is centered around hex, the only integration with hex is determining the latest version available, and since hex is already the default thing that elixir does when it sees a If you would like to continue discussions on this, I created a PR in my own fork with the new changes: TheFirstAvenger#2 |
I think this could be better served by integrating this into
It gets hairy when you want to pass more options. The upside is that the code generation will always work since it's starting with a clean slate. |
Add the
mix deps.add
task. Supports options such as:mix deps.add foo --version 1.2.3
mix deps.add foo
(pulls latest version from hex)mix deps.add foo --no-runtime
mix deps.add foo --only test --only dev
mix deps.add foo --path ../foo
Note: determining latest version from Hex is not yet implemented, defaults to >= 0.0.0. Would like to implement it before merging as it is one of the primary benefits of this feature. Looking to implement this using existing logic if possible instead of falling back to :httpc call.