ash-project / igniter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Support adding unversioned dependencies in `Igniter.Project.Deps.add_dependency/4`.

ibarakaiev opened this issue · comments

Is your feature request related to a problem? Please describe.
An outside caller might want to add a dependency without fixing a particular version when adding a dependency to an igniter.

Describe the solution you'd like
It should be possible to reuse determine_dep_type_and_version/1 in Igniter.Util.Install to fetch the version from hex.pm and fill in the version, if it's not provided in Igniter.Project.Deps.add_dependency/4.

I worry about making network calls any time aside from the igniter.install step at the beginning, feels like it could really degrade the user experience. I think it is better to do something like add_depedency(igniter, :package, "~> 1.0"), because if you're generating code I think its safe to assume that if they release a new major version of that package that your generators may be out of date. In fact, ash_money itself explicitly depends on ex_money_sql matching ~> 1.0.

So I think its best to leave this as it is now, and in your other PR update it to

|> Igniter.Project.Deps.add_dependency(:ex_money_sql, "~> 1.0")

Adding "~> 1.0" will cause mix to install the latest matching version, which means it should be a win-win.

As an option, what if we support the following functionality:

  • if a version is not passed and the dependency is not yet in mix.exs, we add "~> 0.0".
  • if a version is not passed and dependency is already in mix.exs, we skip (i.e. just use whatever version is already in mix.exs).

For example, if ex_money_sql is already in mix.exs with whatever version, Igniter.Project.Deps.add_dep(igniter, :ex_money_sql) won't add it, but if it's not it will add {:ex_money_sql, "~> 0.0"}.

I don't like the idea of versionless dependencies, personally. We can't use ~> 0.0 regardless, as that won't match any post 0.x versions. You'd need to do >= 0.0.0.

iex(1)> Version.match?("1.0.0", "~> 0.0")
false
iex(2)> Version.match?("1.0.0", ">= 0.0.0")
true

This can be achieved using a mix of get_dependency_declaration and add_dep with {:dep_name, ">= 0.0.0"}