homebrew-core/Formula/babel.rb

49 lines
1.5 KiB
Ruby

require "language/node"
require "json"
class Babel < Formula
desc "Compiler for writing next generation JavaScript"
homepage "https://babeljs.io/"
url "https://registry.npmjs.org/@babel/core/-/core-7.18.9.tgz"
sha256 "9a1831b17a6a6b8524ffd957c70deb5b12f2ec90869c0b3b0bacd201bfbc338b"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, all: "749941de8baae171c831461514451a14ca77d382c0fdcb66fc7560702b3367a0"
end
depends_on "node"
resource "babel-cli" do
url "https://registry.npmjs.org/@babel/cli/-/cli-7.18.9.tgz"
sha256 "8966ea88caa56f09e339c3b9afce43347eb9c406cdcc9dd42da28b2dd15443c6"
end
def install
(buildpath/"node_modules/@babel/core").install Dir["*"]
buildpath.install resource("babel-cli")
cd buildpath/"node_modules/@babel/core" do
system "npm", "install", *Language::Node.local_npm_install_args, "--production"
end
# declare babel-core as a bundledDependency of babel-cli
pkg_json = JSON.parse(File.read("package.json"))
pkg_json["dependencies"]["@babel/core"] = version
pkg_json["bundleDependencies"] = ["@babel/core"]
File.write("package.json", JSON.pretty_generate(pkg_json))
system "npm", "install", *Language::Node.std_npm_install_args(libexec)
bin.install_symlink Dir["#{libexec}/bin/*"]
end
test do
(testpath/"script.js").write <<~EOS
[1,2,3].map(n => n + 1);
EOS
system bin/"babel", "script.js", "--out-file", "script-compiled.js"
assert_predicate testpath/"script-compiled.js", :exist?, "script-compiled.js was not generated"
end
end