Compare commits

...
3 Commits
Author SHA1 Message Date
Jordan Harband 09e620c401 [Fix] nvm_download_artifact: without a checksum tool, fail before touching the cache or downloading
Tests: nvm install with set -e / test (push) Skipped
Code scanning - action / CodeQL-Build (push) Failing after 7m17s
Tests: `nvm install-latest-npm` / matrix (push) Failing after 3m40s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (push) Skipped
Tests: linting / eclint (push) Failing after 5m22s
Tests: linting / dockerfile_lint (push) Successful in 7m38s
Tests: linting / doctoc (push) Successful in 6m1s
Tests: linting / test_naming (push) Failing after 1m33s
Tests: linting / check_exec (push) Failing after 14s
Tests: linting / all linting (push) Skipped
Tests: nvm install with set -e / matrix (push) Failing after 32s
Tests: nvm install with set -e / finisher (push) Skipped
Tests: release process / release (push) Failing after 1m35s
Tests: shellcheck / shellcheck_matrix (bash_completion, bash) (push) Failing after 1h13m50s
Tests: shellcheck / shellcheck_matrix (install.sh, bash) (push) Failing after 46m19s
Tests: shellcheck / shellcheck_matrix (nvm-exec, bash) (push) Failing after 29m59s
Tests: shellcheck / shellcheck_matrix (nvm.sh, bash) (push) Failing after 6m7s
Tests: shellcheck / shellcheck_matrix (nvm.sh, ksh) (push) Failing after 4m27s
Tests: shellcheck / shellcheck_matrix (nvm.sh, sh) (push) Failing after 1m19s
Tests: alpine / fast x64 (alpine 3, bash) (push) Failing after 32s
Tests: alpine / fast x64 (alpine 3, dash) (push) Failing after 32s
Tests: shellcheck / shellcheck_matrix (nvm.sh, dash) (push) Failing after 12m8s
Tests: shellcheck / shellcheck (push) Skipped
Tests: alpine / fast x64 (alpine 3, sh) (push) Failing after 15m44s
Tests: alpine / fast x64 (alpine 3, zsh) (push) Failing after 15m36s
Tests: alpine / fast x64 (alpine 3.15, bash) (push) Failing after 22m5s
Tests: alpine / fast x64 (alpine 3.15, dash) (push) Failing after 15m34s
Tests: alpine / fast x64 (alpine 3.15, sh) (push) Failing after 15m38s
Tests: alpine / fast x64 (alpine 3.15, zsh) (push) Failing after 2m4s
Tests: alpine / fast x64 (alpine 3.19, bash) (push) Failing after 1m6s
Tests: alpine / fast x64 (alpine 3.19, dash) (push) Failing after 15m50s
Tests: alpine / fast x64 (alpine 3.19, sh) (push) Failing after 15m32s
Tests: alpine / fast x64 (alpine 3.19, zsh) (push) Failing after 21m53s
Tests: alpine / musl-binary x64 (alpine 3, node v22.12.0) (push) Failing after 14m12s
Tests: alpine / musl-binary x64 (alpine 3.10, node v10.24.1) (push) Failing after 14m12s
Tests: alpine / musl-binary x64 (alpine 3.10, node v8.17.0) (push) Failing after 14m12s
Tests: alpine / musl-binary x64 (alpine 3.12, node v12.22.12) (push) Failing after 14m12s
Tests: alpine / musl-binary x64 (alpine 3.15, node v14.21.3) (push) Failing after 14m12s
Tests: alpine / musl-binary x64 (alpine 3.16, node v16.20.2) (push) Failing after 14m14s
Tests: alpine / musl-binary x64 (alpine 3.18, node v18.20.4) (push) Failing after 14m12s
Tests: alpine / musl-binary x64 (alpine 3.20, node v20.18.1) (push) Failing after 14m12s
Tests: fast / fast (bash, gawk) (push) Failing after 1m33s
Tests: fast / fast (dash, gawk) (push) Failing after 32s
Tests: fast / fast (sh, gawk) (push) Failing after 32s
Tests: installation_iojs / actually compile io.js from source (gcc 4.9 container) (push) Failing after 31s
Tests: installation_iojs / all installation_iojs tests (push) Skipped
Tests: installation_node / installation_node (bash) (push) Failing after 15m36s
Tests: installation_node / installation_node (bash, without curl) (push) Failing after 22m25s
Tests: installation_node / installation_node (zsh, without curl) (push) Failing after 1m56s
Tests: installation_node / all installation_node tests (push) Skipped
Tests: xenial / xenial (bash) (push) Failing after 24m1s
Tests: xenial / xenial (dash) (push) Failing after 16m6s
Tests: xenial / xenial (sh) (push) Failing after 1m32s
urchin tests / tests (bash, install_script) (push) Failing after 32s
urchin tests / tests (dash, slow) (push) Failing after 7m21s
urchin tests / tests (sh, installation_iojs) (push) Failing after 2m14s
urchin tests / tests (sh, slow) (push) Failing after 2m34s
Tests: fast / fast (zsh, gawk) (push) Successful in 6m1s
Tests: fast / fast (bash, mawk) (push) Failing after 3m17s
Tests: fast / fast (dash, mawk) (push) Successful in 16m45s
Tests: fast / fast (sh, mawk) (push) Successful in 10m36s
Tests: fast / fast (zsh, mawk) (push) Failing after 1m4s
Tests: installation_iojs / installation_iojs without curl (bash) (push) Failing after 1m32s
Tests: installation_iojs / installation_iojs without curl (dash) (push) Failing after 1m32s
Tests: installation_iojs / installation_iojs without curl (sh) (push) Failing after 32s
Tests: installation_iojs / installation_iojs without curl (zsh) (push) Failing after 31s
Tests: installation_node / installation_node (dash) (push) Failing after 1m33s
Tests: installation_node / installation_node (dash, without curl) (push) Failing after 10m45s
Tests: installation_node / installation_node (sh) (push) Failing after 32s
Tests: installation_node / installation_node (sh, without curl) (push) Failing after 32s
Tests: installation_node / installation_node (zsh) (push) Failing after 32s
Tests: xenial / xenial (zsh) (push) Failing after 1m33s
Tests: xenial / all xenial tests (push) Skipped
urchin tests / tests (bash, installation_iojs) (push) Failing after 1m51s
urchin tests / tests (bash, slow) (push) Failing after 33s
urchin tests / tests (bash, sourcing) (push) Successful in 10m21s
urchin tests / tests (dash, installation_iojs) (push) Failing after 10m0s
urchin tests / tests (dash, sourcing) (push) Failing after 1m53s
urchin tests / tests (zsh, slow) (push) Failing after 32s
urchin tests / tests (sh, sourcing) (push) Failing after 1m34s
urchin tests / tests (zsh, installation_iojs) (push) Failing after 32s
urchin tests / tests (zsh, sourcing) (push) Failing after 34s
urchin tests / all test suites, all shells (push) Skipped
update readme TOC / update readme TOC (push) Failing after 32s
Tests: alpine / fast arm64 (alpine 3, bash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3, dash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3, sh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3, zsh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, bash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, dash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, sh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, zsh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.19, bash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.19, dash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.19, sh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.19, zsh) (push) Canceled after 0s
Tests: alpine / musl-binary arm64 (alpine 3, node v22.21.1) (push) Canceled after 0s
Tests: alpine / musl-binary arm64 (alpine 3, node v24.9.0) (push) Canceled after 0s
Tests: alpine / musl-binary arm64 (alpine 3.20, node v20.20.1) (push) Canceled after 0s
Tests: alpine / all alpine tests (push) Canceled after 0s
Tests: fast / fast (macOS, bash) (push) Canceled after 0s
Tests: fast / fast (macOS, dash) (push) Canceled after 0s
Tests: fast / fast (macOS, sh) (push) Canceled after 0s
Tests: fast / fast (macOS, zsh) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, bash) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, dash) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, sh) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, zsh) (push) Canceled after 0s
Tests: fast / all fast tests (push) Canceled after 0s
Tests on Windows: `nvm install` / MSYS fail prefix nvm install (push) Canceled after 0s
Tests on Windows: `nvm install` / MSYS nvm install (--default 12) (push) Canceled after 0s
Tests on Windows: `nvm install` / MSYS nvm install (--lts) (push) Canceled after 0s
Tests on Windows: `nvm install` / MSYS nvm install (--no-progress 10) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 18, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 18, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 18, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 18, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 21, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 21, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 21, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 21, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Debian-12) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Debian-13) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Ubuntu-20.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Ubuntu-24.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, --lts, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, --lts, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 10, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 11, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 11, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 12, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 14, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 16, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 18, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 18, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 21, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (, 21, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, --lts, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, --lts, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 11, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 11, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Alpine-3.17) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Alpine-3.23) (push) Canceled after 0s
Tests on Windows: `nvm install` / tests, on windows (push) Canceled after 0s
Tests on Windows: `nvm install` / Cygwin nvm install (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-18.04) (push) Canceled after 0s
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Ubuntu-20.04) (push) Canceled after 0s
Previously, every download was refused only after it was fetched,
a verified cached archive was deleted as "broken",
and the source fallback then downloaded a second archive that was refused the same way,
with no message saying what to install.
2026-11-11 15:23:25 -08:00
NUAAwqyandJordan Harband 362f5e2c71 [Breaking] nvm_compare_checksum: refuse a file whose checksum cannot be verified
The empty-computed-sum branch ended with a bare `return`,
whose status is that of the preceding `nvm_err`, which is 0.
Callers treat 0 as "verified",
so an artifact that could not be verified was installed anyway,
and was even moved into the verified cache slot,
violating nvm.sh's own invariant that only a verified archive may sit at ${TARBALL}
(a later `--offline` install would then use it without any verification).

