1
+ require "language/javascript"
2
+
1
3
# Note that x.even are stable releases, x.odd are devel releases
2
4
class Node < Formula
5
+ include Language ::JS
6
+
3
7
homepage "https://nodejs.org/"
4
8
url "https://nodejs.org/dist/v0.12.0/node-v0.12.0.tar.gz"
5
9
sha256 "9700e23af4e9b3643af48cef5f2ad20a1331ff531a12154eef2bfb0bb1682e32"
@@ -12,6 +16,8 @@ class Node < Formula
12
16
sha1 "8312e7ea6ffec58e39ec7cc1f8671847a9d7b4bf" => :mountain_lion
13
17
end
14
18
19
+ conflicts_with "iojs" , :because => "node and iojs both install a binary/link named node"
20
+
15
21
option "with-debug" , "Build with debugger hooks"
16
22
option "without-npm" , "npm will not be installed"
17
23
option "without-completion" , "npm bash completion will not be installed"
@@ -50,66 +56,38 @@ def install
50
56
system "make" , "install"
51
57
52
58
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
66
61
67
62
if build . with? "completion"
68
- bash_completion . install \
69
- buildpath /"npm_install/lib/utils/completion.sh" => "npm"
63
+ install_npm_bash_completion npm_buildpath
70
64
end
71
65
end
72
66
end
73
67
74
68
def post_install
75
69
return if build . without? "npm"
76
70
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
103
72
end
104
73
105
74
def caveats
106
75
s = ""
107
76
108
77
if build . with? "npm"
109
78
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
112
80
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
113
91
EOS
114
92
else
115
93
s += <<-EOS . undent
@@ -146,9 +124,7 @@ def caveats
146
124
# make sure npm can find node
147
125
ENV . prepend_path "PATH" , opt_bin
148
126
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
152
128
end
153
129
end
154
130
end
0 commit comments