Eiji
Elixir proposal: optional dependencies for deploy
How about add optional dependencies?
defmodule MyApp.MixFile do
use Mix.Project
def project do
[
app: :my_app,
version: "0.1.0",
elixir: "~> 1.4",
elixirc_paths: elixirc_paths(Mix.env),
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
aliases: aliases(),
deps: deps(),
optional_deps: optional_deps(),
]
end
# ...
end
and example code:
defmodule MyApp.Things.Special do
@behavior MyApp.Thing
# don't compile this module if we don't have an optional library
@module_depends_on: :optional_library
def example(), do: OptionalLibrary.example()
# or:
# don't compile this method if we don't have an another optional library
@depends_on: :another_optional_library
def something(), do: AnotherOptionalLibrary.something()
end
mix deps.get should ask if we want an optional dependency in our setup.
Here I think like Gentoo user. In this source based distribution we can choose USE flags so we can compile package for example: with sound support and without bluetooth support. Of course it’s only simple example that probably should be more explained and discussed.
What do you think about my idea? Maybe instead of choosing packages we should choose something like USE flags, so we could provide easy pre-setup for deployment administrators?
Most Liked Responses
josevalim
We already support optional dependencies by specifying optional: true in your dependencies and then you can use something like if Code.ensure_loaded?(ModuleInADep) to check if a dependency is available or not.








