Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Sass version to 1.61.0 #31

Merged
merged 3 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

## v0.7.0

- Update Sass version to `1.61.0`

## v0.6.0

- Overriding `:path` disables version checking.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Once installed, change your `config/config.exs` to pick your
dart_sass version of choice:

```elixir
config :dart_sass, version: "1.54.5"
config :dart_sass, version: "1.61.0"
```

Now you can install dart-sass by running:
Expand Down Expand Up @@ -68,7 +68,7 @@ directory, the OS environment, and default arguments to the

```elixir
config :dart_sass,
version: "1.54.5",
version: "1.61.0",
default: [
args: ~w(css/app.scss ../priv/static/assets/app.css),
cd: Path.expand("../assets", __DIR__)
Expand Down Expand Up @@ -100,7 +100,7 @@ compile CSS to the output location `priv/static/assets/app.css`:

```elixir
config :dart_sass,
version: "1.54.5",
version: "1.61.0",
default: [
args: ~w(css/app.scss ../priv/static/assets/app.css),
cd: Path.expand("../assets", __DIR__)
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Config

config :dart_sass,
version: "1.54.5",
version: "1.61.0",
another: [
args: ["--version"]
]
109 changes: 35 additions & 74 deletions lib/dart_sass.ex
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ defmodule DartSass do

@doc false
# Latest known version at the time of publishing.
def latest_version do
"1.54.5"
end
def latest_version, do: "1.61.0"

@doc """
Returns the configured Sass version.
Expand All @@ -116,24 +114,24 @@ defmodule DartSass do
"""
end

@doc """
Returns the path to the `sass` executable.
defp dest_bin_paths(platform, base_path) do
target = target(platform)
["dart", "sass.snapshot"] |> Enum.map(&Path.join(base_path, "#{&1}-#{target}"))
end

Depending on your system target architecture, the path may be
preceeded by the path to the Dart VM executable.
@doc """
Returns the path to the `dart` VM executable and to the `sass` executable.
"""
def bin_path do
def bin_paths do
cond do
env_path = Application.get_env(:dart_sass, :path) ->
List.wrap(env_path)

Code.ensure_loaded?(Mix.Project) ->
platform = platform()
bin_path(platform, Path.dirname(Mix.Project.build_path()))
dest_bin_paths(platform(), Path.dirname(Mix.Project.build_path()))

true ->
platform = platform()
bin_path(platform, "_build")
dest_bin_paths(platform(), "_build")
end
end

Expand All @@ -150,23 +148,17 @@ defmodule DartSass do
is not available.
"""
def bin_version do
path = bin_path()

with true <- path_exists?(path),
{result, 0} <- cmd(path, ["--version"]) do
with paths = bin_paths(),
true <- paths_exist?(paths),
{result, 0} <- run_cmd(paths, ["--version"]) do
{:ok, String.trim(result)}
else
_ -> :error
end
end

defp cmd(path, args) do
cmd(path, args, [])
end

defp cmd([command | args], extra_args, opts) do
System.cmd(command, args ++ extra_args, opts)
end
defp run_cmd([command_path | bin_paths], extra_args, opts \\ []),
do: System.cmd(command_path, bin_paths ++ extra_args, opts)

@doc """
Runs the given command with `args`.
Expand All @@ -187,20 +179,15 @@ defmodule DartSass do
]

args = config_args ++ extra_args
path = bin_path()

# TODO: Remove when dart-sass will exit when stdin is closed.
# Link: https://github.com/sass/dart-sass/pull/1411
path =
if "--watch" in args and platform() != :windows do
[script_path() | path]
else
path
end
paths =
if "--watch" in args and platform() != :windows,
do: [script_path() | bin_paths()],
else: bin_paths()

path
|> cmd(args, opts)
|> elem(1)
run_cmd(paths, args, opts) |> elem(1)
end

@doc """
Expand All @@ -209,10 +196,7 @@ defmodule DartSass do
Returns the same as `run/2`.
"""
def install_and_run(profile, args) do
unless path_exists?(bin_path()) do
install()
end

paths_exist?(bin_paths()) || install()
run(profile, args)
end

Expand All @@ -229,6 +213,11 @@ defmodule DartSass do
raise "could not install sass. Set MIX_XDG=1 and then set XDG_CACHE_HOME to the path you want to use as cache"

platform = platform()

(platform == :linux and Version.match?(version, "> 1.57.1")) or
raise "versions 1.57.1 and lower are not supported anymore on Linux " <>
"due to changes to the package structure"

name = "dart-sass-#{version}-#{target_extname(platform)}"
url = "https://github.com/sass/dart-sass/releases/download/#{version}/#{name}"
archive = fetch_body!(url)
Expand All @@ -238,43 +227,15 @@ defmodule DartSass do
other -> raise "couldn't unpack archive: #{inspect(other)}"
end

path = bin_path()
[dart, snapshot] = bin_paths()

case platform do
:linux ->
[sass | _] = path
File.rm(sass)
File.cp!(Path.join([tmp_dir, "dart-sass", "sass"]), sass)

:macos ->
[dart, snapshot | _] = path
File.rm(dart)
File.cp!(Path.join([tmp_dir, "dart-sass", "src", "dart"]), dart)
File.rm(snapshot)
File.cp!(Path.join([tmp_dir, "dart-sass", "src", "sass.snapshot"]), snapshot)

:windows ->
[dart, snapshot | _] = path
File.rm(dart)
File.cp!(Path.join([tmp_dir, "dart-sass", "src", "dart.exe"]), dart)
File.rm(snapshot)
File.cp!(Path.join([tmp_dir, "dart-sass", "src", "sass.snapshot"]), snapshot)
end
end
bin_suffix = if platform == :windows, do: ".exe", else: ""

defp bin_path(platform, base_path) do
target = target(platform)

case platform do
:linux ->
[Path.join(base_path, "sass-#{target}")]

_ ->
[
Path.join(base_path, "dart-#{target}"),
Path.join(base_path, "sass.snapshot-#{target}")
]
end
[{"dart#{bin_suffix}", dart}, {"sass.snapshot", snapshot}]
|> Enum.each(fn {src_name, dest_path} ->
File.rm(dest_path)
File.cp!(Path.join([tmp_dir, "dart-sass", "src", src_name]), dest_path)
end)
end

defp platform do
Expand All @@ -286,8 +247,8 @@ defmodule DartSass do
end
end

defp path_exists?(path) do
Enum.all?(path, &File.exists?/1)
defp paths_exist?(paths) do
paths |> Enum.all?(&File.exists?/1)
end

defp freshdir_p(path) do
Expand Down
12 changes: 6 additions & 6 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%{
"castore": {:hex, :castore, "0.1.11", "c0665858e0e1c3e8c27178e73dffea699a5b28eb72239a3b2642d208e8594914", [:mix], [], "hexpm", "91b009ba61973b532b84f7c09ce441cba7aa15cb8b006cf06c6f4bba18220081"},
"earmark_parser": {:hex, :earmark_parser, "1.4.19", "de0d033d5ff9fc396a24eadc2fcf2afa3d120841eb3f1004d138cbf9273210e8", [:mix], [], "hexpm", "527ab6630b5c75c3a3960b75844c314ec305c76d9899bb30f71cb85952a9dc45"},
"ex_doc": {:hex, :ex_doc, "0.27.3", "d09ed7ab590b71123959d9017f6715b54a448d76b43cf909eb0b2e5a78a977b2", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "ee60b329d08195039bfeb25231a208749be4f2274eae42ce38f9be0538a2f2e6"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"},
"castore": {:hex, :castore, "1.0.1", "240b9edb4e9e94f8f56ab39d8d2d0a57f49e46c56aced8f873892df8ff64ff5a", [:mix], [], "hexpm", "b4951de93c224d44fac71614beabd88b71932d0b1dea80d2f80fb9044e01bbb3"},
"earmark_parser": {:hex, :earmark_parser, "1.4.31", "a93921cdc6b9b869f519213d5bc79d9e218ba768d7270d46fdcf1c01bacff9e2", [:mix], [], "hexpm", "317d367ee0335ef037a87e46c91a2269fef6306413f731e8ec11fc45a7efd059"},
"ex_doc": {:hex, :ex_doc, "0.29.4", "6257ecbb20c7396b1fe5accd55b7b0d23f44b6aa18017b415cb4c2b91d997729", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2c6699a737ae46cb61e4ed012af931b57b699643b24dabe2400a8168414bc4f5"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"nimble_parsec": {:hex, :nimble_parsec, "1.2.0", "b44d75e2a6542dcb6acf5d71c32c74ca88960421b6874777f79153bbbbd7dccc", [:mix], [], "hexpm", "52b2871a7515a5ac49b00f214e4165a40724cf99798d8e4a65e4fd64ebd002c1"},
"nimble_parsec": {:hex, :nimble_parsec, "1.3.0", "9e18a119d9efc3370a3ef2a937bf0b24c088d9c4bf0ba9d7c3751d49d347d035", [:mix], [], "hexpm", "7977f183127a7cbe9346981e2f480dc04c55ffddaef746bd58debd566070eef8"},
}
6 changes: 3 additions & 3 deletions test/dart_sass_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule DartSassTest do
use ExUnit.Case, async: true

@version "1.54.5"
@version DartSass.latest_version()

test "run on default" do
assert ExUnit.CaptureIO.capture_io(fn ->
Expand All @@ -16,13 +16,13 @@ defmodule DartSassTest do
end

test "updates on install" do
Application.put_env(:dart_sass, :version, "1.49.11")
Application.put_env(:dart_sass, :version, "1.60.0")

Mix.Task.rerun("sass.install", ["--if-missing"])

assert ExUnit.CaptureIO.capture_io(fn ->
assert DartSass.run(:default, ["--version"]) == 0
end) =~ "1.49.11"
end) =~ "1.60.0"

Application.delete_env(:dart_sass, :version)

Expand Down