Skip to content

Commit d85c06f

Browse files
committed
Switch npm install based on node version
1 parent 7f79f02 commit d85c06f

File tree

1 file changed

+39
-13
lines changed

1 file changed

+39
-13
lines changed

scripts/install.sh

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,39 @@ else
137137
clean="no"
138138
fi
139139

140+
node_version=`"$node" --version 2>&1`
141+
ret=$?
142+
if [ $ret -ne 0 ]; then
143+
echo "You need node to run this program." >&2
144+
echo "node --version reports: $node_version" >&2
145+
echo "with exit code = $ret" >&2
146+
echo "Please install node before continuing." >&2
147+
exit $ret
148+
fi
149+
140150
t="${npm_install}"
141151
if [ -z "$t" ]; then
142-
t="latest"
152+
# switch based on node version.
153+
# note that we can only use strict sh-compatible patterns here.
154+
case $node_version in
155+
0.[0123].* | v0.[0123].*)
156+
echo "You are using an outdated and unsupported version of" >&2
157+
echo "node ($node_version). Please update node and try again." >&2
158+
exit 99
159+
;;
160+
v0.[45].* | 0.[45].*)
161+
echo "install npm@1.0"
162+
t=1.0
163+
;;
164+
v0.[678].* | 0.[678].*)
165+
echo "install npm@1.1"
166+
t=1.1
167+
;;
168+
*)
169+
echo "install npm@latest"
170+
t="latest"
171+
;;
172+
esac
143173
fi
144174

145175
# the npmca cert
@@ -196,22 +226,18 @@ cd "$TMP" \
196226
| $tar -xzf - \
197227
&& rm "$cacert" \
198228
&& cd "$TMP"/* \
199-
&& (node_version=`"$node" --version 2>&1`
200-
ret=$?
201-
if [ $ret -eq 0 ]; then
202-
req=`"$node" bin/read-package-json.js package.json engines.node`
203-
if [ -d node_modules ]; then
204-
"$node" node_modules/semver/bin/semver -v "$node_version" -r "$req"
205-
ret=$?
206-
else
207-
"$node" bin/semver.js -v "$node_version" -r "$req"
208-
ret=$?
209-
fi
229+
&& (req=`"$node" bin/read-package-json.js package.json engines.node`
230+
if [ -d node_modules ]; then
231+
"$node" node_modules/semver/bin/semver -v "$node_version" -r "$req"
232+
ret=$?
233+
else
234+
"$node" bin/semver.js -v "$node_version" -r "$req"
235+
ret=$?
210236
fi
211237
if [ $ret -ne 0 ]; then
212238
echo "You need node $req to run this program." >&2
213239
echo "node --version reports: $node_version" >&2
214-
echo "Please upgrade node before continuing."
240+
echo "Please upgrade node before continuing." >&2
215241
exit $ret
216242
fi) \
217243
&& (ver=`"$node" bin/read-package-json.js package.json version`

0 commit comments

Comments
 (0)