Merge behaviour in Mix.Config means removing things from Keyword lists is not possible

198 views
Skip to first unread message

Felipe Sere

unread,
May 27, 2019, 7:23:41 AM5/27/19
to elixir-lang-core
Hi y'all.


I set out to boot my Phoenix app on Travis-CI to run some cypress tests against it. Since it boots my `dev` env as normally (mix phx.server) I noticed that code-reloading and asset building was on.
It's not a massive issue, but I wanted to turn it off on ci.
So I went ahead and created a config file just for CI like so:

use Mix.Config

import_config "dev.exs"

config :advisor, AdvisorWeb.Endpoint,
  code_reloader: false,
  watchers: []


config :advisor, AdvisorWeb.Endpoint,
  live_reload: []

To my surprise, the watchers for asset building and code-reloading were still on.

Given that I import the dev.exs config, I thought I'd just be overwriting the watches and live_reload settings.
But, keyword lists are deep-merged with the config macro.
This is fine as long as you want to add things.
In my case, I wanted to explicitly remove things.
I resorted to duplicating my `dev.exs` instead of importing it.

I could imagine something like a specific keyword like :none or false to be used to let empty lists take priority when merging.
My config would then look something like this (or with false).

use Mix.Config

import_config "dev.exs"

config :advisor, AdvisorWeb.Endpoint,
  code_reloader: false,
  watchers: :none


config :advisor, AdvisorWeb.Endpoint,
  live_reload: :none 

I imagine merging multiple things could become a night-mare though?

Let me know what you think or if there are other solutions to my issue.

Cheers,
Felipe

José Valim

unread,
May 27, 2019, 7:35:26 AM5/27/19
to elixir-l...@googlegroups.com
Yes, Mix.Config always performs a deep merge. If you want to have something like live_reload: false or live_reload: :none, then Elixir will already giive it higher priority (we only deep merge keyword lists, otherwise the latest always wins), so you just need to make sure Phoenix supports it.


José Valim
Skype: jv.ptec
Founder and Director of R&D


--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4a8b1c7f-32f2-4b2a-b932-968465f0a695%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages