Benjamin-Philip

Benjamin-Philip

I’m thinking of submitting yet another mix deps.add proposal. It has gotten to the point where I feel that such a simple and repetitive task could easily be shortened by adding a mix task for it. However, I have noticed that the Core team ignores/rejects such proposals. I tried look through the mails of the past 2 years and I haven’t found any explanation.

Here’s what I am going to propose:

mix deps.add will only be used for editing the Mixfile and adding a task. Added dependencies are only fetched with deps.get
By default, we would supply the package name, and we will add the latest version. For example:

mix deps.add ecto

Will add

{:ecto, "~> 3.6"}

at this point of time.

It will have the options of --version (to specify version) --git(to specify git repository) and --github (to specify GitHub repository)

So 2 things:

  1. Why are deps.add proposals rejected

  2. What do you think of this proposal ?

PS: This is my first post. Apologies if I violated any code of conduct.

Showing Posts 1 to 10

NobbZ

NobbZ

One of the main reasons is that such a task wouldn’t be able to work reliably, as the mix.exs is code, and not structured data.

Someone experimented with a tool that has written and read an external deps file.

Not sure if this is still findable on GitHub or perhaps even was released on hex.

Though AFAIK it never left the “experimental” status and is also considered problematic as it needs to be installed “globally”

LostKobrakai

LostKobrakai

The tricky question is: where should it be added exactly? Given mix.exs is code there could be any mounts of logic in the list of deps. Even the default of having dependencies listed in a helper function is just convention, but not in any way enforced.

derek-zhou

derek-zhou

Let’s not go down the route of node.js. I absolutely hate it when npm install change my package.json file and mess up the indentation.

Having a file that regularly needs to be modified by human and machine is asking for trouble.

12
Post #3
dorgan

dorgan

On top of what’s already been said, the amount of work you need to do to correctly insert the new dependency without messing up the rest of the code is a bit non trivial. Even if we make it work only in the case of the defp deps do ... convention, regex is unreliable and doing it by playing with the ast is quite a bit of work, even for this single use case. It is doable though.

Regarding the “deps could be anywhere besides deps”, this is one option:

You can make it bail out and give a good error message explaining why. If you’ve moved your deps away from the default, you’re already probably experienced enough to deal with it. This is letting niche use cases prevent usability improvements from the majority.

lud

lud

To me the best proposal would be to add a trailing comma in the one-click copy version on hex.pm. That’s it.

dimitarvp

dimitarvp

IMO getting something like mix deps.add to work reliably, we need a first-class engine for modifying Elixir code. @dorgan here is working on it. :heart:

Benjamin-Philip

Benjamin-Philip OP

I think we can only follow the convention of adding a dependency to the deps function.

When it comes to actually editing the file, the solution that came to mind is using some sort of regex. This though is unreliable albeit easy. I think using the AST is much more reliable, but I am not sure how you would do so. Any resources on editing the code programmatically is much appreciated.

stefanchrobot

stefanchrobot

I think the only way to reliably make this work is to introduce a plain data file - so something like deps.json. Everything else has the issue of having the need to evaluate the code. Not sure what are the exact requirements of .formatter.exs are, but it seems you can throw an if into that file and it just works. Same goes for mix.exs and a potential deps.exs.

And if you’re going to make it work in limited number of use cases - which also probably covers something like 90% of occurences - I think it makes sense to add it as an external package. You could mix install it just once and then just have a global task like phx.new.

hauleth

hauleth

Few examples of mix.exs for you to deduce how you would like to add the new dependency:

defmodule Foo.Mixfile do
  use Mix.Project

  def project, do: [app: :foo, version: "0.0.1"]
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [app: :foo, version: "0.0.1"]
  end
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [app: :foo, version: "0.0.1", deps: [{:mydep, ">= 0.0.0"}]]
  end
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: foos()
    ]
  end

  defp foos, do: []
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: deps(Mix.env())
    ]
  end

  defp deps(:dev) do
    []
  end

  defp deps(:test) do
    [{:benchee, ">= 0.0.0"}]
  end
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: deps(System.get_env("BENCH"))
    ]
  end

  defp deps(nil) do
    []
  end

  defp deps(_) do
    [{:benchee, ">= 0.0.0"}]
  end
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: deps()
    ]
  end

  defp deps do
    [{:foo, ">= 0.0.0"} | more_deps()]
  end

  defp more_deps() do
    [{:bar, ">= 0.0.0"}]
  end
end
defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: deps(System.get_env("BENCH"))
    ]
  end

  defp deps(nil) do
    []
  end

  defp deps(_) do
    [{:benchee, ">= 0.0.0"}]
  end
end
defmodule Foo.Mixfile do
  use Mix.Project

  @deps [{:foo, ">= 0.0.0"}]

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: @deps
    ]
  end
end
defmodule WhyNot do
  def deps, do: [{:foo, ">= 0.0.0"}]
end

defmodule Foo.Mixfile do
  use Mix.Project

  def project do
    [
      app: :foo,
      version: "0.0.1",
      deps: WhyNot.deps()
    ]
  end
end
13
Post #9
Benjamin-Philip

Benjamin-Philip OP

Thank you!

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
AstonJ
Since we have deprecated our Erlang sections (as we have dedicated Erlang Forums now) let’s add this thread for those who’d like to post ...
New
maennchen
:warning: Security advisory: Decimal DoS vulnerability A vulnerability has been published for decimal where very large exponents can cau...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews