From 5d4f97a8549c19e61d5633d1166e53a5d856b3d7 Mon Sep 17 00:00:00 2001 From: Jay Hayes Date: Fri, 4 Jan 2019 08:57:15 -0600 Subject: [PATCH] Make code loading compatible and deprecation free on old and new elixirs --- lib/watcher.ex | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/watcher.ex b/lib/watcher.ex index a183cad..6839b55 100644 --- a/lib/watcher.ex +++ b/lib/watcher.ex @@ -24,7 +24,7 @@ defmodule Watcher do if Path.extname(file) == ".ex" do try do file - |> Code.compile_file() + |> portable_load_file |> Enum.map(&elem(&1, 0)) |> Enum.find(&Runner.koan?/1) |> Runner.modules_to_run() @@ -35,6 +35,17 @@ defmodule Watcher do end end + # Elixir 1.7 deprecates Code.load_file in favor of Code.compile_file. In + # order to avoid the depecation warnings while maintaining backwards + # compatibility, we check the sytem version and execute conditionally. + defp portable_load_file(file) do + if Version.match?(System.version(), "~> 1.7") do + Code.compile_file(file) + else + Code.load_file(file) + end + end + defp normalize(file) do String.replace_suffix(file, "___jb_tmp___", "") end