Check version on --if-missing, closes #5 Co-authored-by: José Valim <jose.valim@dashbit.co>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
diff --git a/lib/mix/tasks/sass.install.ex b/lib/mix/tasks/sass.install.ex
index 073d7ca..d65c832 100644
--- a/lib/mix/tasks/sass.install.ex
+++ b/lib/mix/tasks/sass.install.ex
@@ -23,7 +23,7 @@ defmodule Mix.Tasks.Sass.Install do
def run(args) do
case OptionParser.parse_head!(args, strict: [if_missing: :boolean]) do
{opts, []} ->
- if opts[:if_missing] && DartSass.installed?() do
+ if opts[:if_missing] && latest_version?() do
:ok
else
if Code.ensure_loaded?(Mix.Tasks.App.Config) do
@@ -42,4 +42,9 @@ defmodule Mix.Tasks.Sass.Install do
""")
end
end
+
+ defp latest_version?() do
+ version = DartSass.configured_version()
+ match?({:ok, ^version}, DartSass.bin_version())
+ end
end
diff --git a/test/dart_sass_test.exs b/test/dart_sass_test.exs
index c81f9ec..796296f 100644
--- a/test/dart_sass_test.exs
+++ b/test/dart_sass_test.exs
@@ -1,15 +1,35 @@
defmodule DartSassTest do
use ExUnit.Case, async: true
+ @version "1.38.1"
+
test "run on default" do
assert ExUnit.CaptureIO.capture_io(fn ->
assert DartSass.run(:default, ["--version"]) == 0
- end) =~ "1.38.1"
+ end) =~ @version
end
test "run on profile" do
assert ExUnit.CaptureIO.capture_io(fn ->
assert DartSass.run(:another, []) == 0
- end) =~ "1.38.1"
+ end) =~ @version
+ end
+
+ test "updates on install" do
+ Application.put_env(:dart_sass, :version, "1.36.0")
+
+ Mix.Task.rerun("sass.install", ["--if-missing"])
+
+ assert ExUnit.CaptureIO.capture_io(fn ->
+ assert DartSass.run(:default, ["--version"]) == 0
+ end) =~ "1.36.0"
+
+ Application.delete_env(:dart_sass, :version)
+
+ Mix.Task.rerun("sass.install", ["--if-missing"])
+
+ assert ExUnit.CaptureIO.capture_io(fn ->
+ assert DartSass.run(:default, ["--version"]) == 0
+ end) =~ @version
end
end