Return 1 so the artifact is rejected, as intended by #1858.

Fixes #1858

Signed-off-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
Co-authored-by: NUAAwqy <146524024+NUAAwqy@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-11-06 03:13:03 +00:00
Iain 015c4f1e3b [Fix] install-latest-npm: npm v12 is out 2026-11-11 12:55:38 +00:00
6 changed files with 97 additions and 7 deletions

No files matched your search

+2
View File
@@ -37,6 +37,8 @@ jobs:
matrix: matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }} node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
include: include:
- node-version: "24.14"
- node-version: "22.22.1"
- node-version: "21" - node-version: "21"
- node-version: "20.5" - node-version: "20.5"
- node-version: "20.4" - node-version: "20.4"
+1 -1
View File
@@ -540,7 +540,7 @@ nvm install --offline 14.7.0
This resolves versions using only locally installed versions and cached downloads. It will not attempt to download anything. This is useful in air-gapped environments, on planes, or when you want to avoid network latency. This resolves versions using only locally installed versions and cached downloads. It will not attempt to download anything. This is useful in air-gapped environments, on planes, or when you want to avoid network latency.
A download is only added to the cache (`$NVM_DIR/.cache`) once its checksum has been verified (unless no checksum tool is available, in which case `nvm` warns that it is continuing without verification). `--offline` does not verify cached archives again, so anything placed in the cache by other means is trusted as-is. A download is only added to the cache (`$NVM_DIR/.cache`) once its checksum has been verified. `--offline` does not verify cached archives again, so anything placed in the cache by other means is trusted as-is.
You can combine `--offline` with `--lts` to install the latest cached LTS version (as long as LTS aliases have been populated by a prior `nvm ls-remote --lts`): You can combine `--offline` with `--lts` to install the latest cached LTS version (as long as LTS aliases have been populated by a prior `nvm ls-remote --lts`):
+41 -3
View File
@@ -680,6 +680,31 @@ nvm_install_latest_npm() {
if [ $NVM_IS_21_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 22.9.0; then if [ $NVM_IS_21_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 22.9.0; then
NVM_IS_22_9_OR_ABOVE=1 NVM_IS_22_9_OR_ABOVE=1
fi fi
local NVM_IS_22_22_2_OR_ABOVE
NVM_IS_22_22_2_OR_ABOVE=0
if [ $NVM_IS_22_9_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 22.22.2; then
NVM_IS_22_22_2_OR_ABOVE=1
fi
local NVM_IS_23_OR_ABOVE
NVM_IS_23_OR_ABOVE=0
if [ $NVM_IS_22_22_2_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 23.0.0; then
NVM_IS_23_OR_ABOVE=1
fi
local NVM_IS_24_15_OR_ABOVE
NVM_IS_24_15_OR_ABOVE=0
if [ $NVM_IS_23_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 24.15.0; then
NVM_IS_24_15_OR_ABOVE=1
fi
local NVM_IS_25_OR_ABOVE
NVM_IS_25_OR_ABOVE=0
if [ $NVM_IS_24_15_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 25.0.0; then
NVM_IS_25_OR_ABOVE=1
fi
local NVM_IS_26_OR_ABOVE
NVM_IS_26_OR_ABOVE=0
if [ $NVM_IS_25_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 26.0.0; then
NVM_IS_26_OR_ABOVE=1
fi
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || { if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || {
[ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \ [ $NVM_IS_5_OR_ABOVE -eq 1 ] && nvm_version_greater 5.10.0 "${NODE_VERSION}"; \
@@ -734,6 +759,13 @@ nvm_install_latest_npm() {
; then ; then
nvm_echo '* `npm` `v10.x` is the last version that works on `node` `< v20.17`, `v21`, or `v22.0` - `v22.8`' nvm_echo '* `npm` `v10.x` is the last version that works on `node` `< v20.17`, `v21`, or `v22.0` - `v22.8`'
$NVM_NPM_CMD install -g npm@10 $NVM_NPM_CMD install -g npm@10
elif \
[ $NVM_IS_22_22_2_OR_ABOVE -eq 0 ] \
|| { [ $NVM_IS_23_OR_ABOVE -eq 1 ] && [ $NVM_IS_24_15_OR_ABOVE -eq 0 ]; } \
|| { [ $NVM_IS_25_OR_ABOVE -eq 1 ] && [ $NVM_IS_26_OR_ABOVE -eq 0 ]; } \
; then
nvm_echo '* `npm` `v11.x` is the last version that works on `node` `< v22.22.2`, `v23`, `v24.0` - `v24.14`, or `v25`'
$NVM_NPM_CMD install -g npm@11
else else
nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!' nvm_echo '* Installing latest `npm`; if this does not work on your node version, please report a bug!'
$NVM_NPM_CMD install -g npm $NVM_NPM_CMD install -g npm
@@ -2971,8 +3003,8 @@ nvm_compare_checksum() {
if [ -z "${COMPUTED_SUM}" ]; then if [ -z "${COMPUTED_SUM}" ]; then
nvm_err "Computed checksum of '${FILE}' is empty." # missing in raspberry pi binary nvm_err "Computed checksum of '${FILE}' is empty." # missing in raspberry pi binary
nvm_err 'WARNING: Continuing *without checksum verification*' nvm_err 'Refusing to continue *without checksum verification*'
return return 1
elif [ "${COMPUTED_SUM}" != "${CHECKSUM}" ] && [ "${COMPUTED_SUM}" != "\\${CHECKSUM}" ]; then elif [ "${COMPUTED_SUM}" != "${CHECKSUM}" ] && [ "${COMPUTED_SUM}" != "\\${CHECKSUM}" ]; then
nvm_err "Checksums do not match: '${COMPUTED_SUM}' found, '${CHECKSUM}' expected." nvm_err "Checksums do not match: '${COMPUTED_SUM}' found, '${CHECKSUM}' expected."
return 1 return 1
@@ -3884,6 +3916,12 @@ nvm_download_artifact() {
return 4 return 4
fi fi
# nothing can be verified without a checksum tool, so fail before touching the cache or downloading
if ! nvm_get_checksum_binary >/dev/null; then
nvm_err 'Install one of them so that nvm can verify downloads.'
return 6
fi
local CHECKSUM local CHECKSUM
CHECKSUM="$(nvm_get_checksum "${FLAVOR}" "${TYPE}" "${VERSION}" "${SLUG}" "${COMPRESSION}")" CHECKSUM="$(nvm_get_checksum "${FLAVOR}" "${TYPE}" "${VERSION}" "${SLUG}" "${COMPRESSION}")"
@@ -3909,7 +3947,7 @@ nvm_download_artifact() {
fi fi
nvm_compare_checksum "${TARBALL}" "${CHECKSUM}" nvm_compare_checksum "${TARBALL}" "${CHECKSUM}"
nvm_err "Checksum check failed!" nvm_err "Checksum check failed!"
nvm_err "Removing the broken local cache..." nvm_err "Removing the unverified local cache..."
command rm -rf "${TARBALL}" command rm -rf "${TARBALL}"
fi fi
# `--offline` uses the cached archive without a checksum, so only a verified archive may ever sit at ${TARBALL} # `--offline` uses the cached archive without a checksum, so only a verified archive may ever sit at ${TARBALL}
+2 -2
View File
@@ -33,9 +33,9 @@ EXPECTED_OUTPUT='Provided checksum to compare to is empty.'
try_err nvm_compare_checksum ../../../nvm.sh checksum try_err nvm_compare_checksum ../../../nvm.sh checksum
EXPECTED_OUTPUT="Computed checksum of '../../../nvm.sh' is empty. EXPECTED_OUTPUT="Computed checksum of '../../../nvm.sh' is empty.
WARNING: Continuing *without checksum verification*" Refusing to continue *without checksum verification*"
[ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<" [ "${CAPTURED_STDERR}" = "${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<, got >${CAPTURED_STDERR}<"
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected to exit with code 0, got ${CAPTURED_EXIT_CODE}" [ "${CAPTURED_EXIT_CODE}" = 1 ] || die "expected to exit with code 1, got ${CAPTURED_EXIT_CODE}"
nvm_compute_checksum() { nvm_compute_checksum() {
echo "not checksum: ${1}" echo "not checksum: ${1}"
@@ -4,7 +4,7 @@ WORK="${TMPDIR:-/tmp}/nvm_download_artifact_cache.$$"
cleanup () { cleanup () {
command rm -rf "${WORK}" command rm -rf "${WORK}"
unset -f cleanup die download_offline nvm_get_mirror nvm_binary_available nvm_get_download_slug nvm_get_artifact_compression nvm_cache_dir nvm_get_checksum nvm_version_greater_than_or_equal_to nvm_download nvm_compare_checksum unset -f cleanup die download_offline nvm_get_mirror nvm_binary_available nvm_get_download_slug nvm_get_artifact_compression nvm_cache_dir nvm_get_checksum nvm_version_greater_than_or_equal_to nvm_download nvm_compute_checksum nvm_compare_checksum nvm_get_checksum_binary
} }
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
@@ -57,6 +57,22 @@ try download_offline
[ "${CAPTURED_EXIT_CODE}" = '4' ] || die "empty checksum: expected --offline to find no cached archive (exit code 4), got ${CAPTURED_EXIT_CODE}" [ "${CAPTURED_EXIT_CODE}" = '4' ] || die "empty checksum: expected --offline to find no cached archive (exit code 4), got ${CAPTURED_EXIT_CODE}"
nvm_get_checksum() { nvm_echo 'fake_checksum'; } nvm_get_checksum() { nvm_echo 'fake_checksum'; }
# a download whose checksum cannot be computed has not been verified, so it must not be accepted either
# (this still uses the real `nvm_compare_checksum`, so it runs before that is mocked)
nvm_compute_checksum() { nvm_echo ''; }
try nvm_download_artifact node binary std v20.0.0
[ "${CAPTURED_EXIT_CODE}" = '6' ] || die "unverifiable checksum: expected exit code 6, got ${CAPTURED_EXIT_CODE}"
[ ! -e "${TEST_CACHE_DIR}" ] || die "unverifiable checksum: expected ${TEST_CACHE_DIR} to be removed"
try download_offline
[ "${CAPTURED_EXIT_CODE}" = '4' ] || die "unverifiable checksum: expected --offline to find no cached archive (exit code 4), got ${CAPTURED_EXIT_CODE}"
# nor may a cached archive whose checksum cannot be computed be used
command mkdir -p "${TEST_CACHE_DIR}"
nvm_echo 'cached' > "${TEST_TARBALL}"
try nvm_download_artifact node binary std v20.0.0
[ "${CAPTURED_EXIT_CODE}" = '6' ] || die "unverifiable cached archive: expected exit code 6, got ${CAPTURED_EXIT_CODE}"
[ ! -e "${TEST_CACHE_DIR}" ] || die "unverifiable cached archive: expected ${TEST_CACHE_DIR} to be removed"
# a download that fails its checksum must not be left in the cache either # a download that fails its checksum must not be left in the cache either
nvm_compare_checksum() { return 1; } nvm_compare_checksum() { return 1; }
try nvm_download_artifact node binary std v20.0.0 try nvm_download_artifact node binary std v20.0.0
@@ -76,4 +92,11 @@ try nvm_download_artifact node binary std v20.0.0
[ ! -e "${TEST_TARBALL}.unverified" ] || die 'verified download: expected no unverified download to remain in the cache' [ ! -e "${TEST_TARBALL}.unverified" ] || die 'verified download: expected no unverified download to remain in the cache'
[ ! -e "${WORK}/downloaded-to-final-name" ] || die 'an unverified download was written to the final cache name, where an interrupted download would be left for --offline' [ ! -e "${WORK}/downloaded-to-final-name" ] || die 'an unverified download was written to the final cache name, where an interrupted download would be left for --offline'
# without any checksum tool, nothing is downloaded and the verified cache is left alone
nvm_get_checksum_binary() { return 1; }
try nvm_download_artifact node binary std v20.0.0
[ "${CAPTURED_EXIT_CODE}" = '6' ] || die "no checksum tool: expected exit code 6, got ${CAPTURED_EXIT_CODE}"
[ "$(command cat "${TEST_TARBALL}")" = 'downloaded' ] || die "no checksum tool: expected the cached archive to be left alone, got >$(command cat "${TEST_TARBALL}")<"
[ ! -e "${TEST_TARBALL}.unverified" ] || die 'no checksum tool: expected nothing to be downloaded'
cleanup cleanup
@@ -54,3 +54,30 @@ try_err nvm_install_latest_npm
EXPECTED="Unable to obtain npm version." EXPECTED="Unable to obtain npm version."
[ "${CAPTURED_STDERR}" = "${EXPECTED}" ] || die "When node is system and npm is unavailable, expected >${EXPECTED}<; got >${CAPTURED_STDERR}" [ "${CAPTURED_STDERR}" = "${EXPECTED}" ] || die "When node is system and npm is unavailable, expected >${EXPECTED}<; got >${CAPTURED_STDERR}"
nvm_ls_current() {
node --version
}
node() {
echo "${TEST_NODE_VERSION}"
}
npm() {
case "${1-}" in
--version) echo '10.9.0' ;;
*) echo "npm $*" ;;
esac
}
for TEST_NODE_VERSION in v21.7.3 v22.8.0; do
OUTPUT="$(nvm_install_latest_npm | grep 'install -g')"
[ "${OUTPUT}" = 'npm install -g npm@10' ] || die "on node ${TEST_NODE_VERSION}, expected npm@10; got >${OUTPUT}<"
done
for TEST_NODE_VERSION in v20.17.0 v22.9.0 v22.22.1 v23.0.0 v24.14.1 v25.0.0; do
OUTPUT="$(nvm_install_latest_npm | grep 'install -g')"
[ "${OUTPUT}" = 'npm install -g npm@11' ] || die "on node ${TEST_NODE_VERSION}, expected npm@11; got >${OUTPUT}<"
done
for TEST_NODE_VERSION in v22.22.2 v24.15.0 v26.0.0; do
OUTPUT="$(nvm_install_latest_npm | grep 'install -g')"
[ "${OUTPUT}" = 'npm install -g npm' ] || die "on node ${TEST_NODE_VERSION}, expected the latest npm; got >${OUTPUT}<"
done