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.16.5.tgz"
sha256 "edd24f0453554f598acaf4ccf61454cceed18f485d2b160277441e2f7232c5ac"
license "MIT"
bottle do
sha256 cellar: :any_skip_relocation, all: "000fd82054c55f139221cb18d2f56ee53720cb0bef6150413de8911aee220106"
end
depends_on "node"
resource "babel-cli" do
url "https://registry.npmjs.org/@babel/cli/-/cli-7.16.0.tgz"
sha256 "f082215daada09bf2ff0f76c994f366029ed136d60680902c593b7afb7bfa6ff"
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