I always get annoying when I need to test something quickly, and need a HTTP client or other dependency, and the only way to get it, is to create a shell elixir project and add it as a dependency.
Also some projects that are long running and I do not want to build a release for, yet want to add a dependency to without killing the project and restarting it.
Anyway to do this or any initiative to add this to mix/iex?
You can add an
.iex.exs file to the root of your project to add any imports or aliases you want to load automatically when you start
The point is to be able to load em once IEX is running, and outside a project.
What I personally do is that I have a directory called “playground” with some dependencies and whenever I want to do HTTP requests or just play with ideas, that’s where I go to.
I understand the appeal of doing it from anywhere but global dependencies often cause more problems than they are worth it.
Elixir is pretty lenient in terms of code loading, why not use the httpc module (until baked in ElixirHttp arrives if it ever does) to pull dependencies directly from the web.
Like IEx.Helpers.require_dep “https://github.com/edgurgel/httpoison”
Assuming the mix.exs can be ignored, it would crawl the lib folder and Code.eval_string, the problem would just be properly resolving the evaluation order (maybe Kernel.ParallelCompile.compile/2 can be extended to support binaries of the module being passed). Indeed this would not load all libs (nifs, outside data/files), but the idea is for it to be a time saver. Kind of like how recompile/0 works.
The problem is not that simple. httpoison has dependencies, we need to fetch and compile those. So we can’t do any of this without Mix nor assume mix.exs can be ignored. And I am pretty sure installing each dependency per session would be just too much time consuming for most users. Httpoison requires 7 packages (including itself).
But again, it is not a practical issue, I am sure it can be implemented. The point is that global dependencies is not something we want to encourage.
By default this module ignores the certificates for HTTPS connections, unless properly configured to check them, thereby should not be encouraged it’s use.
To be honest, In my opinion I think it should have an CVE open against it. I am amazed how this issue have been ignored for so long
We don’t want to be in a position like python, where incredibly hacky solutions (like virtualenv, or, worse, virtualenv inside a docker) exist.
On the other hand, I think practically speaking it’s only a problem if you try to release something and expect a global dependency. And there have been times when I have wanted, say Jason, in a quick, needs-async, so I didn’t want to wrap my head around async bash, script I was writing. I wound up downloading jq and calling it from System.cmd.
Is there maybe a middle ground, where we can make it relatively easy to give someone global dependencies (if, say, the list is made explicit somewhere) which are never imported when there is a -S option in the command?