Skip to content

Commit

Permalink
Fix installation path/unzip on windows (#3)
Browse files Browse the repository at this point in the history
* Fix path to windows .zip archive
* Fix unpacking .zip archive
  • Loading branch information
mcrumm authored Jul 30, 2021
1 parent 2e8eba4 commit b4536fc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 14 additions & 3 deletions lib/dart_sass.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit b4536fc

Please sign in to comment.