require "language/node" require "json" class Webpack < Formula desc "Bundler for JavaScript and friends" homepage "https://webpack.js.org/" url "https://registry.npmjs.org/webpack/-/webpack-4.26.0.tgz" sha256 "38d0964d87c6cd261ef5bf146f7a396da8733ad3f088c1f60d553eaffae82dff" head "https://github.com/webpack/webpack.git" bottle do sha256 "e26ded816b4f71ae205fe63115cdfb2851ec9b1fad9ec3246a79ff67a0079eb3" => :mojave sha256 "4ecbae5bbfd8f3fa1db7a4f6e93d9d1219e7801d7266082eb575f3516b97e98b" => :high_sierra sha256 "57783a916507ca6ce163e80ad568c66bbc468fd7077805c71d05db19c31bd741" => :sierra end depends_on "node" resource "webpack-cli" do url "https://registry.npmjs.org/webpack-cli/-/webpack-cli-3.1.2.tgz" sha256 "135962a43cdec4d24f68925c32e4daea600d6433d7b8fb912a9709a65712411e" end def install (buildpath/"node_modules/webpack").install Dir["*"] buildpath.install resource("webpack-cli") # declare webpack as a bundledDependency of webpack-cli pkg_json = JSON.parse(IO.read("package.json")) pkg_json["dependencies"]["webpack"] = version pkg_json["bundledDependencies"] = ["webpack"] IO.write("package.json", JSON.pretty_generate(pkg_json)) system "npm", "install", *Language::Node.std_npm_install_args(libexec) bin.install_symlink libexec/"bin/webpack-cli" bin.install_symlink libexec/"bin/webpack-cli" => "webpack" end test do (testpath/"index.js").write <<~EOS function component () { var element = document.createElement('div'); element.innerHTML = 'Hello' + ' ' + 'webpack'; return element; } document.body.appendChild(component()); EOS system bin/"webpack", "index.js", "--output=bundle.js" assert_predicate testpath/"bundle.js", :exist?, "bundle.js was not generated" end end