|
| 1 | +class DartSass < Formula |
| 2 | + desc "Reference implementation of Sass, written in Dart" |
| 3 | + homepage "https://sass-lang.com/dart-sass" |
| 4 | + url "https://github.com/sass/dart-sass/archive/refs/tags/1.98.0.tar.gz" |
| 5 | + sha256 "2eab6aebaba4e095e67b970baf8b0bdb4b934be17fdee1ca5d5da6a490b5517a" |
| 6 | + license "MIT" |
| 7 | + |
| 8 | + depends_on "buf" => :build |
| 9 | + depends_on "dart-sdk" => :build |
| 10 | + |
| 11 | + resource "language" do |
| 12 | + url "https://github.com/sass/sass/archive/refs/tags/embedded-protocol-3.2.0.tar.gz" |
| 13 | + sha256 "4e1f81684bc1666f03e52ddc790d0c2c22d99a5313fa2efe1dde4a5b5733c186" |
| 14 | + end |
| 15 | + |
| 16 | + def install |
| 17 | + ENV["PUB_ENVIRONMENT"] = "homebrew:sass" |
| 18 | + ENV["DART_SUPPRESS_ANALYTICS"] = "true" |
| 19 | + |
| 20 | + (buildpath/"build/language").install resource("language") |
| 21 | + |
| 22 | + system "dart", "pub", "get" |
| 23 | + with_env(UPDATE_SASS_PROTOCOL: "false") do |
| 24 | + system "dart", "run", "grinder", "protobuf" |
| 25 | + end |
| 26 | + |
| 27 | + args = %W[ |
| 28 | + -Dversion=#{version} |
| 29 | + -Ddart-vesrion=#{Formula["dart-sdk"].version} |
| 30 | + -Dcompiler-version=#{version} |
| 31 | + -Dprotocol-version=#{resource("language").version} |
| 32 | + ] |
| 33 | + if OS.mac? |
| 34 | + system "dart", "compile", "exe", "--output", "sass", *args, "bin/sass.dart" |
| 35 | + bin.install "sass" |
| 36 | + else |
| 37 | + system "dart", "compile", "aot-snapshot", "--output", "sass.aot", *args, "bin/sass.dart" |
| 38 | + libexec.install "sass.aot" |
| 39 | + # Dart creates elf binary with inner elf binary on linux and it breaks during the bottle creation |
| 40 | + # So, here we copy `dartaotruntime` binary to run the compiled aot snapshot |
| 41 | + cp Formula["dart-sdk"].opt_libexec/"bin/dartaotruntime", libexec |
| 42 | + |
| 43 | + (bin/"sass").write_env_script libexec/"dartaotruntime", "#{libexec}/sass.aot" |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + test do |
| 48 | + assert_match version.to_s, shell_output("#{bin}/sass --version") |
| 49 | + |
| 50 | + (testpath/"test.scss").write(".class {property: 1 + 1}") |
| 51 | + assert_match "property: 2;", shell_output("#{bin}/sass test.scss 2>&1") |
| 52 | + |
| 53 | + (testpath/"input.scss").write <<~EOS |
| 54 | + div { |
| 55 | + img { |
| 56 | + border: 0px; |
| 57 | + } |
| 58 | + } |
| 59 | + EOS |
| 60 | + |
| 61 | + assert_equal "div img{border:0px}", |
| 62 | + shell_output("#{bin}/sass --style compressed input.scss").strip |
| 63 | + end |
| 64 | +end |
0 commit comments