Skip to content

Commit

Permalink
Alternative arrangement for node and iojs
Browse files Browse the repository at this point in the history
This PR
- takes iojs out of keg-only
- conflicts node and iojs
- patches iojs’s installed npm
- currently leaves in the iojs patch flag from Homebrew#36357
  • Loading branch information
bcomnes committed Jan 29, 2015
1 parent b765478 commit f70bd11
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 8 deletions.
120 changes: 112 additions & 8 deletions Library/Formula/iojs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,99 @@ class Iojs < Formula
sha1 "f62a32113ae476095c7bcdee8dffe6c87f3675a8" => :mountain_lion
end

keg_only "iojs conflicts with node (which is currently more established)"
conflicts_with "node", :because => "node and iojs both install a binary/link named node"

option "with-debug", "Build with debugger hooks"
option "without-npm", "npm will not be installed"
option "without-completion", "npm bash completion will not be installed"

depends_on :python => :build

resource "npm" do
url "https://registry.npmjs.org/npm/-/npm-2.3.0.tgz"
sha1 "3588ec5c18fb5ac41e5721b0ea8ece3a85ab8b4b"
end

def install
args = %W[--prefix=#{prefix} --without-npm]
args << "--debug" if build.with? "debug"

system "./configure", *args
system "make", "install"

if build.with? "npm"
resource("npm").stage npm_buildpath = buildpath/"npm_install"
# make sure npm can find node
ENV.prepend_path "PATH", bin

# set log level temporarily for npm's `make install`
ENV["NPM_CONFIG_LOGLEVEL"] = "verbose"

cd npm_buildpath do
p = Patch.create(:p1, :DATA)
p.path = Pathname.new(__FILE__).expand_path
p.apply

system "./configure", "--prefix=#{libexec}/npm"
system "make", "install"
end

if build.with? "completion"
bash_completion.install \
npm_buildpath/"lib/utils/completion.sh" => "npm"
end
end
end

def post_install
return if build.without? "npm"

node_modules = HOMEBREW_PREFIX/"lib/node_modules"
node_modules.mkpath
npm_exec = node_modules/"npm/bin/npm-cli.js"
# Kill npm but preserve all other modules across node updates/upgrades.
rm_rf node_modules/"npm"

cp_r libexec/"npm/lib/node_modules/npm", node_modules
# This symlink doesn't hop into homebrew_prefix/bin automatically so
# remove it and make our own. This is a small consequence of our bottle
# npm make install workaround. All other installs **do** symlink to
# homebrew_prefix/bin correctly. We ln rather than cp this because doing
# so mimics npm's normal install.
ln_sf npm_exec, "#{HOMEBREW_PREFIX}/bin/npm"

# Let's do the manpage dance. It's just a jump to the left.
# And then a step to the right, with your hand on rm_f.
["man1", "man3", "man5", "man7"].each do |man|
# Dirs must exist first: https://github.com/Homebrew/homebrew/issues/35969
mkdir_p HOMEBREW_PREFIX/"share/man/#{man}"
rm_f Dir[HOMEBREW_PREFIX/"share/man/#{man}/{npm.,npm-,npmrc.}*"]
ln_sf Dir[libexec/"npm/share/man/#{man}/npm*"], HOMEBREW_PREFIX/"share/man/#{man}"
end

npm_root = node_modules/"npm"
npmrc = npm_root/"npmrc"
npmrc.atomic_write("prefix = #{HOMEBREW_PREFIX}\n")
end

def caveats; <<-EOS.undent
iojs was installed without npm. To install npm with iojs compatability:
brew install node --with-iojs-patch
def caveats;
s = ""

To prepend iojs to your PATH add to your ~/.bashrc:
export PATH="#{Formula["iojs"].opt_bin}:$PATH"
if build.with? "npm"
s += <<-EOS.undent
If you update npm itself, do NOT use the npm update command.
The upstream-recommended way to update npm is:
npm install -g npm@latest
EOS
else
s += <<-EOS.undent
Homebrew has NOT installed npm. If you later install it, you should supplement
your NODE_PATH with the npm module folder:
#{HOMEBREW_PREFIX}/lib/node_modules
EOS
end

This will also e.g. make npm use iojs's node.
EOS
s
end

test do
Expand All @@ -41,5 +111,39 @@ def caveats; <<-EOS.undent
output = `#{bin}/iojs #{path}`.strip
assert_equal "hello", output
assert_equal 0, $?.exitstatus

if build.with? "npm"
# make sure npm can find node
ENV.prepend_path "PATH", opt_bin
assert_equal which("node"), opt_bin/"node"
assert (HOMEBREW_PREFIX/"bin/npm").exist?, "npm must exist"
assert (HOMEBREW_PREFIX/"bin/npm").executable?, "npm must be executable"
system "#{HOMEBREW_PREFIX}/bin/npm", "--verbose", "install", "npm@latest"
end
end
end

__END__
diff --git a/node_modules/node-gyp/lib/install.js b/node_modules/node-gyp/lib/install.js
index 6f72e6a..ebc4e57 100644
--- a/node_modules/node-gyp/lib/install.js
+++ b/node_modules/node-gyp/lib/install.js
@@ -39,7 +39,7 @@ function install (gyp, argv, callback) {
}
}

- var distUrl = gyp.opts['dist-url'] || gyp.opts.disturl || 'http://nodejs.org/dist'
+ var distUrl = gyp.opts['dist-url'] || gyp.opts.disturl || 'https://iojs.org/dist'


// Determine which node dev files version we are installing
@@ -185,7 +185,7 @@ function install (gyp, argv, callback) {

// now download the node tarball
var tarPath = gyp.opts['tarball']
- var tarballUrl = tarPath ? tarPath : distUrl + '/v' + version + '/node-v' + version + '.tar.gz'
+ var tarballUrl = tarPath ? tarPath : distUrl + '/v' + version + '/iojs-v' + version + '.tar.gz'
, badDownload = false
, extractCount = 0
, gunzip = zlib.createGunzip()

2 changes: 2 additions & 0 deletions Library/Formula/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class Node < Formula
sha1 "b5d7094ed826813b2cc35303bcde8269b1ad9292" => :mountain_lion
end

conflicts_with "iojs", :because => "node and iojs both install a binary/link named node"

devel do
url "https://nodejs.org/dist/v0.11.15/node-v0.11.15.tar.gz"
sha256 "e613d274baa4c99a0518038192491433f7877493a66d8505af263f6310991d01"
Expand Down

0 comments on commit f70bd11

Please sign in to comment.