BartOtten

BartOtten

How to switch between local or Hex dependency?

For my public libs I have created demo apps. During development the demo app should depend on the development version of the library; so I use path: ../my_lib. However, when the demo app is cloned by a user it should depend on the Hex version instead.

Currently I set an environment flag which toggles the location of the dependency, but it keeps nagging in my head: this should be easier. Maybe detecting the existence of a file not committed to Git..?

Anyone having a better idea?

Ps. Detecting :dev runtime environment is not gonna cut it, as the user will probably run the demo in :dev too.

Most Liked

Nicodemus

Nicodemus

I do this in the demo for one of my projects, in “mix.exs”:

defp deps do
  [
    {:phoenix, "~> 1.7.14"},
    ...,
    my_lib_dep()
  ]
end

defp my_lib_dep() do
    if File.exists?(Path.join(__DIR__, "../my_lib/mix.exs")) do
      {:my_lib, path: "../my_lib"}
    else
      {:my_lib, "~> 0.1.0"}
    end
end

Or you can append an entire list to the end if you have multiple deps. The nice thing about “mix.exs” is that it’s code, and is executed every time you run mix.

BartOtten

BartOtten

Current implementation is like this. I did commit an .envrc file which sets the path. It seems checking path existence is the only ‘fully native’ solution. Combining it with env override and a warning might hit the sweet spot.

defp routex_dep() do
    if path = System.get_env("ROUTEX_PATH") do
      IO.puts(">> !! USING LOCAL ROUTEX PATH !! <<")
      {:routex, path: path}
    else
      {:routex, ">= 0.0.0"}
    end
  end
zachdaniel

zachdaniel

Creator of Ash

Something that might be useful is that Mix.env() returns :prod when your package is compiled for use in a user’s application.

So

@dependency if Mix.env() == :prod do
  {:package, "~> ..."}
else
  {:package, path: "..."}
end

Last Post!

sodapopcan

sodapopcan

Ya, I wasn’t clear on this—I actually have multiple in mine (two) and it’s only annoying as it adds to the grepping madness. Of course it’s simple to mitigate in different ways and you get used to it pretty quickly, it just adds another a thing you have to think about.

EDIT: I meant “I wasn’t clear on this.” Fixed.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 130286 1222
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New

We're in Beta

About us Mission Statement