Skip to content

Commit a781acb

Browse files
committed
[Fix] nvm install-latest-npm: ensure npm 8 does not install on unsupported nodes
1 parent 7b530ed commit a781acb

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

.github/workflows/latest-npm.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
node-version:
16+
- "16"
17+
- "15"
18+
- "14"
19+
- "13"
20+
- "12"
1621
- "11"
1722
- "10"
1823
- "9"

nvm.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,31 @@ nvm_install_latest_npm() {
268268
if [ $NVM_IS_9_3_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 10.0.0; then
269269
NVM_IS_10_OR_ABOVE=1
270270
fi
271+
local NVM_IS_12_LTS_OR_ABOVE
272+
NVM_IS_12_LTS_OR_ABOVE=0
273+
if [ $NVM_IS_10_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 12.13.0; then
274+
NVM_IS_12_LTS_OR_ABOVE=1
275+
fi
276+
local NVM_IS_13_OR_ABOVE
277+
NVM_IS_13_OR_ABOVE=0
278+
if [ $NVM_IS_12_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 13.0.0; then
279+
NVM_IS_13_OR_ABOVE=1
280+
fi
281+
local NVM_IS_14_LTS_OR_ABOVE
282+
NVM_IS_14_LTS_OR_ABOVE=0
283+
if [ $NVM_IS_13_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 14.15.0; then
284+
NVM_IS_14_LTS_OR_ABOVE=1
285+
fi
286+
local NVM_IS_15_OR_ABOVE
287+
NVM_IS_15_OR_ABOVE=0
288+
if [ $NVM_IS_14_LTS_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 15.0.0; then
289+
NVM_IS_15_OR_ABOVE=1
290+
fi
291+
local NVM_IS_16_OR_ABOVE
292+
NVM_IS_16_OR_ABOVE=0
293+
if [ $NVM_IS_15_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 16.0.0; then
294+
NVM_IS_16_OR_ABOVE=1
295+
fi
271296

272297
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
273298
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
@@ -289,6 +314,13 @@ nvm_install_latest_npm() {
289314
elif [ $NVM_IS_10_OR_ABOVE -eq 0 ]; then
290315
nvm_echo '* `npm` `v6.x` is the last version that works on `node` below `v10.0.0`'
291316
$NVM_NPM_CMD install -g npm@6
317+
elif \
318+
[ $NVM_IS_12_LTS_OR_ABOVE -eq 0 ] \
319+
|| { [ $NVM_IS_13_OR_ABOVE -eq 1 ] && [ $NVM_IS_14_LTS_OR_ABOVE -eq 0 ]; } \
320+
|| { [ $NVM_IS_15_OR_ABOVE -eq 1 ] && [ $NVM_IS_16_OR_ABOVE -eq 0 ]; } \
321+
; then
322+
nvm_echo '* `npm` `v7.x` is the last version that works on `node` `v13`, `v15`, below `v12.13`, or `v14.0` - `v14.15`'
323+
$NVM_NPM_CMD install -g npm@7
292324
else
293325
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
294326
$NVM_NPM_CMD install -g npm

test/installation_node/install latest npm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ set +e # todo: fix
88
\. ../../nvm.sh
99
set -e
1010

11+
nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 1'
12+
nvm install 12.12 >/dev/null 2>&1 || die 'install v12.12 failed'
13+
nvm install-latest-npm || die 'nvm install-latest-npm failed: 1'
14+
NPM_VERSION="$(npm --version)"
15+
nvm_version_greater_than_or_equal_to "${NPM_VERSION}" 7.0.0 \
16+
&& nvm_version_greater 8.0.0 "${NPM_VERSION}" || die "node v12.12 updates to ${NPM_VERSION}; expected v7"
17+
1118
nvm deactivate >/dev/null 2>&1 || die 'unable to deactivate: 1'
1219
nvm install 4 >/dev/null 2>&1 || die 'install v4 failed'
1320
nvm install-latest-npm || die 'nvm install-latest-npm failed: 1'

0 commit comments

Comments
 (0)