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

Commit f900829

Browse files
committed
node: install npm using tarball.
Install npm to the expected location using the upstream tarball. This should make everyone happier. Closes #27479.
1 parent 2803df4 commit f900829

File tree

1 file changed

+32
-57
lines changed

1 file changed

+32
-57
lines changed

Library/Formula/node.rb

Lines changed: 32 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,5 @@
11
require 'formula'
22

3-
class NpmRequirement < Requirement
4-
fatal true
5-
6-
def modules_folder
7-
"#{HOMEBREW_PREFIX}/lib/node_modules"
8-
end
9-
10-
def message; <<-EOS.undent
11-
Beginning with 0.8.0, this recipe now comes with npm.
12-
It appears you already have npm installed at #{modules_folder}/npm.
13-
To use the npm that comes with this recipe, first uninstall npm with
14-
`npm uninstall npm -g`, then run this command again.
15-
16-
If you would like to keep your installation of npm instead of
17-
using the one provided with homebrew, install the formula with
18-
the `--without-npm` option.
19-
EOS
20-
end
21-
22-
satisfy :build_env => false do
23-
begin
24-
path = Pathname.new("#{modules_folder}/npm/bin/npm")
25-
path.realpath.to_s.include?(HOMEBREW_CELLAR)
26-
rescue Errno::ENOENT
27-
true
28-
end
29-
end
30-
end
31-
323
# Note that x.even are stable releases, x.odd are devel releases
334
class Node < Formula
345
homepage 'http://nodejs.org/'
@@ -46,56 +17,58 @@ class Node < Formula
4617
option 'without-npm', 'npm will not be installed'
4718
option 'without-completion', 'npm bash completion will not be installed'
4819

49-
depends_on NpmRequirement => :recommended
5020
depends_on :python
5121

5222
fails_with :llvm do
5323
build 2326
5424
end
5525

56-
def install
57-
args = %W{--prefix=#{prefix}}
26+
resource "npm" do
27+
url "http://registry.npmjs.org/npm/-/npm-1.4.6.tgz"
28+
sha1 "0e151bce38e72cf2206a6299fa5164123f04256e"
29+
end
5830

31+
def install
32+
args = %W{--prefix=#{prefix} --without-npm}
5933
args << "--debug" if build.include? 'enable-debug'
60-
args << "--without-npm" if build.without? "npm"
6134

6235
system "./configure", *args
63-
system "make install"
36+
system "make", "install"
37+
38+
resource("npm").stage libexec/"npm" if build.with? "npm"
39+
end
6440

65-
if build.with? "npm"
66-
(lib/"node_modules/npm/npmrc").write("prefix = #{npm_prefix}\n")
41+
def post_install
42+
return if build.without? "npm"
6743

68-
# Link npm manpages
69-
Pathname.glob("#{lib}/node_modules/npm/man/*") do |man|
70-
dir = send(man.basename)
71-
man.children.each { |file| dir.install_symlink(file) }
72-
end
44+
node_modules = HOMEBREW_PREFIX/"lib/node_modules"
45+
node_modules.mkpath
46+
cp_r libexec/"npm", node_modules
7347

74-
if build.with? "completion"
75-
bash_completion.install_symlink \
76-
lib/"node_modules/npm/lib/utils/completion.sh" => "npm"
77-
end
48+
npm_root = node_modules/"npm"
49+
npmrc = npm_root/"npmrc"
50+
npmrc.delete if npmrc.exist?
51+
npmrc.write("prefix = #{HOMEBREW_PREFIX}\n")
52+
53+
npm_root.cd { system "make", "install" }
54+
system "#{HOMEBREW_PREFIX}/bin/npm", "update", "npm", "-g"
55+
56+
Pathname.glob(npm_root/"man/*") do |man|
57+
dir = send(man.basename)
58+
man.children.each {|file| dir.install_symlink(file) }
7859
end
79-
end
8060

81-
def npm_prefix
82-
d = "#{HOMEBREW_PREFIX}/share/npm"
83-
if File.directory? d
84-
d
85-
else
86-
HOMEBREW_PREFIX.to_s
61+
if build.with? "completion"
62+
bash_completion.install_symlink \
63+
npm_root/"lib/utils/completion.sh" => "npm"
8764
end
8865
end
8966

9067
def caveats
9168
if build.without? "npm"; <<-end.undent
9269
Homebrew has NOT installed npm. If you later install it, you should supplement
9370
your NODE_PATH with the npm module folder:
94-
#{npm_prefix}/lib/node_modules
95-
end
96-
elsif not ENV['PATH'].split(':').include? "#{npm_prefix}/bin"; <<-end.undent
97-
Probably you should amend your PATH to include npm-installed binaries:
98-
#{npm_prefix}/bin
71+
#{HOMEBREW_PREFIX}/lib/node_modules
9972
end
10073
end
10174
end
@@ -107,5 +80,7 @@ def caveats
10780
output = `#{bin}/node #{path}`.strip
10881
assert_equal "hello", output
10982
assert_equal 0, $?.exitstatus
83+
84+
system "#{HOMEBREW_PREFIX}/bin/npm", "install", "npm" if build.with? "npm"
11085
end
11186
end

0 commit comments

Comments
 (0)