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