|
| 1 | +class Iojs < Formula |
| 2 | + homepage "https://iojs.org/" |
| 3 | + url "https://iojs.org/dist/v1.0.1/iojs-v1.0.1.tar.gz" |
| 4 | + sha256 "c26052dad5d9ccd8a7b9134806994ebf2d217a57d6efd5633e01c5cc1dcdedc5" |
| 5 | + |
| 6 | + conflicts_with "node", :because => "io.js includes a symlink named node for compatibility." |
| 7 | + |
| 8 | + option "with-debug", "Build with debugger hooks" |
| 9 | + option "without-npm", "npm will not be installed" |
| 10 | + option "without-completion", "npm bash completion will not be installed" |
| 11 | + |
| 12 | + depends_on :python => :build |
| 13 | + |
| 14 | + resource "npm" do |
| 15 | + url "https://registry.npmjs.org/npm/-/npm-2.1.18.tgz" |
| 16 | + sha1 "e2af4c5f848fb023851cd2ec129005d33090bd57" |
| 17 | + end |
| 18 | + |
| 19 | + def install |
| 20 | + args = %W{--prefix=#{prefix} --without-npm} |
| 21 | + args << "--debug" if build.with? "debug" |
| 22 | + |
| 23 | + system "./configure", *args |
| 24 | + system "make", "install" |
| 25 | + |
| 26 | + if build.with? "npm" |
| 27 | + resource("npm").stage buildpath/"npm_install" |
| 28 | + |
| 29 | + # make sure npm can find iojs |
| 30 | + ENV.prepend_path "PATH", bin |
| 31 | + |
| 32 | + # set log level temporarily for npm's `make install` |
| 33 | + ENV["NPM_CONFIG_LOGLEVEL"] = "verbose" |
| 34 | + |
| 35 | + cd buildpath/"npm_install" do |
| 36 | + system "./configure", "--prefix=#{libexec}/npm" |
| 37 | + system "make", "install" |
| 38 | + end |
| 39 | + |
| 40 | + if build.with? "completion" |
| 41 | + bash_completion.install \ |
| 42 | + buildpath/"npm_install/lib/utils/completion.sh" => "npm" |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | + |
| 47 | + def post_install |
| 48 | + return if build.without? "npm" |
| 49 | + |
| 50 | + node_modules = HOMEBREW_PREFIX/"lib/node_modules" |
| 51 | + node_modules.mkpath |
| 52 | + npm_exec = node_modules/"npm/bin/npm-cli.js" |
| 53 | + # Kill npm but preserve all other modules across iojs updates/upgrades. |
| 54 | + rm_rf node_modules/"npm" |
| 55 | + |
| 56 | + cp_r libexec/"npm/lib/node_modules/npm", node_modules |
| 57 | + # This symlink doesn't hop into homebrew_prefix/bin automatically so |
| 58 | + # remove it and make our own. This is a small consequence of our bottle |
| 59 | + # npm make install workaround. All other installs **do** symlink to |
| 60 | + # homebrew_prefix/bin correctly. We ln rather than cp this because doing |
| 61 | + # so mimics npm's normal install. |
| 62 | + ln_sf npm_exec, "#{HOMEBREW_PREFIX}/bin/npm" |
| 63 | + |
| 64 | + # Let's do the manpage dance. It's just a jump to the left. |
| 65 | + # And then a step to the right, with your hand on rm_f. |
| 66 | + ["man1", "man3", "man5", "man7"].each do |man| |
| 67 | + rm_f Dir[HOMEBREW_PREFIX/"share/man/#{man}/{npm.,npm-,npmrc.}*"] |
| 68 | + Dir[libexec/"npm/share/man/#{man}/npm*"].each {|f| ln_sf f, HOMEBREW_PREFIX/"share/man/#{man}" } |
| 69 | + end |
| 70 | + |
| 71 | + npm_root = node_modules/"npm" |
| 72 | + npmrc = npm_root/"npmrc" |
| 73 | + npmrc.atomic_write("prefix = #{HOMEBREW_PREFIX}\n") |
| 74 | + end |
| 75 | + |
| 76 | + def caveats |
| 77 | + s = "" |
| 78 | + |
| 79 | + if build.with? "npm" |
| 80 | + s += <<-EOS.undent |
| 81 | + If you update npm itself, do NOT use the npm update command. |
| 82 | + The upstream-recommended way to update npm is: |
| 83 | + npm install -g npm@latest |
| 84 | + EOS |
| 85 | + else |
| 86 | + s += <<-EOS.undent |
| 87 | + Homebrew has NOT installed npm. If you later install it, you should supplement |
| 88 | + your NODE_PATH with the npm module folder: |
| 89 | + #{HOMEBREW_PREFIX}/lib/node_modules |
| 90 | + EOS |
| 91 | + end |
| 92 | + |
| 93 | + s |
| 94 | + end |
| 95 | + |
| 96 | + test do |
| 97 | + path = testpath/"test.js" |
| 98 | + path.write "console.log('hello');" |
| 99 | + |
| 100 | + output = `#{bin}/iojs #{path}`.strip |
| 101 | + assert_equal "hello", output |
| 102 | + assert_equal 0, $?.exitstatus |
| 103 | + |
| 104 | + if build.with? "npm" |
| 105 | + # make sure npm can find node |
| 106 | + ENV.prepend_path "PATH", opt_bin |
| 107 | + assert_equal which("iojs"), opt_bin/"iojs" |
| 108 | + assert (HOMEBREW_PREFIX/"bin/npm").exist?, "npm must exist" |
| 109 | + assert (HOMEBREW_PREFIX/"bin/npm").executable?, "npm must be executable" |
| 110 | + system "#{HOMEBREW_PREFIX}/bin/npm", "--userconfig=/dev/null", "--verbose", "install", "npm@latest" |
| 111 | + end |
| 112 | + end |
| 113 | +end |
0 commit comments