|
| 1 | +class Bun < Formula |
| 2 | + desc "Incredibly fast JavaScript runtime, bundler, test runner, and package manager" |
| 3 | + homepage "https://bun.com" |
| 4 | + url "https://github.com/oven-sh/bun.git", |
| 5 | + tag: "bun-v1.3.0", |
| 6 | + revision: "b0a6feca57bf5c2a9ec2ef9773499cab7d904b30" |
| 7 | + license all_of: [ |
| 8 | + "MIT", # Bun itself and most of the dependencies |
| 9 | + "Apache-2.0", # boringssl, simdutf, uSockets, and others |
| 10 | + "BSD-3-Clause", # boringssl, lol-html |
| 11 | + "BSD-2-Clause", # libbase64 |
| 12 | + "Zlib", # zlib |
| 13 | + ] |
| 14 | + head "https://github.com/oven-sh/bun.git", branch: "main" |
| 15 | + |
| 16 | + depends_on "automake" => :build |
| 17 | + depends_on "ccache" => :build |
| 18 | + depends_on "cmake" => :build |
| 19 | + depends_on "coreutils" => :build |
| 20 | + depends_on "gnu-sed" => :build |
| 21 | + depends_on "go" => :build |
| 22 | + depends_on "icu4c@77" => :build |
| 23 | + depends_on "libtool" => :build |
| 24 | + depends_on "lld@19" => :build |
| 25 | + depends_on "llvm@19" => :build |
| 26 | + depends_on "ninja" => :build |
| 27 | + depends_on "pkgconf" => :build |
| 28 | + depends_on "ruby" => :build |
| 29 | + depends_on "rust" => :build |
| 30 | + |
| 31 | + on_macos do |
| 32 | + depends_on "libiconv" => :build |
| 33 | + end |
| 34 | + |
| 35 | + # Update the resource only if build fails |
| 36 | + resource "bun-bootstrap" do |
| 37 | + on_macos do |
| 38 | + on_arm do |
| 39 | + url "https://github.com/oven-sh/bun/releases/download/bun-v1.3.0/bun-darwin-aarch64.zip" |
| 40 | + sha256 "85848e3f96481efcabe75a500fd3b94b9bb95686ab7ad0a3892976c7be15036a" |
| 41 | + end |
| 42 | + on_intel do |
| 43 | + url "https://github.com/oven-sh/bun/releases/download/bun-v1.3.0/bun-darwin-x64.zip" |
| 44 | + sha256 "09d54af86ec45354bb63ff7ccc3ce9520d74f4e45f9f7cac8ceb7fac422fcc19" |
| 45 | + end |
| 46 | + end |
| 47 | + on_linux do |
| 48 | + on_arm do |
| 49 | + url "https://github.com/oven-sh/bun/releases/download/bun-v1.3.0/bun-linux-aarch64.zip" |
| 50 | + sha256 "68b7dcd86a35e7d5e156b37e4cef4b4ab6d6b37fd2179570c0e815f13890febd" |
| 51 | + end |
| 52 | + on_intel do |
| 53 | + url "https://github.com/oven-sh/bun/releases/download/bun-v1.3.0/bun-linux-x64.zip" |
| 54 | + sha256 "60c39d92b8bd090627524c98b3012f0c08dc89024cfdaa7c9c98cb5fd4359376" |
| 55 | + end |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + def install |
| 60 | + ENV.llvm_clang |
| 61 | + |
| 62 | + resource("bun-bootstrap").stage buildpath/"bootstrap" |
| 63 | + ENV.prepend_path "PATH", buildpath/"bootstrap" |
| 64 | + |
| 65 | + # Trying to fix `-Wundefined-var-template` error |
| 66 | + # TODO: file an issue |
| 67 | + ENV.append "CXXFLAGS", "-Wno-missing-template-instantion" |
| 68 | + |
| 69 | + system "bun", "run", "build:release" |
| 70 | + bin.install "build/release/bun" |
| 71 | + bin.install_symlink bin/"bun" => "bunx" |
| 72 | + |
| 73 | + bash_completion.install "completions/bun.bash" => "bun" |
| 74 | + zsh_completion.install "completions/bun.zsh" => "_bun" |
| 75 | + fish_completion.install "completions/bun.fish" |
| 76 | + end |
| 77 | + |
| 78 | + test do |
| 79 | + assert_match version.to_s, shell_output("#{bin}/bun --version") |
| 80 | + |
| 81 | + system bin/"bun", "init", "--yes" |
| 82 | + assert_path_exists "bun.lock" |
| 83 | + |
| 84 | + (testpath/"test.ts").write <<~TYPESCRIPT |
| 85 | + console.log("Hello world!"); |
| 86 | + TYPESCRIPT |
| 87 | + |
| 88 | + assert_equal "Hello world!", shell_output("#{bin}/bun run test.ts").chomp |
| 89 | + assert_match "Hello world!", shell_output("#{bin}/bunx cowsay 'Hello world!'") |
| 90 | + end |
| 91 | +end |
0 commit comments