1
1
require 'formula'
2
2
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
-
32
3
# Note that x.even are stable releases, x.odd are devel releases
33
4
class Node < Formula
34
5
homepage 'http://nodejs.org/'
@@ -46,56 +17,58 @@ class Node < Formula
46
17
option 'without-npm' , 'npm will not be installed'
47
18
option 'without-completion' , 'npm bash completion will not be installed'
48
19
49
- depends_on NpmRequirement => :recommended
50
20
depends_on :python
51
21
52
22
fails_with :llvm do
53
23
build 2326
54
24
end
55
25
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
58
30
31
+ def install
32
+ args = %W{ --prefix=#{ prefix } --without-npm }
59
33
args << "--debug" if build . include? 'enable-debug'
60
- args << "--without-npm" if build . without? "npm"
61
34
62
35
system "./configure" , *args
63
- system "make install"
36
+ system "make" , "install"
37
+
38
+ resource ( "npm" ) . stage libexec /"npm" if build . with? "npm"
39
+ end
64
40
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"
67
43
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
73
47
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 ) }
78
59
end
79
- end
80
60
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"
87
64
end
88
65
end
89
66
90
67
def caveats
91
68
if build . without? "npm" ; <<-end . undent
92
69
Homebrew has NOT installed npm. If you later install it, you should supplement
93
70
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
99
72
end
100
73
end
101
74
end
@@ -107,5 +80,7 @@ def caveats
107
80
output = `#{ bin } /node #{ path } ` . strip
108
81
assert_equal "hello" , output
109
82
assert_equal 0 , $?. exitstatus
83
+
84
+ system "#{ HOMEBREW_PREFIX } /bin/npm" , "install" , "npm" if build . with? "npm"
110
85
end
111
86
end
0 commit comments