BartOtten

BartOtten

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.

Showing Posts 1 to 10

sodapopcan

sodapopcan

This may not work for you but taking inspiration from Doggo, I package the demo app alongside the library in the same repo. While there some annoyances around grepping and how some editor tools handle nested mix.exs, it’s generally really convenient for everyone: 1) You can simply leave the dep as {:my_lib, path: ".."} in your demo’s mix.exs, 2) the demo repo is source controlled alongside the lib, and 3) when users only have to clone one repo to get everything.

I can imagine this isn’t always viable so I’m also interested in other options.

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.

sodapopcan

sodapopcan

I didn’t do it this way because it feels wrong to reach out into an unsuspecting user’s filesystem to execute code (at least from an unsanctioned directory). While I’m fully aware it’s super edge case, you never know what people have on their machines. For example, maybe they clone the example app into a directory where a long time ago they were experimenting with a mix project with the same name as your lib. Confusion ensues. It’s certainly an option, but I wish there was a more “official” way.

D4no0

D4no0

If you don’t like that option, you can always use a environment variable to achieve the same, the important point is as @Nicodemus mentioned: you can execute elixir code inside of mix.exs, which is a very powerful concept.

sodapopcan

sodapopcan

@BartOtten already mentioned the env variable approach which I do like better. I’m certainly aware mix.exs is just code which I thought was implied by my saying I already considered @Nicodemus’s approach (well, same goes for checking an env var, really).

D4no0

D4no0

Indeed, after reading it again I misunderstood the question.

Addressing your previous concerns, just opening a project with a LSP carries risk of executing stuff you are unaware of, especially since elixir metaprogramming allows execution of code at compile-time.

BartOtten

BartOtten OP

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
D4no0

D4no0

If the solution works without many hitches, what is inherently wrong with it?

I guess you could use a mix task to ask the user the default option before he starts the project, but I don’t see that as a much better approach.

BartOtten

BartOtten OP

Not much. But as I can imagine others having the same use case, I wondered if there would be a better way.

And because I rather have a minimum of helper apps (such as direnv).

BartOtten

BartOtten OP

—nvm—..

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews