49 lines
1.5 KiB
Ruby
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.20.5.tgz"
|
|
sha256 "7c30f9e1dcb7ac82fba886325e71ff4da29f628706258c842844aa394dd63f93"
|
|
license "MIT"
|
|
|
|
bottle do
|
|
sha256 cellar: :any_skip_relocation, all: "b4e286e27b7c6c5ee747b229d23a5f6976a7d30b080997a7003d6eeafebd226b"
|
|
end
|
|
|
|
depends_on "node"
|
|
|
|
resource "babel-cli" do
|
|
url "https://registry.npmjs.org/@babel/cli/-/cli-7.19.3.tgz"
|
|
sha256 "7d0020e4385192f46e815dad036353de275dd30d94855c83ededee7fc69012f7"
|
|
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
|