Skip to content

Commit 0ae8409

Browse files
committed
[Fix] nvm install-latest-npm: ensure npm 9 does not install on unsupported nodes
1 parent 5e9791c commit 0ae8409

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

nvm.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ nvm_install_latest_npm() {
283283
if [ $NVM_IS_13_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 14.15.0; then
284284
NVM_IS_14_LTS_OR_ABOVE=1
285285
fi
286+
local NVM_IS_14_17_OR_ABOVE
287+
NVM_IS_14_17_OR_ABOVE=0
288+
if [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 14.17.0; then
289+
NVM_IS_14_17_OR_ABOVE=1
290+
fi
286291
local NVM_IS_15_OR_ABOVE
287292
NVM_IS_15_OR_ABOVE=0
288293
if [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 15.0.0; then
@@ -293,6 +298,21 @@ nvm_install_latest_npm() {
293298
if [ $NVM_IS_15_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 16.0.0; then
294299
NVM_IS_16_OR_ABOVE=1
295300
fi
301+
local NVM_IS_16_LTS_OR_ABOVE
302+
NVM_IS_16_LTS_OR_ABOVE=0
303+
if [ $NVM_IS_16_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 16.13.0; then
304+
NVM_IS_16_LTS_OR_ABOVE=1
305+
fi
306+
local NVM_IS_17_OR_ABOVE
307+
NVM_IS_17_OR_ABOVE=0
308+
if [ $NVM_IS_16_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 17.0.0; then
309+
NVM_IS_17_OR_ABOVE=1
310+
fi
311+
local NVM_IS_18_OR_ABOVE
312+
NVM_IS_18_OR_ABOVE=0
313+
if [ $NVM_IS_17_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 18.0.0; then
314+
NVM_IS_18_OR_ABOVE=1
315+
fi
296316

297317
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
298318
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
@@ -321,6 +341,14 @@ nvm_install_latest_npm() {
321341
; then
322342
nvm_echo '* `npm` `v7.x` is the last version that works on `node` `v13`, `v15`, below `v12.13`, or `v14.0` - `v14.15`'
323343
$NVM_NPM_CMD install -g npm@7
344+
elif \
345+
{ [ $NVM_IS_12_LTS_OR_ABOVE -eq 1 ] && [ $NVM_IS_13_OR_ABOVE -eq 0 ]; } \
346+
|| { [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && [ $NVM_IS_14_17_OR_ABOVE -eq 0 ]; } \
347+
|| { [ $NVM_IS_16_OR_ABOVE -eq 1 ] && [ $NVM_IS_16_LTS_OR_ABOVE -eq 0 ]; } \
348+
|| { [ $NVM_IS_17_OR_ABOVE -eq 1 ] && [ $NVM_IS_18_OR_ABOVE -eq 0 ]; } \
349+
; then
350+
nvm_echo '* `npm` `v8.x` is the last version that works on `node` `v12`, `v14.13` - `v14.16`, or `v16.0` - `v16.12`'
351+
$NVM_NPM_CMD install -g npm@8
324352
else
325353
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
326354
$NVM_NPM_CMD install -g npm

0 commit comments

Comments
 (0)