class Deno < Formula desc "Secure runtime for JavaScript and TypeScript" homepage "https://deno.land/" url "https://github.com/denoland/deno/releases/download/v1.22.0/deno_src.tar.gz" sha256 "ffa1cd143ba1e53ab5d380c1e630a2fe73910b7be4e483b0d643d14b31b23ed4" license "MIT" head "https://github.com/denoland/deno.git", branch: "main" bottle do sha256 cellar: :any_skip_relocation, arm64_monterey: "ef4b117706e007e417804196ce60872e1ce6f7202ea3f862184c25278cccffb2" sha256 cellar: :any_skip_relocation, arm64_big_sur: "ebb26e6a478fbbfe089532b5ded2661ddf7e14041a9c8619a8baf10c6ff84877" sha256 cellar: :any_skip_relocation, monterey: "85628d306b00dca9cdc8a989f859bd8074427607f61a158c71bdc5ae792c38b0" sha256 cellar: :any_skip_relocation, big_sur: "b866adea0a356019407a3172095f708831f48ca7a4578d5b8d47e587d4575f50" sha256 cellar: :any_skip_relocation, catalina: "1c4a4feccfcc738dfa6127eadde112793ee82521043e4df21eec13f655ff360b" sha256 x86_64_linux: "b5a64d4feae3eae0b2837dfed6d0d7b1bfea07a8a643f6c6abc565ac9cf4cf73" end depends_on "llvm" => :build depends_on "ninja" => :build depends_on "python@3.10" => :build depends_on "rust" => :build uses_from_macos "xz" on_macos do depends_on xcode: ["10.0", :build] # required by v8 7.9+ end on_linux do depends_on "pkg-config" => :build depends_on "gcc" depends_on "glib" end fails_with gcc: "5" # To find the version of gn used: # 1. Find v8 version: https://github.com/denoland/deno/blob/v#{version}/core/Cargo.toml # 2. Find ninja_gn_binaries tag: https://github.com/denoland/rusty_v8/tree/v#{v8_version}/tools/ninja_gn_binaries.py # 3. Find short gn commit hash from commit message: https://github.com/denoland/ninja_gn_binaries/tree/#{ninja_gn_binaries_tag} # 4. Find full gn commit hash: https://gn.googlesource.com/gn.git/+/#{gn_commit} resource "gn" do url "https://gn.googlesource.com/gn.git", revision: "53d92014bf94c3893886470a1c7c1289f8818db0" end def install if OS.mac? && (MacOS.version < :mojave) # Overwrite Chromium minimum SDK version of 10.15 ENV["FORCE_MAC_SDK_MIN"] = MacOS.version end # env args for building a release build with our python3, ninja and gn ENV.prepend_path "PATH", Formula["python@3.10"].libexec/"bin" ENV["PYTHON"] = Formula["python@3.10"].opt_bin/"python3" ENV["GN"] = buildpath/"gn/out/gn" ENV["NINJA"] = Formula["ninja"].opt_bin/"ninja" # build rusty_v8 from source ENV["V8_FROM_SOURCE"] = "1" # Build with llvm and link against system libc++ (no runtime dep) ENV["CLANG_BASE_PATH"] = Formula["llvm"].prefix ENV.remove "HOMEBREW_LIBRARY_PATHS", Formula["llvm"].opt_lib resource("gn").stage buildpath/"gn" cd "gn" do system "python3", "build/gen.py" system "ninja", "-C", "out" end cd "cli" do # cargo seems to build rusty_v8 twice in parallel, which causes problems, # hence the need for -j1 system "cargo", "install", "-vv", "-j1", *std_cargo_args end bash_output = Utils.safe_popen_read(bin/"deno", "completions", "bash") (bash_completion/"deno").write bash_output zsh_output = Utils.safe_popen_read(bin/"deno", "completions", "zsh") (zsh_completion/"_deno").write zsh_output fish_output = Utils.safe_popen_read(bin/"deno", "completions", "fish") (fish_completion/"deno.fish").write fish_output end test do (testpath/"hello.ts").write <<~EOS console.log("hello", "deno"); EOS assert_match "hello deno", shell_output("#{bin}/deno run hello.ts") assert_match "console.log", shell_output("#{bin}/deno run --allow-read=#{testpath} https://deno.land/std@0.50.0/examples/cat.ts " \ "#{testpath}/hello.ts") end end