Skip to content
This repository was archived by the owner on Jan 16, 2025. It is now read-only.

Commit 4e9cdfc

Browse files
committed
Graduate iojs out of keg-only
This PR - takes iojs out of keg-only - conflicts node and iojs - patches iojs’s installed npm - does not patch node’s installed npm - Added NPM install code to language/javascript.rb - Added npm caveats to iojs and node formula based off of python caveats. - incorporated 1580f8b change Signed-off-by: Bret Comnes <[email protected]>
1 parent e70e0ee commit 4e9cdfc

File tree

3 files changed

+141
-51
lines changed

3 files changed

+141
-51
lines changed

Library/Formula/iojs.rb

Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1+
require "language/javascript"
2+
13
class Iojs < Formula
4+
include Language::JS
5+
26
homepage "https://iojs.org/"
37
url "https://iojs.org/dist/v1.3.0/iojs-v1.3.0.tar.xz"
48
sha256 "0c20c0d26d8c8e8814f02fd20fb5e57098f747692cddfd7453ffae973ebcebda"
@@ -9,29 +13,73 @@ class Iojs < Formula
913
sha1 "cdcc1f499cc7ea2b17ebf0311a49a46352ba4ba4" => :mountain_lion
1014
end
1115

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

1418
option "with-debug", "Build with debugger hooks"
1519
option "with-icu4c", "Build with Intl (icu4c) support"
20+
option "without-npm", "npm will not be installed"
21+
option "without-completion", "npm bash completion will not be installed"
1622

1723
depends_on "pkg-config" => :build
1824
depends_on "icu4c" => :optional
1925
depends_on :python => :build
2026

