Fix installation path/unzip on windows (#3) * Fix path to windows .zip archive * Fix unpacking .zip archive
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 01a3d99..3c6ad17 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## v0.1.1 (Unreleased)
+ * Fix installation path/unzip on windows
* Add wrapper script to address zombie processes
## v0.1.0 (2021-07-25)
diff --git a/lib/dart_sass.ex b/lib/dart_sass.ex
index db2bca7..2088d1f 100644
--- a/lib/dart_sass.ex
+++ b/lib/dart_sass.ex
@@ -210,9 +210,9 @@ defmodule DartSass do
name = "dart-sass-#{version}-#{target()}"
url = "https://github.com/sass/dart-sass/releases/download/#{version}/#{name}"
- tar = fetch_body!(url)
+ archive = fetch_body!(url)
- case :erl_tar.extract({:binary, tar}, [:compressed, cwd: tmp_dir]) do
+ case unpack_archive(Path.extname(name), archive, tmp_dir) do
:ok -> :ok
other -> raise "couldn't unpack archive: #{inspect(other)}"
end
@@ -235,11 +235,22 @@ defmodule DartSass do
end
end
+ defp unpack_archive(".zip", zip, cwd) do
+ with {:ok, _} <- :zip.unzip(zip, cwd: cwd), do: :ok
+ end
+
+ defp unpack_archive(_, tar, cwd) do
+ :erl_tar.extract({:binary, tar}, [:compressed, cwd: cwd])
+ end
+
# Available targets: https://github.com/sass/dart-sass/releases
defp target do
case :os.type() do
{:win32, _} ->
- "windows-#{:erlang.system_info(:wordsize) * 8}.zip"
+ case :erlang.system_info(:wordsize) * 8 do
+ 32 -> "windows-ia32.zip"
+ 64 -> "windows-x64.zip"
+ end
{:unix, osname} ->
arch_str = :erlang.system_info(:system_architecture)