27+
resource "npm" do
28+
url "https://registry.npmjs.org/npm/-/npm-2.3.0.tgz"
29+
sha1 "3588ec5c18fb5ac41e5721b0ea8ece3a85ab8b4b"
30+
end
31+
2132
def install
2233
args = %W[--prefix=#{prefix} --without-npm]
2334
args << "--debug" if build.with? "debug"
2435
args << "--with-intl=system-icu" if build.with? "icu4c"
2536

2637
system "./configure", *args
2738
system "make", "install"
39+
40+
if build.with? "npm"
41+
resource("npm").stage npm_buildpath = buildpath/"npm_install"
42+
install_npm npm_buildpath
43+
44+
if build.with? "completion"
45+
install_npm_bash_completion npm_buildpath
46+
end
47+
end
2848
end
2949

30-
def caveats; <<-EOS.undent
31-
iojs was installed without npm.
50+
def post_install
51+
return if build.without? "npm"
3252

33-
iojs currently requires a patched npm (i.e. not the npm installed by node).
34-
EOS
53+
npm_post_install libexec
54+
end
55+
56+
def caveats
57+
s = ""
58+
59+
if build.with? "npm"
60+
s += <<-EOS.undent
61+
npm has been installed. To update run
62+
npm install -g npm@latest
63+
64+
You can install global npm packages with
65+
npm install -g <package>
66+
67+
They will install into the global node_modiles directory
68+
/usr/local/lib/node_modules
69+
70+
Do NOT use the npm update command with global modules.
71+
The upstream-recommended way to update global modules is:
72+
npm install -g <package>@latest
73+
EOS
74+
else
75+
s += <<-EOS.undent
76+
Homebrew has NOT installed npm. If you later install it, you should supplement
77+
your NODE_PATH with the npm module folder:
78+
#{HOMEBREW_PREFIX}/lib/node_modules
79+
EOS
80+
end
81+
82+
s
3583
end
3684

3785
test do
@@ -41,5 +89,13 @@ def caveats; <<-EOS.undent
4189
output = `#{bin}/iojs #{path}`.strip
4290
assert_equal "hello", output
4391
assert_equal 0, $?.exitstatus
92+
93+
if build.with? "npm"
94+
# make sure npm can find node
95+
ENV.prepend_path "PATH", opt_bin
96+
assert_equal which("node"), opt_bin/"node"
97+
npm_test_install
98+
end
4499
end
45100
end
101+

Library/Formula/node.rb

Lines changed: 22 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
require "language/javascript"
2+
13
# Note that x.even are stable releases, x.odd are devel releases
24
class Node < Formula
5+
include Language::JS
6+
37
homepage "https://nodejs.org/"
48
url "https://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz"
59
sha256 "9700e23af4e9b3643af48cef5f2ad20a1331ff531a12154eef2bfb0bb1682e32"
@@ -12,6 +16,8 @@ class Node < Formula
1216
sha1 "8312e7ea6ffec58e39ec7cc1f8671847a9d7b4bf" => :mountain_lion
1317
end
1418

19+
conflicts_with "iojs", :because => "node and iojs both install a binary/link named node"
20+
1521
option "with-debug", "Build with debugger hooks"
1622
option "without-npm", "npm will not be installed"
1723
option "without-completion", "npm bash completion will not be installed"
@@ -50,66 +56,38 @@ def install
5056
system "make", "install"
5157

5258
if build.with? "npm"
53-
resource("npm").stage buildpath/"npm_install"
54-
55-
# make sure npm can find node
56-
ENV.prepend_path "PATH", bin
57-
# make sure user prefix settings in $HOME are ignored
58-
ENV["HOME"] = buildpath/"home"
59-
# set log level temporarily for npm's `make install`
60-
ENV["NPM_CONFIG_LOGLEVEL"] = "verbose"
61-
62-
cd buildpath/"npm_install" do
63-
system "./configure", "--prefix=#{libexec}/npm"
64-
system "make", "install"
65-
end
59+
resource("npm").stage npm_buildpath = buildpath/"npm_install"
60+
install_npm npm_buildpath
6661

6762
if build.with? "completion"
68-
bash_completion.install \
69-
buildpath/"npm_install/lib/utils/completion.sh" => "npm"
63+
install_npm_bash_completion npm_buildpath
7064
end
7165
end
7266
end
7367

7468
def post_install
7569
return if build.without? "npm"
7670

77-
node_modules = HOMEBREW_PREFIX/"lib/node_modules"
78-
node_modules.mkpath
79-
npm_exec = node_modules/"npm/bin/npm-cli.js"
80-
# Kill npm but preserve all other modules across node updates/upgrades.
81-
rm_rf node_modules/"npm"
82-
83-
cp_r libexec/"npm/lib/node_modules/npm", node_modules
84-
# This symlink doesn't hop into homebrew_prefix/bin automatically so
85-
# remove it and make our own. This is a small consequence of our bottle
86-
# npm make install workaround. All other installs **do** symlink to
87-
# homebrew_prefix/bin correctly. We ln rather than cp this because doing
88-
# so mimics npm's normal install.
89-
ln_sf npm_exec, "#{HOMEBREW_PREFIX}/bin/npm"
90-
91-
# Let's do the manpage dance. It's just a jump to the left.
92-
# And then a step to the right, with your hand on rm_f.
93-
["man1", "man3", "man5", "man7"].each do |man|
94-
# Dirs must exist first: https://github.com/Homebrew/homebrew/issues/35969
95-
mkdir_p HOMEBREW_PREFIX/"share/man/#{man}"
96-
rm_f Dir[HOMEBREW_PREFIX/"share/man/#{man}/{npm.,npm-,npmrc.}*"]
97-
ln_sf Dir[libexec/"npm/share/man/#{man}/npm*"], HOMEBREW_PREFIX/"share/man/#{man}"
98-
end
99-
100-
npm_root = node_modules/"npm"
101-
npmrc = npm_root/"npmrc"
102-
npmrc.atomic_write("prefix = #{HOMEBREW_PREFIX}\n")
71+
npm_post_install libexec
10372
end
10473

10574
def caveats
10675
s = ""
10776

10877
if build.with? "npm"
10978
s += <<-EOS.undent
110-
If you update npm itself, do NOT use the npm update command.
111-
The upstream-recommended way to update npm is:
79+
npm has been installed. To update run
11280
npm install -g npm@latest
81+
82+
You can install global npm packages with
83+
npm install -g <package>
84+
85+
They will install into the global node_modiles directory
86+
/usr/local/lib/node_modules
87+
88+
Do NOT use the npm update command with global modules.
89+
The upstream-recommended way to update global modules is:
90+
npm install -g <package>@latest
11391
EOS
11492
else
11593
s += <<-EOS.undent
@@ -146,9 +124,7 @@ def caveats
146124
# make sure npm can find node
147125
ENV.prepend_path "PATH", opt_bin
148126
assert_equal which("node"), opt_bin/"node"
149-
assert (HOMEBREW_PREFIX/"bin/npm").exist?, "npm must exist"
150-
assert (HOMEBREW_PREFIX/"bin/npm").executable?, "npm must be executable"
151-
system "#{HOMEBREW_PREFIX}/bin/npm", "--verbose", "install", "npm@latest"
127+
npm_test_install
152128
end
153129
end
154130
end
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
module Language
2+
module JS
3+
def install_npm(path)
4+
# make sure npm can find node
5+
ENV.prepend_path "PATH", bin
6+
# make sure user prefix settings in $HOME are ignored
7+
ENV["HOME"] = buildpath/"home"
8+
# set log level temporarily for npm's `make install`
9+
ENV["NPM_CONFIG_LOGLEVEL"] = "verbose"
10+
11+
cd path do
12+
system "./configure", "--prefix=#{libexec}/npm"
13+
system "make", "install"
14+
end
15+
end
16+
17+
def install_npm_bash_completion (path)
18+
bash_completion.install \
19+
path/"lib/utils/completion.sh" => "npm"
20+
end
21+
22+
def npm_post_install(libexec)
23+
node_modules = HOMEBREW_PREFIX/"lib/node_modules"
24+
node_modules.mkpath
25+
npm_exec = node_modules/"npm/bin/npm-cli.js"
26+
# Kill npm but preserve all other modules across node updates/upgrades.
27+
rm_rf node_modules/"npm"
28+
29+
cp_r libexec/"npm/lib/node_modules/npm", node_modules
30+
# This symlink doesn't hop into homebrew_prefix/bin automatically so
31+
# remove it and make our own. This is a small consequence of our bottle
32+
# npm make install workaround. All other installs **do** symlink to
33+
# homebrew_prefix/bin correctly. We ln rather than cp this because doing
34+
# so mimics npm's normal install.
35+
ln_sf npm_exec, "#{HOMEBREW_PREFIX}/bin/npm"
36+
37+
# Let's do the manpage dance. It's just a jump to the left.
38+
# And then a step to the right, with your hand on rm_f.
39+
["man1", "man3", "man5", "man7"].each do |man|
40+
# Dirs must exist first: https://github.com/Homebrew/homebrew/issues/35969
41+
mkdir_p HOMEBREW_PREFIX/"share/man/#{man}"
42+
rm_f Dir[HOMEBREW_PREFIX/"share/man/#{man}/{npm.,npm-,npmrc.}*"]
43+
ln_sf Dir[libexec/"npm/share/man/#{man}/npm*"], HOMEBREW_PREFIX/"share/man/#{man}"
44+
end
45+
46+
npm_root = node_modules/"npm"
47+
npmrc = npm_root/"npmrc"
48+
npmrc.atomic_write("prefix = #{HOMEBREW_PREFIX}\n")
49+
end
50+
51+
def npm_test_install
52+
assert (HOMEBREW_PREFIX/"bin/npm").exist?, "npm must exist"
53+
assert (HOMEBREW_PREFIX/"bin/npm").executable?, "npm must be executable"
54+
system "#{HOMEBREW_PREFIX}/bin/npm", "--verbose", "install", "npm@latest"
55+
system "#{HOMEBREW_PREFIX}/bin/npm", "--verbose", "install", "buffertools"
56+
end
57+
end
58+
end

0 commit comments

Comments
 (0)