Compare commits

...
36 Commits
Author SHA1 Message Date
ii1818nn ea0fcdbe16 [readme] Ansible: use ansible_facts.env rather than the deprecated injected ansible_env
Tests: alpine / fast arm64 (alpine 3, bash) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.15, bash) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.15, sh) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.19, bash) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.19, dash) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.19, zsh) (push) Waiting to run
Tests: fast / fast (macOS, bash) (push) Waiting to run
Tests: fast / fast (macOS, dash) (push) Waiting to run
Tests: fast / fast (macOS, zsh) (push) Waiting to run
Tests: fast / fast (WSL Ubuntu-24.04, dash) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 18, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 21, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / MSYS nvm install (--default 12) (push) Waiting to run
Tests on Windows: `nvm install` / MSYS nvm install (--lts) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 21, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Debian-13) (push) Waiting to run
Tests: `nvm install-latest-npm` / matrix (push) Successful in 1m1s
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, --lts, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, --lts, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 18, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 21, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, --lts, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, --lts, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 11, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 11, Alpine-3.23) (push) Waiting to run
Code scanning - action / CodeQL-Build (push) Failing after 3m59s
Tests: linting / doctoc (push) Failing after 5s
Tests: linting / all linting (push) Skipped
Tests: nvm install with set -e / matrix (push) Failing after 5s
Tests: nvm install with set -e / finisher (push) Skipped
Tests: release process / release (push) Failing after 5s
Tests: shellcheck / shellcheck_matrix (bash_completion, bash) (push) Failing after 6s
Tests: shellcheck / shellcheck_matrix (nvm-exec, bash) (push) Failing after 5s
Tests: shellcheck / shellcheck_matrix (nvm.sh, ksh) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3, bash) (push) Failing after 6s
Tests: alpine / fast x64 (alpine 3, dash) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3, sh) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3.15, dash) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3.19, dash) (push) Failing after 6s
Tests: alpine / fast x64 (alpine 3.19, sh) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3.19, zsh) (push) Failing after 5s
Tests: alpine / musl-binary x64 (alpine 3.12, node v12.22.12) (push) Failing after 6s
Tests: alpine / musl-binary x64 (alpine 3.15, node v14.21.3) (push) Failing after 5s
Tests: alpine / musl-binary x64 (alpine 3.20, node v20.18.1) (push) Failing after 6s
Tests: fast / fast (bash, gawk) (push) Failing after 6s
Tests: fast / fast (dash, gawk) (push) Failing after 5s
Tests: fast / fast (sh, gawk) (push) Failing after 5s
Tests: fast / fast (zsh, gawk) (push) Failing after 5s
Tests: fast / fast (bash, mawk) (push) Failing after 6s
Tests: installation_iojs / installation_iojs without curl (bash) (push) Failing after 5s
Tests: installation_iojs / installation_iojs without curl (dash) (push) Failing after 5s
Tests: installation_iojs / installation_iojs without curl (sh) (push) Failing after 5s
Tests: installation_node / installation_node (dash, without curl) (push) Failing after 5s
Tests: installation_node / installation_node (sh) (push) Failing after 5s
Tests: installation_node / installation_node (sh, without curl) (push) Failing after 6s
Tests: installation_node / installation_node (zsh) (push) Failing after 5s
Tests: xenial / xenial (dash) (push) Failing after 5s
Tests: xenial / all xenial tests (push) Skipped
urchin tests / tests (bash, install_script) (push) Failing after 6s
urchin tests / tests (dash, sourcing) (push) Failing after 5s
urchin tests / tests (sh, sourcing) (push) Failing after 5s
urchin tests / tests (zsh, sourcing) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (0.10) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (0.12) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (1) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (16) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (17) (push) Failing after 1m30s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (18) (push) Successful in 1m55s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (19) (push) Successful in 7m37s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (2) (push) Successful in 1m43s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (20) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (24.14) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (26) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (3) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (4) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (5) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (8) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (9) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (9.0) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (9.1) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (push) Skipped
Tests: alpine / fast arm64 (alpine 3, dash) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.15, dash) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.15, zsh) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3.19, sh) (push) Waiting to run
Tests: alpine / musl-binary arm64 (alpine 3, node v22.21.1) (push) Waiting to run
Tests: alpine / musl-binary arm64 (alpine 3, node v24.9.0) (push) Waiting to run
Tests: fast / fast (macOS, sh) (push) Waiting to run
Tests: fast / fast (WSL Ubuntu-24.04, bash) (push) Waiting to run
Tests: fast / fast (WSL Ubuntu-24.04, zsh) (push) Waiting to run
Tests on Windows: `nvm install` / MSYS nvm install (--no-progress 10) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 18, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 18, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 18, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 21, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / MSYS fail prefix nvm install (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Debian-12) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 10, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 11, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 11, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 18, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Alpine-3.23) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Alpine-3.23) (push) Waiting to run
Tests: linting / eclint (push) Failing after 6s
Tests: linting / dockerfile_lint (push) Failing after 5s
Tests: linting / check_exec (push) Failing after 5s
Tests: nvm install with set -e / test (push) Skipped
Tests: shellcheck / shellcheck_matrix (install.sh, bash) (push) Failing after 5s
Tests: shellcheck / shellcheck_matrix (nvm.sh, bash) (push) Failing after 5s
Tests: shellcheck / shellcheck_matrix (nvm.sh, dash) (push) Failing after 6s
Tests: shellcheck / shellcheck_matrix (nvm.sh, sh) (push) Failing after 5s
Tests: shellcheck / shellcheck (push) Skipped
Tests: alpine / fast x64 (alpine 3, zsh) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3.15, bash) (push) Failing after 7s
Tests: alpine / fast x64 (alpine 3.15, sh) (push) Failing after 5s
Tests: alpine / fast x64 (alpine 3.15, zsh) (push) Failing after 6s
Tests: alpine / fast x64 (alpine 3.19, bash) (push) Failing after 6s
Tests: alpine / musl-binary x64 (alpine 3, node v22.12.0) (push) Failing after 7s
Tests: alpine / musl-binary x64 (alpine 3.10, node v10.24.1) (push) Failing after 6s
Tests: alpine / musl-binary x64 (alpine 3.10, node v8.17.0) (push) Failing after 5s
Tests: alpine / musl-binary x64 (alpine 3.16, node v16.20.2) (push) Failing after 6s
Tests: alpine / musl-binary x64 (alpine 3.18, node v18.20.4) (push) Failing after 5s
Tests: fast / fast (dash, mawk) (push) Failing after 5s
Tests: fast / fast (sh, mawk) (push) Failing after 5s
Tests: fast / fast (zsh, mawk) (push) Failing after 6s
Tests: installation_iojs / installation_iojs without curl (zsh) (push) Failing after 5s
Tests: installation_iojs / actually compile io.js from source (gcc 4.9 container) (push) Failing after 5s
Tests: installation_iojs / all installation_iojs tests (push) Skipped
Tests: installation_node / installation_node (bash) (push) Failing after 6s
Tests: installation_node / installation_node (dash) (push) Failing after 5s
Tests: installation_node / installation_node (zsh, without curl) (push) Failing after 5s
Tests: installation_node / all installation_node tests (push) Skipped
Tests: xenial / xenial (bash) (push) Failing after 6s
Tests: xenial / xenial (sh) (push) Failing after 5s
Tests: xenial / xenial (zsh) (push) Failing after 5s
urchin tests / tests (bash, installation_iojs) (push) Failing after 5s
urchin tests / tests (bash, slow) (push) Failing after 5s
urchin tests / tests (bash, sourcing) (push) Failing after 6s
urchin tests / tests (dash, installation_iojs) (push) Failing after 5s
urchin tests / tests (dash, slow) (push) Failing after 5s
urchin tests / tests (sh, installation_iojs) (push) Failing after 5s
urchin tests / tests (sh, slow) (push) Failing after 5s
urchin tests / tests (zsh, installation_iojs) (push) Failing after 5s
urchin tests / tests (zsh, slow) (push) Failing after 5s
urchin tests / all test suites, all shells (push) Skipped
Tests: `nvm install-latest-npm` / nvm install-latest-npm (10) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (11) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (12) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (13) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (14) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (14.16) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (14.17) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (15) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (20.4) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (21) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (22) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (22.22.1) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (23) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (24) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (25) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (4.4) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (4.5) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (5.9) (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (6) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (7) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (9.2) (push) Failing after 5s
Tests: alpine / fast arm64 (alpine 3, sh) (push) Waiting to run
Tests: alpine / fast arm64 (alpine 3, zsh) (push) Waiting to run
Tests: alpine / musl-binary arm64 (alpine 3.20, node v20.20.1) (push) Waiting to run
Tests: fast / fast (WSL Ubuntu-24.04, sh) (push) Waiting to run
Tests on Windows: `nvm install` / Cygwin nvm install (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 21, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Debian-13) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-18.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Ubuntu-20.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Ubuntu-24.04) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (, 21, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Alpine-3.17) (push) Waiting to run
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Alpine-3.23) (push) Waiting to run
Tests: linting / test_naming (push) Failing after 5s
Tests: installation_node / installation_node (bash, without curl) (push) Failing after 5s
update readme TOC / update readme TOC (push) Failing after 6s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (20.5) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (4.6) (push) Failing after 5s
Tests: `nvm install-latest-npm` / nvm install-latest-npm (6.1) (push) Failing after 5s
Fixes #3784.
2026-11-20 14:53:54 -08:00
Jordan HarbandandCurt J. Sampson f6e169b130 [readme] Docker: improve the "Docker For Development Environment" section
- Add `--name` to `docker run` command to make the container easier to
  manipulate. (This will produce collisions if two developers both try
  this on the same system, but it's not worth a lot of extra
  documentation to try to sort out the few developers who can't figure
  out what's going on from the error messages)

 - Explain better that the current repo and working copy are copied to ~/.nvm/ inside the container

 - Explain that the container is not deleted when you exit, and how to re-enter and delete it

 - General improvements to the language.

Co-authored-by: Curt J. Sampson <cjs@cynic.net>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-11-20 14:31:22 -08:00
Jordan HarbandandThan Tibbetts 11f7827dfc [readme] update outdated Node.js version examples in nvm --help and the readme
Several "pick a recent version" examples cited EOL Node versions
(4.2, 4.8.3, 5.9, 6.10.3, 8.x, 12.22.1, 14.x, 16.x, 18.x, and Iron's 20).
Update them to current LTS lines (22.x/24.x),
including the full `.nvmrc` walkthrough output,
preserving the `--help` column alignment.

Intentionally-historical references are left unchanged:
the io.js migration examples,
the `stable`/`unstable` alias notes,
the Alpine version table,
the source-build narrative,
and the `--shared-zlib` example
(which explicitly demonstrates installing an older version)

Signed-off-by: Than Tibbetts <than@me.com>
Co-authored-by: Than Tibbetts <than@me.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-11-20 12:37:11 -08:00
Jordan HarbandandDivya Chukkapalli 62adf80079 [Fix] --lts=<name>: match codenames containing the name, not as a regex
`nvm_ls_remote_index_tab` compared the codename with awk's `!~`,
so the name was a regex: `--lts=.` matched every LTS line,
and `--lts=i.on` or `--lts=(` didn't mean what they say.
Use `index()` so a name still matches every codename that contains it,
but literally, and do the same in `nvm_filter_lts_versions`,
for `--lts=<name>` in an alias.

Locally, `--lts=<name>` resolved the `lts/<name>` alias,
which only exists for full codenames,
so `nvm use --lts=ir` failed where `nvm install --lts=ir` installed Iron.
Add `nvm_resolve_lts_name`,
which picks the newest codename in `$NVM_DIR/.lts-status` that contains the name,
and resolve `lts/<codename>` with it in `nvm use`, `uninstall`, `exec`, `run`,
and in `nvm install` for its offline lookup and the default and `--alias=` it writes.
Without a recorded status, or when no codename contains the name,
the name is used as given.

Signed-off-by: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com>
Co-authored-by: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-11-20 10:36:47 -08:00
Jordan Harbandanddajiaohuang dbda4b9387 [Fix] install.sh: update from nvm's remote; nvm_ls: list versions without globs; nvm_ensure_version_installed: do not leak VERSION
`install.sh`: an existing install now fetches from the remote whose URL is nvm's source,
adding one when none matches,
instead of always fetching `origin`;
fresh installs still name it `origin`.
The remote's URL is read with `git config`,
since `git remote get-url` needs git 2.7.

`nvm_ls`: `find` lists each version directory's non-hidden subdirectories itself,
so it works under `set -f`,
which disables the globs it was given;
the directories only need to exist.

`nvm_ensure_version_installed`:
the resolved alias was assigned to `VERSION` without declaring it local.

Co-authored-by: dajiaohuang <mikewushuwen@outlook.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-11-19 22:51:28 -08:00
Gregory Myers a4fadf1eae [readme] zsh load-nvmrc: skip during tab completion
When completing a path containing `../` for `cd`, `pushd`, or `chdir`,
zsh's `_cd` runs `$(cd ${PREFIX%/*} ...)`,
which fires the `chpwd` hook in a subshell,
so `load-nvmrc` ran on each such completion, slowly in large directories.

`compstate` is set only inside completion widgets.
Checking `ZSH_SUBSHELL` instead would also skip deliberate subshells, like `( cd proj && npm test )`,
and checking it along with `WIDGET` would skip any widget's subshell, not just completion's.

Fixes #3606
2026-11-05 11:04:35 +00:00
Jordan Harband ecf142d1f0 [Refactor] nvm_version: simplify the stable fast path's condition
An LTS filter already turns `stable` into `node`,
so it never reaches this check,
and the alias path needs no command substitutions.
2026-11-19 16:09:39 -08:00
Jordan Harband b0a377a524 [Perf] nvm_ls: check whether a version directory has entries without forking
Each check ran `ls` piped into `grep` in a subshell,
which cost more than the `find` it guards;
a glob finds the same entries in the shell.
2026-11-19 16:05:28 -08:00
Hridhin Varkey Joseph 887c2969b7 [Perf] nvm_version: list installed versions once for node/stable
Once the newest installed version is 1.0 or later, `stable` is that version, so list the installed versions once and take the newest, instead of `nvm_ls stable` listing them three times.

Only 0.x installs (where `stable` is the newest even minor), a user alias named `stable`, and `--lts` filters keep the existing path. A system node, which `nvm_ls` lists last, is skipped.

Part of #3416.
2026-11-19 15:39:47 -08:00
hqzingandJordan Harband e8144d4194 [New] Add support for OpenHarmony platform
also: `nvm_get_os`: set `NVM_DIR` in the OpenHarmony chroots, and skip them without a glibc x86-64 layout

`sudo` resets the environment, and `nvm.sh` returns early when it cannot detect `NVM_DIR`,
so in the chroots `nvm_get_os` was undefined and every check got an empty result.
The chroot setup needs `ldd` and `/lib64/ld-linux-x86-64.so.2`, which macOS does not have.

Co-authored-by: hqzing <hqzing@outlook.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-08-18 17:23:11 +08:00
Jordan Harband 0054ed6022 [Dockerfile] remove the apt mirror; it broke the build
The mirror now redirects to HTTPS,
and `ubuntu:22.04` has no CA certificates before its first `apt install`,
so on amd64 every source was ignored and installing packages failed:

    Ign:2 https://ubuntu.cs.utah.edu/ubuntu jammy-updates InRelease
    W: http://ubuntu.cs.utah.edu/ubuntu/dists/jammy-updates/InRelease: No system certificates available. Try installing ca-certificates.

Use Ubuntu's default sources, as arm64 builds already did
(`ports.ubuntu.com`, which the `sed` did not rewrite);
Docker caches the package layers anyway.
2026-11-18 22:54:36 -08:00
Aryan ChandavarkarandJordan Harband 60e2ec3b8e [Docs] security policy: link to the threat model and incident response plan with absolute URLs
The repo's security policy page resolves relative links from the repository root,
but viewing `.github/SECURITY.md` resolves them from `.github/`,
so no relative link works in both.

Co-authored-by: Aryan Chandavarkar <aryanmc2004@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-10-10 12:01:49 -04:00
Jordan Harband 944232943b [Fix] nvm_process_nvmrc_content: a key containing a space is not a duplicate of each word in it
The duplicate-key check kept keys in a space-separated list,
so a key such as `a b` followed by a key `a` or `b` was reported as a duplicate,
unlike in the `nvmrc` package.
Keep the keys newline-separated, since a key cannot contain a newline.
2026-11-18 16:20:53 -08:00
Divya Chukkapalli e8cfc3975d [Tests] nvm_process_nvmrc_content: compare .nvmrc keys literally
The duplicate-key check used to splice each key into an extended regex,
so distinct keys whose characters are regex syntax collided
(`node.dist` matched `node-dist`, `a+b` matched `ab`),
a key with `(` or `[` printed a grep error,
and a repeated `[x` key was not caught.
e4fcf988 now compares keys literally with a `case` pattern;
cover those cases.

Signed-off-by: Divya Chukkapalli <12871391+divya0795@users.noreply.github.com>
2026-11-18 11:59:49 -08:00
Jordan Harband ad42d90860 [Fix] nvm_ls_remote_index_tab, nvm_compare_checksum: also keep non-ASCII controls from the mirror off the terminal
Rejecting only ASCII control characters in the LTS codename still lets through a UTF-8 C1 control
(like U+009B, a CSI) or a bidi override (like U+202E),
which some terminals act on.
A row is now kept only if its codename is `-`, empty, or alias-safe,
which is the same shape the LTS alias step already requires,
and every real codename has.

BusyBox `tr` mishandles `-c` with a character class,
so on Alpine the expected checksum printed as almost all `?`;
an octal range in the C locale works in BusyBox, GNU, and BSD `tr`,
and does not make BSD `tr` abort on invalid UTF-8.
2026-11-16 15:13:13 -08:00
kasparovabi f3ad1d23b7 [Fix] nvm_ls_remote_index_tab, nvm_compare_checksum: keep control characters from the mirror off the terminal
`index.tab` and `SHASUMS256.txt` are untrusted mirror metadata.
An LTS codename (`$10`) carrying ESC/BEL bytes was printed by `nvm ls-remote`,
and a mismatched expected checksum was echoed as received.

Skip `index.tab` rows whose codename has a control character,
next to the existing version check,
and show non-printable bytes of the expected checksum as `?`.
2026-11-12 14:28:16 +03:00
Jordan Harband d66749b21c [Fix] install.sh: run the system npm outside the project
`nvm_check_global_modules` ran `npm --version` and `npm list -g` in `$PWD`,
so the project `.npmrc` applied, eg its `logs-dir` on npm v8.11 through v10.5.
The "npm unavailable" test put its fake npm on a relative `PATH` entry, which no longer resolves from `/`.
2026-11-16 15:31:02 -08:00
Jordan Harband e837e16067 [Fix] run npm outside the project for nvm use, install-latest-npm, and global package installs
These also ran npm in `$PWD`, applying the untrusted project `.npmrc`.
npm v7 through v8.2 apply it even with `-g`,
so its `registry` chose where `nvm install-latest-npm`, `--latest-npm`, `default-packages`, and `reinstall-packages` downloaded globally-installed packages from, and their install scripts then ran.
npm v8.11 through v10.5 honor its `logs-dir` and `cache` for `npm --version`,
so every non-silent `nvm use` created those directories and wrote a debug log there.

Use `nvm_npm`, or `nvm_cd_root` where `xargs` runs npm.
`npm link` still runs in each linked package's own directory.
2026-11-16 15:31:01 -08:00
Jordan Harband f07f4ed8f3 [Fix] nvm debug: do not let a project .npmrc configure npm
`nvm debug` ran `npm config get prefix` in `$PWD`, so npm applied the untrusted project `.npmrc`.
Its `logs-dir` chose where npm wrote its debug log,
and npm 11 copies unknown keys into that log verbatim,
so `logs-dir=~/.bashrc.d` plus a `$(...)` key runs a command in the next shell on Fedora-style setups.
Its `userconfig` makes npm 11 echo the lines of any file into the log and into the `nvm debug` output.

`-g` is not enough: npm v7 through v8.2 load the project `.npmrc` even in global mode.
Add `nvm_npm`, which runs npm from `/`, and use it for both npm commands.
`$NVM_CD_FLAGS` is not used, since a zsh parent exports `-q` to bash and sh children.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-ZF4UWQNS.
2026-11-16 15:21:25 -08:00
Jordan Harband 2abfc380ad [Fix] nvm_download: pass a mirror URL with credentials to curl and GNU Wget on stdin, not as an argument
903e3493 moved `$NVM_AUTH_HEADER` out of the downloader's arguments,
but a mirror URL with `user:password@` in it was still one,
so any local user could read the password in `ps` or /proc/<pid>/cmdline
for every index.tab, SHASUMS, and tarball request.
curl now gets such a URL as `url = "..."` in the config it already reads with `--config -`,
with `"` and `\` escaped;
GNU Wget reads it with `--input-file=-`,
including in the same-origin redirect loop.
A URL with whitespace or a control character cannot be one config line, and stays an argument.
BusyBox wget has no way to take a URL other than as an argument; the README says so.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-MNDN98RD.
2026-11-16 15:15:25 -08:00
Jordan Harband cb7b66c729 [Fix] nvm_download_artifact: give each download a path no other process knows
Every download went to the fixed `<archive>.unverified`,
and curl opens its `-o` file only on the first body byte,
so a curl left running by an earlier install of the same version
(past the install lock via `nvm cache clear`, a stale-lock takeover, or a removed lock)
survived the `rm -f`, then opened the same file
and could rewrite it after the checksum passed, while `tar` read it,
and leave it in the cache that `--offline` trusts.

Downloading into a `mktemp -d` directory in the same cache dir
keeps the rename atomic and the file's mode following the umask.
Leftover `.unverified*` paths from interrupted installs are still removed first.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-XUXR5LQ4.
2026-11-16 15:09:20 -08:00
Jordan Harband f39a6cbc2d [Fix] nvm_write_nvmrc: don't let a symlink swapped in after the check be written through
The symlink check and the `tee` were two steps,
so anyone who can write `$PWD` could rename a symlink over `.nvmrc` in between,
and `nvm use --save`/`nvm install --save` would truncate any file the user can write.

Write the version in a private `mktemp -d` dir instead, and rename it into `$PWD/`:
a rename replaces a symlink rather than following it,
and moving into the directory (not onto `.nvmrc`) avoids landing inside a symlinked directory.
An existing `.nvmrc` must be a writable regular file, since a rename would also replace a read-only one.
`.nvmrc` is now a new file whose mode comes from the umask.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-EXZRTATX.
2026-11-16 15:08:32 -08:00
Jordan Harband 391a1ccde9 [Fix] nvm_process_nvmrc: check that the file read is the regular file at the path
`nvm_process_nvmrc` tested `[ ! -L ]` and then opened the path again with `cat`,
so another local user who can write the directory
could rename a symlink over `.nvmrc` in between (timed by `cat`'s exec),
and the target's content was printed and passed to `find` and `sed` as a version,
where that user could read it from the process list (67268ebc's check, bypassed).

sh can't open without following symlinks,
so read the file once, from one open,
and when its content is not a version or an existing alias,
show it or pass it on only if one `lstat` (`find -prune -type f -links 1 -inum`)
finds a regular file at the path with the open file's inode and no other links.
Anything else is handled as a symlink.
A hard link to another user's file, where the OS allows one, is refused the same way.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-WJUJDPM2.
2026-11-16 15:12:18 -08:00
Jordan Harband f7280d116e [Fix] nvm_echo: in pdksh and mksh, use print, not /usr/bin/printf
pdksh (OpenBSD's `/bin/sh`) and mksh have no `printf` builtin,
so every `nvm_echo` ran `/usr/bin/printf` with its text as an argument,
which every local user can read (`ps`, `/proc/<pid>/cmdline`).
That text includes a symlinked `.nvmrc`'s content while it is parsed,
so these shells still exposed it after 3a6403f9.
2026-11-16 15:08:59 -08:00
Jordan Harband 5671e688d2 [readme] zsh and fish auto-switch hooks: let nvm parse .nvmrc
The zsh `load-nvmrc` and fish `load_nvm` examples passed `$(cat .nvmrc)` to `nvm version` and `nvm install`,
so a `.nvmrc` symlinked to any readable file put that file's content,
a whole one-line file with no `=` needed,
in the arguments of `find`, `sed`, and (for fish) `bass` and `bash`,
which every local user can read,
and tried to install it as a version.
Get the version from `nvm_process_nvmrc` instead, as the bash `cdnvm` example has since c314f1cb.

bass runs its arguments as bash code,
so the fish example also ran `.nvmrc` content like `v20$(touch x)`;
pass the path and version to bass in the environment instead.

Reported by Anthropic's OSS Scanner, alongside vulnerability ANT-2026-GG4I2LOU.
2026-11-16 11:35:44 -08:00
Jordan Harband e4fcf988c5 [Fix] nvm_process_nvmrc_content, nvm_is_valid_version: keep .nvmrc content out of commands' arguments
A symlinked `.nvmrc`'s content is never printed (67268ebc),
but it was still parsed with external commands that took part of it as arguments,
which every local user can read (`ps`, `/proc/<pid>/cmdline`):
the duplicate-key check passed each key (the text before a line's first `=`) to `grep -E`,
and `nvm_is_valid_version` passed prerelease-shaped text to `awk` before checking that its core is numeric.
So another local user who can place a `.nvmrc` symlink where the victim runs nvm
(or merely sources `nvm.sh`, with no default alias)
could read, for example, a WireGuard private key the victim's symlink target holds.

Compare keys with `case`, literally rather than as a regex,
and let the existing shell check validate a prerelease's core,
which makes `0.0.N-<prerelease>` valid.

Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-GG4I2LOU.
2026-11-16 11:34:02 -08:00
ryenusandJordan Harband ceef142f8a [New] ls-remote, install, version-remote: add --min=
add CLI option --min=<version>, fallback to env var "NVM_MIN" if set.

The latter two pick the newest match,
which is below the minimum only when every match is,
so they check the resolved version.
`ls-remote` prints its notice on stderr, so the list stays parseable.

Other minor changes:
 - fix: disable color in nvm_print_versions tests
 - trim leading space in mock output due to eslint errors
 - ensure prefixed versions like v18 also work
 - remove function ref duplication
 - avoid inline initialization for ksh compatibility
 - apply `--min=` before checking for an empty list; require a version

Co-authored-by: ryenus <ryenus@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
2026-10-29 20:23:46 +08:00
Jordan Harband 68986f7778 [Refactor] nvm_ls: check for a system version where it is listed
Each branch now only records which system binary applies,
and the check runs in the block that lists the system version,
so the patterns that list it are named in one place.
2026-11-17 10:22:51 -08:00
Wei-Lun Li a2c0ebaec1 [Perf] nvm_ls: only look for a system node when the pattern can list it
`nvm_ls` lists the system version only for an empty pattern, `v`, or
`system`, but it checked for a system node/io.js for every pattern.
Each check runs `nvm deactivate` in a subshell, and a found system node
also runs `node -v`. So every partial-version lookup, like resolving a
`default` alias of `24` on shell startup, did that work and discarded it.

Refs #3425, #3416.

Signed-off-by: Wei-Lun Li <b84330808@gmail.com>
2026-11-14 22:28:35 +09:00
Amar e759a03ee4 [Docs] Document Cygwin curl setup
Fixes #2515 by documenting the Cygwin curl package and checking which executable is selected.
2026-11-13 18:33:49 +05:30
Amar 6294413afa [Fix] Report remote version index download failures
Check the downloader exit status before parsing index.tab, and report the failed mirror without exposing its credentials. Discard incomplete responses instead of treating them as successful version lists.

Fixes #673.
2026-11-13 13:15:55 +05:30
Amar 682b43037d [Docs] Correct upstream branch in contribution instructions 2026-11-13 13:02:08 +05:30
Jordan Harband 6f5767a530 [Fix] nvm_extract_tarball: don't let tar rewrite member names
`--strip-components 1` (and OpenBSD's `-s` equivalent)
rewrites each name after the extracting tar has checked it,
so with tars that have no `openat2` jail
(upstream GNU tar, busybox tar without its traversal protection)
a member named `node-v…//home/user/.bashrc` was written to `/home/user/.bashrc`,
and a hard link to `node-v…//abs/path` linked that file into the install tree,
both silently and with a zero exit.

Extract the archive as-is into a sibling staging directory,
require exactly one top-level entry that is a real directory,
and rename it into place;
dotfiles in the archive are kept.

busybox tar does not contain hard link targets at all
(absolute, `..`, or through an earlier symlink member),
so refuse any extracted file with more than one link.
No node.js or io.js archive contains a hard link.
2026-11-16 10:43:29 -08:00
Jordan Harband 09e620c401 [Fix] nvm_download_artifact: without a checksum tool, fail before touching the cache or downloading
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 / doctoc (push) Successful in 6m1s
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 (nvm-exec, bash) (push) Failing after 29m59s
Tests: shellcheck / shellcheck_matrix (nvm.sh, ksh) (push) Failing after 4m27s
Tests: alpine / fast x64 (alpine 3, bash) (push) Failing after 32s
Tests: alpine / fast x64 (alpine 3, dash) (push) Failing after 32s
Tests: alpine / fast x64 (alpine 3, sh) (push) Failing after 15m44s
Tests: alpine / fast x64 (alpine 3.15, dash) (push) Failing after 15m34s
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.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.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: xenial / xenial (dash) (push) Failing after 16m6s
urchin tests / tests (bash, install_script) (push) Failing after 32s
Tests: fast / fast (zsh, gawk) (push) Successful in 6m1s
Tests: fast / fast (bash, mawk) (push) Failing after 3m17s
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_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 / all xenial tests (push) Skipped
urchin tests / tests (dash, sourcing) (push) Failing after 1m53s
urchin tests / tests (sh, sourcing) (push) Failing after 1m34s
urchin tests / tests (zsh, sourcing) (push) Failing after 34s
Tests: alpine / fast arm64 (alpine 3, bash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, bash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, sh) (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, zsh) (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, zsh) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, dash) (push) Canceled after 0s
Tests: fast / all fast tests (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` / WSL nvm install (, 10, Debian-12) (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-24.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, Ubuntu-18.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 (, 18, Ubuntu-20.04) (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, 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, 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, 16, Ubuntu-20.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, 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 (, 12, Alpine-3.17) (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 (, 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 (, 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, 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, 14, Alpine-3.23) (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` / tests, on windows (push) Canceled after 0s
Tests: nvm install with set -e / test (push) Skipped
Tests: linting / eclint (push) Failing after 5m22s
Tests: linting / dockerfile_lint (push) Successful in 7m38s
Tests: linting / check_exec (push) Failing after 14s
Tests: shellcheck / shellcheck_matrix (install.sh, bash) (push) Failing after 46m19s
Tests: shellcheck / shellcheck_matrix (nvm.sh, bash) (push) Failing after 6m7s
Tests: shellcheck / shellcheck_matrix (nvm.sh, sh) (push) Failing after 1m19s
Tests: shellcheck / shellcheck_matrix (nvm.sh, dash) (push) Failing after 12m8s
Tests: shellcheck / shellcheck (push) Skipped
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, 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 / 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.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: 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 (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 (sh) (push) Failing after 1m32s
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 (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 (zsh) (push) Failing after 31s
Tests: installation_node / installation_node (dash) (push) Failing after 1m33s
Tests: xenial / xenial (zsh) (push) Failing after 1m33s
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 (zsh, slow) (push) Failing after 32s
urchin tests / tests (zsh, installation_iojs) (push) Failing after 32s
urchin tests / all test suites, all shells (push) Skipped
Tests: alpine / fast arm64 (alpine 3, dash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, dash) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.15, zsh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3.19, sh) (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: fast / fast (macOS, sh) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, bash) (push) Canceled after 0s
Tests: fast / fast (WSL Ubuntu-24.04, zsh) (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 (--no-progress 10) (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-20.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-20.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-20.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-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 (script, 10, Debian-12) (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, 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, 18, Debian-13) (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.23) (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 (, 18, 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, 12, Alpine-3.17) (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, 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: linting / test_naming (push) Failing after 1m33s
Tests: installation_node / installation_node (bash, without curl) (push) Failing after 22m25s
update readme TOC / update readme TOC (push) Failing after 32s
Tests: alpine / fast arm64 (alpine 3, sh) (push) Canceled after 0s
Tests: alpine / fast arm64 (alpine 3, zsh) (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 (WSL Ubuntu-24.04, sh) (push) Canceled after 0s
Tests on Windows: `nvm install` / Cygwin nvm install (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 (, 14, Ubuntu-24.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 (, 21, Debian-13) (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, 16, Ubuntu-18.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, Ubuntu-20.04) (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 (, 21, 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, 16, Alpine-3.17) (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
39 changed files with 2269 additions and 166 deletions

No files matched your search

+2 -2
View File
@@ -28,8 +28,8 @@ We meet 78% of the “gold” criteria. The gaps are as follows:
## Threat Model
See [THREAT_MODEL.md](.github/THREAT_MODEL.md).
See [THREAT_MODEL.md](https://github.com/nvm-sh/nvm/blob/HEAD/.github/THREAT_MODEL.md).
## Incident Response Plan
Please see our [Incident Response Plan](.github/INCIDENT_RESPONSE_PLAN.md).
Please see our [Incident Response Plan](https://github.com/nvm-sh/nvm/blob/HEAD/.github/INCIDENT_RESPONSE_PLAN.md).
+2
View File
@@ -37,6 +37,8 @@ jobs:
matrix:
node-version: ${{ fromJson(needs.matrix.outputs.latest) }}
include:
- node-version: "24.14"
- node-version: "22.22.1"
- node-version: "21"
- node-version: "20.5"
- node-version: "20.4"
+1 -1
View File
@@ -67,7 +67,7 @@ Before sending the pull request, make sure your code is running on the latest av
```
git fetch upstream
git rebase upstream/main
git rebase upstream/master
```
Verify your changes
-8
View File
@@ -20,14 +20,6 @@ ENV DEBIAN_FRONTEND=noninteractive
# ShellCheck version
ENV SHELLCHECK_VERSION=0.7.0
# Pick a Ubuntu apt mirror site for better speed
# ref: https://launchpad.net/ubuntu/+archivemirrors
ENV UBUNTU_APT_SITE=ubuntu.cs.utah.edu
# Replace origin apt package site with the mirror site
RUN sed -E -i "s/([a-z]+.)?archive.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
RUN sed -i "s/security.ubuntu.com/$UBUNTU_APT_SITE/g" /etc/apt/sources.list
# Install apt packages
RUN apt update && \
apt upgrade -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" && \
+54 -44
View File
@@ -263,7 +263,7 @@ You can use a task:
ansible.builtin.shell: >
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.41.0/install.sh | bash
args:
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
creates: "{{ ansible_facts.env.HOME }}/.nvm/nvm.sh"
```
### Verify Installation
@@ -288,6 +288,8 @@ If you're running a system without prepackaged binary available, which means you
- [nodist](https://github.com/marcelklehr/nodist)
- [nvs](https://github.com/jasongin/nvs)
**Note:** When using Cygwin, install the `curl` package through [Cygwin's setup program](https://cygwin.com/install.html). Run `command -v curl` in your Cygwin terminal and ensure it points to Cygwin's `curl` (for example, `/usr/bin/curl`), rather than a Windows executable. A Windows version of `curl` may fail to write downloads to Cygwin paths (see [#2515](https://github.com/nvm-sh/nvm/issues/2515)).
**Note:** `nvm` does not support [Fish] either (see [#303](https://github.com/nvm-sh/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
@@ -384,13 +386,13 @@ nvm install node # "node" is an alias for the latest version
To install a specific version of node:
```sh
nvm install 14.7.0 # or 16.3.0, 12.22.1, etc
nvm install 22.11.0 # or 24.0.0, etc
```
To set an alias:
```sh
nvm alias my_alias v14.4.0
nvm alias my_alias v22.11.0
```
Make sure that your alias does not contain any spaces or slashes.
@@ -402,6 +404,13 @@ You can list available versions using `ls-remote`:
nvm ls-remote
```
To hide versions below a given version, use `--min=`, or set `NVM_MIN` to the same kind of version, for example in your shell profile; `--min=` overrides it. `nvm install` and `nvm version-remote` accept it too, and fail rather than select a version below it:
```sh
nvm ls-remote --min=20
nvm ls-remote --only=lts --min=v18.2
```
When no version or `--lts` filter is given, the list also marks the version the `node` alias would install, and every version that one of your own aliases would resolve to. Each kind of annotation always starts in the same column, so the output can be sliced with `cut -c` or similar tools:
```
@@ -426,16 +435,16 @@ nvm run node --version
Or, you can run any arbitrary command in a subshell with the desired version of node:
```sh
nvm exec 4.2 node --version
nvm exec 22.11 node --version
```
You can also get the path to the executable to where it was installed:
```sh
nvm which 12.22
nvm which 22.11
```
In place of a version pointer like "14.7" or "16.3" or "12.22.1", you can use the following special default aliases with `nvm install`, `nvm use`, `nvm run`, `nvm exec`, `nvm which`, etc:
In place of a version pointer like "22" or "24.0" or "22.11.0", you can use the following special default aliases with `nvm install`, `nvm use`, `nvm run`, `nvm exec`, `nvm which`, etc:
- `node`: this installs the latest version of [`node`](https://nodejs.org/en/)
- `iojs`: this installs the latest version of [`io.js`](https://iojs.org/en/)
@@ -535,12 +544,12 @@ This reinstalls all global packages from `22.20.0` into the currently-active ver
If you've previously downloaded a node version (or it's still in the cache), you can install it without any network access using the `--offline` flag:
```sh
nvm install --offline 14.7.0
nvm install --offline 22.11.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.
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`):
@@ -659,10 +668,10 @@ To set a default Node version to be used in any new shell, use the alias 'defaul
```sh
nvm alias default node # this refers to the latest installed version of node
nvm alias default 18 # this refers to the latest installed v18.x version of node
nvm alias default 18.12 # this refers to the latest installed v18.12.x version of node
nvm alias default 22 # this refers to the latest installed v22.x version of node
nvm alias default 22.11 # this refers to the latest installed v22.11.x version of node
nvm alias default --lts node # this refers to the latest installed LTS version of node
nvm alias default --lts=iron 20 # this refers to the latest installed v20.x version of node from the "iron" LTS line
nvm alias default --lts=jod 22 # this refers to the latest installed v22.x version of node from the "jod" LTS line
```
nvm records the LTS status of every version each time it downloads the list of available versions, so `--lts` aliases know which installed versions are LTS.
@@ -674,7 +683,7 @@ To use a mirror of the node binaries, set `$NVM_NODEJS_ORG_MIRROR`:
export NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist
nvm install node
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 4.2
NVM_NODEJS_ORG_MIRROR=https://nodejs.org/dist nvm install 22.11
```
To use a mirror of the io.js binaries, set `$NVM_IOJS_ORG_MIRROR`:
@@ -703,7 +712,7 @@ The header is only sent with requests for URLs under a mirror, never to any othe
nvm gives the header to `curl` and to GNU Wget in a config file (for GNU Wget, a private temporary file that also holds a copy of your `~/.wgetrc`), not as a command-line argument, which other users of the same machine could read. Other `wget`s, like BusyBox's, read no config file, so on a machine shared with other users, install `curl` before using `$NVM_AUTH_HEADER`.
`$NVM_AUTH_HEADER` is the recommended way to authenticate to a mirror. Credentials embedded in the mirror URL itself (`https://user:password@host/...`) also work, and nvm prints such URLs with the credentials masked as `***@`.
`$NVM_AUTH_HEADER` is the recommended way to authenticate to a mirror. Credentials embedded in the mirror URL itself (`https://user:password@host/...`) also work, and nvm prints such URLs with the credentials masked as `***@`. Like the header, such a URL is given to `curl` in a config and to GNU Wget on its standard input, not as a command-line argument; other `wget`s, like BusyBox's, only take a URL as an argument, so on a machine shared with other users, install `curl` before putting credentials in a mirror URL.
### Platforms without official binaries
@@ -735,10 +744,10 @@ Neither host is gapless, and both change over time; the `index.tab` at the root
You can create a `.nvmrc` file containing a node version number (or any other string that `nvm` understands; see `nvm --help` for details) in the project root directory (or any parent directory).
Afterwards, `nvm use`, `nvm install`, and `nvm which` will use the version specified in the `.nvmrc` file if no version is supplied on the command line; if no `.nvmrc` is found either, they exit with status `127`. (`nvm exec` and `nvm run` follow the same `.nvmrc` lookup, but currently fall back to the active node if neither resolves &mdash; treat that fallback as undefined behavior; pass an explicit version if you need predictable scripting.) If you want the currently active version, pass `current` explicitly (e.g. `nvm which current`) &mdash; `current` is not affected by `.nvmrc`.
For example, to make nvm default to the latest 5.9 release, the latest LTS version, or the latest node version for the current directory:
For example, to make nvm default to the latest 22.11 release, the latest LTS version, or the latest node version for the current directory:
```sh
$ echo "5.9" > .nvmrc
$ echo "22.11" > .nvmrc
$ echo "lts/*" > .nvmrc # to default to the latest LTS version
@@ -751,21 +760,21 @@ Then when you run nvm use:
```sh
$ nvm use
Found '/path/to/project/.nvmrc' with version <5.9>
Now using node v5.9.1 (npm v3.7.3)
Found '/path/to/project/.nvmrc' with version <22.11>
Now using node v22.11.0 (npm v10.9.0)
```
Running nvm install will also switch over to the correct version, but if the correct node version isn't already installed, it will install it for you.
```sh
$ nvm install
Found '/path/to/project/.nvmrc' with version <5.9>
Downloading and installing node v5.9.1...
Downloading https://nodejs.org/dist/v5.9.1/node-v5.9.1-linux-x64.tar.xz...
Found '/path/to/project/.nvmrc' with version <22.11>
Downloading and installing node v22.11.0...
Downloading https://nodejs.org/dist/v22.11.0/node-v22.11.0-linux-x64.tar.xz...
#################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v5.9.1 (npm v3.7.3)
Now using node v22.11.0 (npm v10.9.0)
```
`nvm use` et. al. will traverse directory structure upwards from the current directory looking for the `.nvmrc` file. In other words, running `nvm use` et. al. in any subdirectory of a directory with an `.nvmrc` will result in that `.nvmrc` being utilized.
@@ -853,12 +862,19 @@ Put this into your `$HOME/.zshrc` to call `nvm use` automatically whenever you e
autoload -U add-zsh-hook
load-nvmrc() {
# skip during tab completion, which can run `cd` in a subshell
(( $+compstate )) && return
local nvmrc_path
nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_version
# Let nvm parse `.nvmrc`, so that comments are ignored and the content of an invalid
# or symlinked `.nvmrc` is not passed along to other commands
nvmrc_version="$(nvm_process_nvmrc "${nvmrc_path}")" || return
local nvmrc_node_version
nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
nvmrc_node_version=$(nvm version "${nvmrc_version}")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
@@ -897,9 +913,15 @@ function load_nvm --on-variable="PWD"
set -l node_version (nvm version)
set -l nvmrc_path (nvm_find_nvmrc)
if test -n "$nvmrc_path"
set -l nvmrc_node_version (nvm version (cat $nvmrc_path))
# Let nvm parse `.nvmrc`, so that comments are ignored and the content of an invalid
# or symlinked `.nvmrc` is not passed along to other commands.
# bass runs its arguments as bash code, so pass the path and version in the environment.
set -lx NVMRC_PATH $nvmrc_path
set -lx NVMRC_VERSION (bass source ~/.nvm/nvm.sh --no-use ';' nvm_process_nvmrc '"$NVMRC_PATH"')
or return
set -l nvmrc_node_version (nvm version '"$NVMRC_VERSION"')
if test "$nvmrc_node_version" = "N/A"
nvm install (cat $nvmrc_path)
nvm install '"$NVMRC_VERSION"'
else if test "$nvmrc_node_version" != "$node_version"
nvm use $nvmrc_node_version
end
@@ -1094,29 +1116,17 @@ export NVM_DIR="$HOME/.nvm"
To make development and testing work easier we supply a Dockerfile for development usage. It's based on an Ubuntu base image prepared with essential and useful tools for `nvm` development. To build the docker image of the environment, do a Docker build at the root of `nvm` repository:
```sh
$ docker build -t nvm-dev .
docker build -t nvm-dev . # Create the nvm-dev image
docker images # Confirm nvm-dev appears in the list.
# Create a container named `nvm-dev` (with the same hostname)
# and enter an interactive session in it.
docker run --name nvm-dev -h nvm-dev -it nvm-dev
```
This will package your current nvm working copy with our pre-defined development environment into a Docker image named `nvm-dev`. After the build you should see it appear in the list of images:
This will place you in the container in the `~/.nvm/` directory as the `nvm` user. When you exit the container will not be deleted (so as to avoid losing any work in it); you can re-enter the container with `docker start -i nvm-dev` or delete it permanently with `docker container rm -f nvm-dev`. (For more information on using Docker, see the [website][docker-www] and [documentation][docker-docs].)
```sh
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
nvm-dev latest 9ca4c57a97d8 7 days ago 650 MB
```
To start and enter a container based on this image:
```sh
$ docker run -h nvm-dev -it nvm-dev
nvm@nvm-dev:~/.nvm$
```
It takes several minutes to build the image and the image size is about 650MB, so it's not suitable for production usage.
For more information and documentation about Docker, please refer to its [official website][docker-www] and [documentation][docker-docs]:
Note that the build takes several minutes and well over half a gigabyte of disk space, so it's not suitable for production usage.
## Problems
+27 -4
View File
@@ -172,11 +172,33 @@ install_nvm_from_git() {
fi
local fetch_error
local NVM_REMOTE_NAME
NVM_REMOTE_NAME='origin'
if [ -d "$INSTALL_DIR/.git" ]; then
# Updating repo
nvm_echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
command printf '\r=> '
fetch_error="Failed to update nvm with $NVM_VERSION, run 'git fetch' in $INSTALL_DIR yourself."
local NVM_REMOTE
local NVM_GIT_SOURCE
NVM_GIT_SOURCE="$(nvm_source git)"
NVM_REMOTE_NAME=''
for NVM_REMOTE in $(command git --git-dir="${INSTALL_DIR}/.git" remote); do
if [ "$(command git --git-dir="${INSTALL_DIR}/.git" config --get "remote.${NVM_REMOTE}.url")" = "${NVM_GIT_SOURCE}" ]; then
NVM_REMOTE_NAME="${NVM_REMOTE}"
break
fi
done
if [ -z "${NVM_REMOTE_NAME}" ]; then
NVM_REMOTE_NAME='nvm-origin'
local NVM_REMOTE_SUFFIX
NVM_REMOTE_SUFFIX=0
while command git --git-dir="${INSTALL_DIR}/.git" config --get "remote.${NVM_REMOTE_NAME}.url" >/dev/null; do
NVM_REMOTE_SUFFIX=$((NVM_REMOTE_SUFFIX + 1))
NVM_REMOTE_NAME="nvm-origin-${NVM_REMOTE_SUFFIX}"
done
command git --git-dir="${INSTALL_DIR}/.git" remote add "${NVM_REMOTE_NAME}" "${NVM_GIT_SOURCE}" || return 2
fi
else
fetch_error="Failed to fetch origin with $NVM_VERSION. Please report this!"
nvm_echo "=> Downloading nvm from git to '$INSTALL_DIR'"
@@ -205,10 +227,10 @@ install_nvm_from_git() {
fi
fi
# Try to fetch tag
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin tag "$NVM_VERSION" --depth=1 2>/dev/null; then
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch "${NVM_REMOTE_NAME}" tag "$NVM_VERSION" --depth=1 2>/dev/null; then
:
# Fetch given version
elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch origin "$NVM_VERSION" --depth=1; then
elif ! command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch "${NVM_REMOTE_NAME}" "$NVM_VERSION" --depth=1; then
nvm_echo >&2 "$fetch_error"
exit 1
fi
@@ -403,14 +425,15 @@ nvm_check_global_modules() {
*/*) nvm_is_wsl && [ -f "${NPM_COMMAND%/*}/npm.cmd" ] && return 0 ;;
esac
# run npm from `/`, so it does not apply the npmrc of the (untrusted) project that `$PWD` is in
local NPM_VERSION
NPM_VERSION="$(npm --version)"
NPM_VERSION="$(command cd / && npm --version)"
NPM_VERSION="${NPM_VERSION:--1}"
[ "${NPM_VERSION%%[!-0-9]*}" -gt 0 ] || return 0
local NPM_GLOBAL_MODULES
NPM_GLOBAL_MODULES="$(
npm list -g --depth=0 |
(command cd / && npm list -g --depth=0) |
command sed -e '/ npm@/d' -e '/ (empty)$/d'
)"
+560 -95
View File
File diff suppressed because it is too large. Load diff
@@ -47,6 +47,14 @@ nvm alias work --lts=jod 22 >/dev/null 2>&1 || die 'nvm alias work --lts=jod 22
nvm alias other --lts=iron 22 >/dev/null 2>&1
[ "_$(nvm version other)" = '_N/A' ] || die "no installed v22 is iron; got >$(nvm version other)<"
# an LTS name matches every codename containing it, but not as a regex
nvm alias some --lts=o node >/dev/null 2>&1 || die 'nvm alias some --lts=o node failed'
[ "_$(nvm version some)" = '_v24.11.0' ] || die "some should be the latest installed version whose codename contains o; got >$(nvm version some)<"
nvm alias some --lts=ir node >/dev/null 2>&1 || die 'nvm alias some --lts=ir node failed'
[ "_$(nvm version some)" = '_v20.19.0' ] || die "some should be the latest installed version whose codename contains ir; got >$(nvm version some)<"
nvm alias some --lts=. node >/dev/null 2>&1 || die 'nvm alias some --lts=. node failed'
[ "_$(nvm version some)" = '_N/A' ] || die "no codename contains a literal .; got >$(nvm version some)<"
OUTPUT="$(nvm unalias work)"
[ "_${OUTPUT}" = '_Deleted alias work - restore it with `nvm alias "work" --lts=jod "22"`' ] || die "the restore hint should keep --lts=jod as its own argument; got >${OUTPUT}<"
@@ -0,0 +1,66 @@
#!/bin/sh
ORIG_NVM_DIR="${NVM_DIR}"
TMP_DIR=''
cleanup () {
case "${TMP_DIR}" in
/*) rm -rf "${TMP_DIR}" ;;
esac
NVM_DIR="${ORIG_NVM_DIR}"
export NVM_DIR
}
die () { echo "$@" ; cleanup ; exit 1; }
: nvm.sh
\. ../../nvm.sh
\. ../common.sh
TMP_DIR="$(mktemp -d)"
NVM_DIR="${TMP_DIR}/nvm"
export NVM_DIR
mkdir -p "${NVM_DIR}/alias/lts" || die 'could not create alias dir'
# `nvm exec` runs `$NVM_DIR/nvm-exec`, which sources the `nvm.sh` beside it
ln -s "${PWD}/../../nvm.sh" "${PWD}/../../nvm-exec" "${NVM_DIR}/" || die 'could not link nvm.sh and nvm-exec'
for VERSION in v20.19.0 v22.11.0 v24.11.0; do
make_fake_node "${VERSION}" || die "fake node ${VERSION} could not be made"
done
row () {
printf '%s\t2024-01-01\tsrc\t-\t-\t-\t-\t-\t-\t%s\t-\n' "$1" "$2"
}
{ row v26.12.1 -; row v24.11.0 Krypton; row v24.0.0 -; row v22.11.0 Jod; row v20.19.0 Iron; } | nvm_record_lts_status || die 'could not record LTS status'
nvm_make_alias lts/iron v20.19.0 >/dev/null 2>&1 || die 'could not alias lts/iron'
nvm_make_alias lts/jod v22.11.0 >/dev/null 2>&1 || die 'could not alias lts/jod'
nvm_make_alias lts/krypton v24.11.0 >/dev/null 2>&1 || die 'could not alias lts/krypton'
nvm_make_alias 'lts/*' lts/krypton >/dev/null 2>&1 || die 'could not alias lts/*'
# "o" is in Iron, Jod and Krypton; Krypton is the newest
nvm use --delete-prefix --lts=o >/dev/null 2>&1 || die '`nvm use --lts=o` failed'
[ "_$(nvm current)" = '_v24.11.0' ] || die "\`nvm use --lts=o\` should use the newest codename containing it, krypton; got >$(nvm current)<"
nvm use --delete-prefix --lts=ir >/dev/null 2>&1 || die '`nvm use --lts=ir` failed'
[ "_$(nvm current)" = '_v20.19.0' ] || die "\`nvm use --lts=ir\` should use iron; got >$(nvm current)<"
nvm use --delete-prefix --lts=jod >/dev/null 2>&1 || die '`nvm use --lts=jod` failed'
[ "_$(nvm current)" = '_v22.11.0' ] || die "\`nvm use --lts=jod\` should use jod; got >$(nvm current)<"
# not a regex
try_err nvm use --delete-prefix --lts=.
[ "_${CAPTURED_EXIT_CODE}" != '_0' ] || die '`nvm use --lts=.` should fail'
OUTPUT="$(nvm exec --lts=ir node 2>/dev/null)" || die '`nvm exec --lts=ir node` failed'
[ "_$(nvm_echo "${OUTPUT}" | command tail -1)" = '_v20.19.0' ] || die "\`nvm exec --lts=ir node\` should run iron; got >${OUTPUT}<"
case "${OUTPUT}" in
'Running node LTS "iron" -> v20.19.0'*) ;;
*) die "\`nvm exec --lts=ir\` should name the codename it picked; got >${OUTPUT}<" ;;
esac
OUTPUT="$(nvm run --silent --lts=kr 2>/dev/null)" || die '`nvm run --lts=kr` failed'
[ "_$(nvm_echo "${OUTPUT}" | command tail -1)" = '_v24.11.0' ] || die "\`nvm run --lts=kr\` should run krypton; got >${OUTPUT}<"
nvm uninstall --lts=ir >/dev/null 2>&1 || die '`nvm uninstall --lts=ir` failed'
! nvm_is_version_installed v20.19.0 || die '`nvm uninstall --lts=ir` should uninstall iron'
nvm_is_version_installed v22.11.0 || die '`nvm uninstall --lts=ir` should keep jod'
cleanup
@@ -0,0 +1,39 @@
#!/bin/sh
TMP_DIR=''
cleanup () {
case "${TMP_DIR}" in
/*) rm -rf "${TMP_DIR}" ;;
esac
}
die () { echo "$@" ; cleanup ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
TMP_DIR="$(mktemp -d)"
mkdir -p "${TMP_DIR}/project" || die 'could not make the project dir'
echo '{}' > "${TMP_DIR}/project/package.json"
echo "logs-dir=${TMP_DIR}/logs" > "${TMP_DIR}/project/.npmrc"
NPM_CALLS="${TMP_DIR}/npm-calls"
npm() {
echo "$(pwd): $*" >> "${NPM_CALLS}"
echo "npm $*"
}
OUTPUT="$(cd "${TMP_DIR}/project" && nvm debug 2>&1)"
EXPECTED_CALLS="/: config get prefix
/: root -g"
CALLS="$(cat "${NPM_CALLS}")"
[ "_${CALLS}" = "_${EXPECTED_CALLS}" ] || die "nvm debug should run npm outside the project: expected >${EXPECTED_CALLS}<; got >${CALLS}<"
case "${OUTPUT}" in
*"npm config get prefix: npm config get prefix"*"npm root -g: npm root -g"*) ;;
*) die "nvm debug should print npm's prefix and global root; got >${OUTPUT}<" ;;
esac
cleanup
@@ -72,6 +72,32 @@ nvm install -s --lts --default "${version}" > /dev/null 2>&1 || die "\`nvm insta
OUTPUT="$(nvm_alias default)"
[ "${OUTPUT}" = "${version}" ] || die "expected the default alias to be ${version} for \`--lts ${version}\`, got >${OUTPUT}<"
# `--lts=<name>` aliases the newest codename containing the name
reset
printf 'v22.0.0 jod\n%s iron\nv18.0.0 hydrogen\n' "${version}" > "$(nvm_lts_status_path)"
nvm install -s --lts=ir --default > /dev/null 2>&1 || die '`nvm install -s --lts=ir --default` failed'
OUTPUT="$(nvm_alias default)"
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the default alias to be lts/iron after \`--lts=ir\`, got >${OUTPUT}<"
# again, now that the version is installed
nvm alias default v18.0.0 > /dev/null 2>&1
nvm install -s --lts=ir --default > /dev/null 2>&1 || die '`nvm install -s --lts=ir --default` failed for an installed version'
OUTPUT="$(nvm_alias default)"
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the default alias to be lts/iron for an installed version, got >${OUTPUT}<"
nvm install -s --lts=ir --alias=foo > /dev/null 2>&1 || die '`nvm install -s --lts=ir --alias=foo` failed for an installed version'
OUTPUT="$(nvm_alias foo)"
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the foo alias to be lts/iron for an installed version, got >${OUTPUT}<"
reset
nvm install -s --lts=ir --alias=foo > /dev/null 2>&1 || die '`nvm install -s --lts=ir --alias=foo` failed'
OUTPUT="$(nvm_alias foo)"
[ "${OUTPUT}" = 'lts/iron' ] || die "expected the foo alias to be lts/iron after \`--lts=ir\`, got >${OUTPUT}<"
# offline, `--lts=<name>` finds the installed version of that codename
nvm_echo "${version}" > "$(nvm_alias_path)/lts/iron"
OUTPUT="$(nvm_remote_version() { return 3; }; nvm install --offline --lts=ir 2>&1)" || die "\`nvm install --offline --lts=ir\` failed: >${OUTPUT}<"
rm -f "$(nvm_lts_status_path)"
reset
nvm install --save "${version}" > /dev/null 2>&1 || die "\`nvm install --save ${version}\` failed"
OUTPUT="$(cat .nvmrc 2> /dev/null)"
+183
View File
@@ -0,0 +1,183 @@
#!/bin/sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
rm -rf "${TEST_NVM_DIR-}"
unset -f nvm_download nvm_record_lts_status nvm_get_remote_aliases nvm_has_colors versions install_below_min
unset TEST_NVM_DIR OUTPUT EXIT_CODE NVM_MIN NVM_MIN_ARG NVM_MIN_COMMAND
}
: nvm.sh
\. ../../../nvm.sh
unset NVM_MIN NVM_ONLY
TEST_NVM_DIR="$(mktemp -d)" || die 'could not create a temporary NVM_DIR'
NVM_DIR="${TEST_NVM_DIR}"
nvm_has_colors() { return 1; }
nvm_record_lts_status() { :; }
nvm_get_remote_aliases() { :; }
nvm_download() {
case "$*" in
*"$(nvm_get_mirror node std)/index.tab"*)
printf 'version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\tlts\tsecurity\n'
printf '%s\t2026-01-01\tsrc\t-\t-\t-\t-\t-\t-\t%s\t-\n' \
v27.0.0-alpha.1.0.0 - \
v26.1.0 - \
v24.2.0 Krypton \
v22.12.0 Jod \
v20.18.1 Iron \
v20.0.0 - \
v18.20.5 Hydrogen \
v0.12.18 - \
v0.10.48 -
;;
*"$(nvm_get_mirror iojs std)/index.tab"*)
printf 'version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\n'
printf '%s\t2015-01-01\tsrc\t-\t-\t-\t-\t-\t-\n' v3.3.1 v2.5.0 v1.8.4
;;
*) return 42 ;;
esac
}
# prints only the version column, on one line
versions() {
nvm ls-remote --no-colors "$@" 2>/dev/null | command awk '{ printf "%s ", $1 }'
}
[ "$(versions)" = 'v0.10.48 v0.12.18 iojs-v1.8.4 iojs-v2.5.0 iojs-v3.3.1 v18.20.5 v20.0.0 v20.18.1 v22.12.0 v24.2.0 v26.1.0 ' ] \
|| die "without a minimum, expected every non-alpha version; got >$(versions)<"
[ "$(versions --min=20)" = 'v20.0.0 v20.18.1 v22.12.0 v24.2.0 v26.1.0 ' ] \
|| die "--min=20: got >$(versions --min=20)<"
[ "$(versions --min=v20.1)" = 'v20.18.1 v22.12.0 v24.2.0 v26.1.0 ' ] \
|| die "--min=v20.1: got >$(versions --min=v20.1)<"
[ "$(versions --min=20.18.1)" = 'v20.18.1 v22.12.0 v24.2.0 v26.1.0 ' ] \
|| die "--min=20.18.1: got >$(versions --min=20.18.1)<"
# io.js majors are compared like node majors
[ "$(versions --min=2)" = 'iojs-v2.5.0 iojs-v3.3.1 v18.20.5 v20.0.0 v20.18.1 v22.12.0 v24.2.0 v26.1.0 ' ] \
|| die "--min=2: got >$(versions --min=2)<"
# combined with --only and --lts
[ "$(versions --only=lts --min=20)" = 'v20.18.1 v22.12.0 v24.2.0 ' ] \
|| die "--only=lts --min=20: got >$(versions --only=lts --min=20)<"
[ "$(versions --min=20 --only=non-lts)" = 'v20.0.0 v26.1.0 ' ] \
|| die "--min=20 --only=non-lts: got >$(versions --min=20 --only=non-lts)<"
[ "$(versions --only=iojs --min=3)" = 'iojs-v3.3.1 ' ] \
|| die "--only=iojs --min=3: got >$(versions --only=iojs --min=3)<"
[ "$(versions --only=alpha,lts --min=24)" = 'v24.2.0 v27.0.0-alpha.1.0.0 ' ] \
|| die "--only=alpha,lts --min=24: got >$(versions --only=alpha,lts --min=24)<"
[ "$(versions --lts --min=22)" = 'v22.12.0 v24.2.0 ' ] \
|| die "--lts --min=22: got >$(versions --lts --min=22)<"
# a partial minimum includes the prereleases of its first release; a full one is above them
[ "$(versions --only=alpha --min=27)" = 'v27.0.0-alpha.1.0.0 ' ] \
|| die "--only=alpha --min=27: got >$(versions --only=alpha --min=27)<"
OUTPUT="$(nvm ls-remote --no-colors --only=alpha --min=27.0.0)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] && [ "$(nvm_echo "${OUTPUT}" | command tr -d ' ')" = 'N/A' ] \
|| die "--only=alpha --min=27.0.0 should print N/A and exit 3; got >${OUTPUT}<, exit ${EXIT_CODE}"
# nothing at or above the minimum, or nothing matching the pattern, is N/A
OUTPUT="$(nvm ls-remote --no-colors --min=99)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] && [ "$(nvm_echo "${OUTPUT}" | command tr -d ' ')" = 'N/A' ] \
|| die "--min=99 should print N/A and exit 3; got >${OUTPUT}<, exit ${EXIT_CODE}"
OUTPUT="$(nvm ls-remote --no-colors --only=lts --min=25)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] && [ "$(nvm_echo "${OUTPUT}" | command tr -d ' ')" = 'N/A' ] \
|| die "--only=lts --min=25 should print N/A and exit 3; got >${OUTPUT}<, exit ${EXIT_CODE}"
OUTPUT="$(nvm ls-remote --no-colors --min=18 99)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] && [ "$(nvm_echo "${OUTPUT}" | command tr -d ' ')" = 'N/A' ] \
|| die "a pattern with no match should print N/A and exit 3 with --min; got >${OUTPUT}<, exit ${EXIT_CODE}"
# NVM_MIN is the default, and --min= overrides it
NVM_MIN=22
[ "$(versions)" = 'v22.12.0 v24.2.0 v26.1.0 ' ] \
|| die "NVM_MIN=22: got >$(versions)<"
[ "$(versions --min=26)" = 'v26.1.0 ' ] \
|| die "NVM_MIN=22 --min=26: got >$(versions --min=26)<"
nvm ls-remote --no-colors >/dev/null 2>"${TEST_NVM_DIR}/stderr"
OUTPUT="$(cat "${TEST_NVM_DIR}/stderr")"
[ "_${OUTPUT}" = '_8 versions below 22 are hidden by `$NVM_MIN`.' ] \
|| die "NVM_MIN=22 notice: got >${OUTPUT}<"
OUTPUT="$(nvm version-remote 20)"
[ "_${OUTPUT}" = '_N/A' ] || die "NVM_MIN=22 version-remote 20: got >${OUTPUT}<"
[ "$(nvm version-remote --min=20 20)" = 'v20.18.1' ] \
|| die "NVM_MIN=22 version-remote --min=20 20: got >$(nvm version-remote --min=20 20)<"
# a notice on stderr says how many versions are hidden, and by what
nvm ls-remote --no-colors --min=20 >/dev/null 2>"${TEST_NVM_DIR}/stderr"
OUTPUT="$(cat "${TEST_NVM_DIR}/stderr")"
[ "_${OUTPUT}" = '_6 versions below 20 are hidden by `--min=20`.' ] \
|| die "--min=20 notice: got >${OUTPUT}<"
nvm ls-remote --no-colors --only=lts --min=20 >/dev/null 2>"${TEST_NVM_DIR}/stderr"
OUTPUT="$(cat "${TEST_NVM_DIR}/stderr")"
[ "_${OUTPUT}" = '_1 version below 20 is hidden by `--min=20`.' ] \
|| die "--only=lts --min=20 notice: got >${OUTPUT}<"
nvm ls-remote --no-colors --min=0 >/dev/null 2>"${TEST_NVM_DIR}/stderr"
OUTPUT="$(cat "${TEST_NVM_DIR}/stderr")"
[ -z "${OUTPUT}" ] || die "--min=0 hides nothing, so should print no notice; got >${OUTPUT}<"
# version-remote and install select only from versions at or above the minimum
[ "$(nvm version-remote --min=20 20)" = 'v20.18.1' ] \
|| die "version-remote --min=20 20: got >$(nvm version-remote --min=20 20)<"
OUTPUT="$(nvm version-remote --min=22 20)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] && [ "_${OUTPUT}" = '_N/A' ] \
|| die "version-remote --min=22 20 should print N/A and exit 3; got >${OUTPUT}<, exit ${EXIT_CODE}"
OUTPUT="$(nvm version-remote --lts=iron --min=22)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] && [ "_${OUTPUT}" = '_N/A' ] \
|| die "version-remote --lts=iron --min=22 should print N/A and exit 3; got >${OUTPUT}<, exit ${EXIT_CODE}"
install_below_min() {
OUTPUT="$(nvm install "$@" 2>&1)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 3 ] || die "install $* should exit 3; got ${EXIT_CODE}: >${OUTPUT}<"
case "${OUTPUT}" in
*'It matches v20.18.1, which is below the minimum version 22 from `--min=22`.'*) ;;
*) die "install $* should explain the minimum; got >${OUTPUT}<" ;;
esac
}
install_below_min --min=22 20
install_below_min 20 --min=22
# NVM_MIN only applies to commands that select remote versions
mkdir -p "${NVM_DIR}/versions/node/v18.20.5/bin" || die 'could not create an installed version'
OUTPUT="$(nvm ls --no-colors --no-alias | command awk '{ printf "%s ", $1 }')"
case "${OUTPUT}" in
*v18.20.5*) ;;
*) die "NVM_MIN should not hide installed versions from nvm ls; got >${OUTPUT}<" ;;
esac
[ "${NVM_MIN}" = 22 ] || die "nvm ls changed NVM_MIN to >${NVM_MIN}<"
# the minimum must be a version, given with `=`
for NVM_MIN_ARG in --min --min= --min=lts/iron --min=node --min=18.x --min=v18.1.0.0; do
OUTPUT="$(nvm ls-remote --no-colors "${NVM_MIN_ARG}" 2>&1)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 55 ] || die "ls-remote ${NVM_MIN_ARG} should exit 55; got ${EXIT_CODE}: >${OUTPUT}<"
OUTPUT="$(nvm version-remote "${NVM_MIN_ARG}" 20 2>&1)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 55 ] || die "version-remote ${NVM_MIN_ARG} should exit 55; got ${EXIT_CODE}: >${OUTPUT}<"
OUTPUT="$(nvm install "${NVM_MIN_ARG}" 20 2>&1)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 55 ] || die "install ${NVM_MIN_ARG} 20 should exit 55; got ${EXIT_CODE}: >${OUTPUT}<"
OUTPUT="$(nvm install 20 "${NVM_MIN_ARG}" 2>&1)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 55 ] || die "install 20 ${NVM_MIN_ARG} should exit 55; got ${EXIT_CODE}: >${OUTPUT}<"
done
unset NVM_MIN_ARG
NVM_MIN=node
for NVM_MIN_COMMAND in ls-remote version-remote install; do
OUTPUT="$(nvm "${NVM_MIN_COMMAND}" 2>&1)"
EXIT_CODE=$?
[ "${EXIT_CODE}" = 55 ] || die "NVM_MIN=node ${NVM_MIN_COMMAND} should exit 55; got ${EXIT_CODE}: >${OUTPUT}<"
done
unset NVM_MIN_COMMAND
cleanup
+64
View File
@@ -0,0 +1,64 @@
#!/bin/sh
TMP_DIR=''
cleanup () {
case "${TMP_DIR}" in
/*) rm -rf "${TMP_DIR}" ;;
esac
}
die () { echo "$@" ; cleanup ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
TMP_DIR="$(mktemp -d)"
mkdir -p "${TMP_DIR}/project" "${TMP_DIR}/bin" || die 'could not make the test dirs'
echo '{}' > "${TMP_DIR}/project/package.json"
echo 'registry=http://127.0.0.1:9/' > "${TMP_DIR}/project/.npmrc"
# a real executable, since `xargs` cannot run a shell function
NPM_CALLS="${TMP_DIR}/npm-calls"
cat > "${TMP_DIR}/bin/npm" <<FAKE
#!/bin/sh
echo "\$(pwd): \$*" >> '${NPM_CALLS}'
echo '6.0.0'
FAKE
chmod +x "${TMP_DIR}/bin/npm" || die 'could not make the fake npm'
PATH="${TMP_DIR}/bin:${PATH}"
check_calls () {
CALLS="$(cat "${NPM_CALLS}")"
[ "_${CALLS}" = "_$2" ] || die "$1 should run npm from \`/\`: expected >$2<; got >${CALLS}<"
rm -f "${NPM_CALLS}"
}
cd "${TMP_DIR}/project" || die 'could not cd to the project'
PROJECT_PWD="$(pwd)"
if nvm_is_zsh; then
# eg, a hook that runs `nvm use` on every directory change
eval 'chpwd() { echo "chpwd: $(pwd)" >> "${NPM_CALLS}"; }'
fi
nvm_npm config get registry >/dev/null
check_calls nvm_npm '/: config get registry'
[ "_$(pwd)" = "_${PROJECT_PWD}" ] || die "nvm_npm should not change the caller's directory; got >$(pwd)<"
OUTPUT="$(nvm_print_npm_version)"
[ "_${OUTPUT}" = '_ (npm v6.0.0)' ] || die "nvm_print_npm_version should print the npm version; got >${OUTPUT}<"
check_calls nvm_print_npm_version '/: --version'
nvm_get_default_packages() { echo 'a b'; }
nvm_install_default_packages >/dev/null
check_calls nvm_install_default_packages '/: install -g --quiet a b'
nvm_ls_current() { echo 'v8.0.0'; }
nvm_install_latest_npm >/dev/null
check_calls nvm_install_latest_npm '/: --version
/: install -g npm@6
/: --version'
cleanup
+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
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_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() {
echo "not checksum: ${1}"
@@ -0,0 +1,149 @@
#!/bin/sh
WORK="$PWD/nvm_download-url-credentials-work.$$"
TEST_BIN="$WORK/bin"
ARGV_LOG="$WORK/argv.log"
STDIN_LOG="$WORK/stdin.log"
OLDHOME="$HOME"
cleanup() {
unset -f die cleanup nvm_has_executable
unset NVM_AUTH_HEADER NVM_NODEJS_ORG_MIRROR WGET_IS_GNU FAKE_EXIT
rm -rf "$WORK"
export PATH="$OLDPATH"
HOME="$OLDHOME"
export HOME
}
die () { echo "$@" ; cleanup ; exit 1; }
\. ../../../nvm.sh
\. ../../common.sh
OLDPATH="$PATH"
# fake curl: record every argument, and the config it reads from stdin
make_fake_curl "$TEST_BIN" 'for a in "$@"; do printf "%s\n" "$a"; done > "$ARGV_LOG"
: > "$STDIN_LOG"
for a in "$@"; do if [ "$a" = --config ]; then cat > "$STDIN_LOG"; fi; done'
VERSION_MESSAGE="curl 7.99.0 (fake)"
# fake wget: GNU Wget when $WGET_IS_GNU is set, and like BusyBox's otherwise;
# record every argument, and the URLs it reads from stdin
{
echo '#!/bin/sh'
echo 'if [ "$1" = --version ]; then'
echo ' [ -n "${WGET_IS_GNU-}" ] || exit 1'
echo ' echo "GNU Wget 1.21.2 built on linux-gnu."; exit 0'
echo 'fi'
echo 'for a in "$@"; do printf "%s\n" "$a"; done > "$ARGV_LOG"'
echo ': > "$STDIN_LOG"'
echo 'for a in "$@"; do if [ "$a" = --input-file=- ]; then cat > "$STDIN_LOG"; fi; done'
echo 'exit "${FAKE_EXIT:-0}"'
} > "$TEST_BIN/wget"
chmod +x "$TEST_BIN/wget"
mkdir -p "$WORK/home"
HOME="$WORK/home"
export HOME ARGV_LOG STDIN_LOG
export PATH="$TEST_BIN:$OLDPATH"
NVM_NODEJS_ORG_MIRROR='https://ci-bot:s3cr3t@mirror.example/dist'
export NVM_NODEJS_ORG_MIRROR
URL="${NVM_NODEJS_ORG_MIRROR}/index.tab"
assert_not_an_argument() {
! grep -q 's3cr3t' "$ARGV_LOG" || die "${1}: the mirror password is an argument; got: $(cat "$ARGV_LOG")"
}
# given curl
nvm_download -L -s "$URL" -o - || die 'curl: nvm_download returned nonzero'
assert_not_an_argument 'curl'
EXPECTED='-q
--fail
-L
-s
-o
-
--config
-'
[ "$(cat "$ARGV_LOG")" = "$EXPECTED" ] || die "curl: expected args >$EXPECTED<, got >$(cat "$ARGV_LOG")<"
[ "$(cat "$STDIN_LOG")" = "url = \"${URL}\"" ] || die "curl: expected the URL in its config, got >$(cat "$STDIN_LOG")<"
# given a header as well, both go in the one config
NVM_AUTH_HEADER='Bearer test-token'
export NVM_AUTH_HEADER
nvm_download -L -s "$URL" -o - || die 'curl with header: nvm_download returned nonzero'
assert_not_an_argument 'curl with header'
[ "$(grep -c -Fxe '--config' "$ARGV_LOG")" = 1 ] || die "curl with header: expected one --config, got >$(cat "$ARGV_LOG")<"
EXPECTED="header = \"Authorization: Bearer test-token\"
url = \"${URL}\""
[ "$(cat "$STDIN_LOG")" = "$EXPECTED" ] || die "curl with header: expected config >$EXPECTED<, got >$(cat "$STDIN_LOG")<"
unset NVM_AUTH_HEADER
# given a quote or a backslash, they are escaped within curl's quoted string
nvm_download -L -s "${NVM_NODEJS_ORG_MIRROR}/a\"b\\c" -o - || die 'curl, quote: nvm_download returned nonzero'
assert_not_an_argument 'curl, quote'
[ "$(cat "$STDIN_LOG")" = "url = \"${NVM_NODEJS_ORG_MIRROR}/a\\\"b\\\\c\"" ] || die "curl, quote: got config >$(cat "$STDIN_LOG")<"
# given a line break, the URL cannot add a line to the config
nvm_download -L -s "$(printf '%s\noutput = "/tmp/nvm-pwned' "$URL")" -o - || die 'curl, line break: nvm_download returned nonzero'
! grep -Fxqe '--config' "$ARGV_LOG" || die "curl, line break: got config >$(cat "$STDIN_LOG")<"
# given a URL without credentials, it stays an argument
nvm_download -L -s 'https://nodejs.org/dist/index.tab' -o - || die 'curl, no credentials: nvm_download returned nonzero'
EXPECTED='-q
--fail
-L
-s
https://nodejs.org/dist/index.tab
-o
-'
[ "$(cat "$ARGV_LOG")" = "$EXPECTED" ] || die "curl, no credentials: expected args >$EXPECTED<, got >$(cat "$ARGV_LOG")<"
# given only GNU Wget
nvm_has_executable() { [ "$1" != curl ] && command -v "$1" >/dev/null 2>&1; }
WGET_IS_GNU=1
export WGET_IS_GNU
nvm_download -L -C - --progress-bar "$URL" -o "$WORK/out" || die 'GNU Wget: nvm_download returned nonzero'
assert_not_an_argument 'GNU Wget'
EXPECTED="-c
--progress=bar
-O
$WORK/out
--input-file=-"
[ "$(cat "$ARGV_LOG")" = "$EXPECTED" ] || die "GNU Wget: expected args >$EXPECTED<, got >$(cat "$ARGV_LOG")<"
[ "$(cat "$STDIN_LOG")" = "$URL" ] || die "GNU Wget: expected the URL on stdin, got >$(cat "$STDIN_LOG")<"
# and its exit code is kept
FAKE_EXIT=8
export FAKE_EXIT
nvm_download -L -s "$URL" -o -
EXIT_CODE=$?
unset FAKE_EXIT
[ "$EXIT_CODE" = 8 ] || die "GNU Wget: expected exit code 8, got $EXIT_CODE"
# given a header as well, which goes through the same-origin redirect check
NVM_AUTH_HEADER='Bearer test-token'
export NVM_AUTH_HEADER
nvm_download -L -s "$URL" -o - || die 'GNU Wget with header: nvm_download returned nonzero'
assert_not_an_argument 'GNU Wget with header'
EXPECTED='--max-redirect=0
-q
-O
-
--input-file=-'
[ "$(cat "$ARGV_LOG")" = "$EXPECTED" ] || die "GNU Wget with header: expected args >$EXPECTED<, got >$(cat "$ARGV_LOG")<"
[ "$(cat "$STDIN_LOG")" = "$URL" ] || die "GNU Wget with header: expected the URL on stdin, got >$(cat "$STDIN_LOG")<"
unset NVM_AUTH_HEADER
# given a wget that reads no URL from stdin, like BusyBox's, the URL stays an argument
unset WGET_IS_GNU
nvm_download -L -s "$URL" -o - || die 'other wget: nvm_download returned nonzero'
EXPECTED="-q
${URL}
-O
-"
[ "$(cat "$ARGV_LOG")" = "$EXPECTED" ] || die "other wget: expected args >$EXPECTED<, got >$(cat "$ARGV_LOG")<"
cleanup
@@ -4,7 +4,7 @@ WORK="${TMPDIR:-/tmp}/nvm_download_artifact_cache.$$"
cleanup () {
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; }
@@ -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}"
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
nvm_compare_checksum() { return 1; }
try nvm_download_artifact node binary std v20.0.0
@@ -69,11 +85,52 @@ try download_offline
nvm_compare_checksum() { return 0; }
command mkdir -p "${TEST_CACHE_DIR}"
nvm_echo 'partial' > "${TEST_TARBALL}.unverified"
command mkdir -p "${TEST_TARBALL}.unverified.abc123"
nvm_echo 'partial' > "${TEST_TARBALL}.unverified.abc123/${TEST_SLUG}.tar.gz"
try nvm_download_artifact node binary std v20.0.0
[ "${CAPTURED_EXIT_CODE}" = '0' ] || die "verified download: expected exit code 0, got ${CAPTURED_EXIT_CODE}"
[ "${CAPTURED_STDOUT}" = "${TEST_TARBALL}" ] || die "verified download: expected >${TEST_TARBALL}<, got >${CAPTURED_STDOUT}<"
[ "$(command cat "${TEST_TARBALL}")" = 'downloaded' ] || die "verified download: expected the cached archive to hold only the new download, got >$(command cat "${TEST_TARBALL}")<"
[ ! -e "${TEST_TARBALL}.unverified" ] || die 'verified download: expected no unverified download to remain in the cache'
[ "$(command ls "${TEST_CACHE_DIR}")" = "$(nvm_echo 'files'; nvm_echo "${TEST_SLUG}.tar.gz")" ] || die "verified download: expected no unverified download to remain in the cache, got >$(command ls "${TEST_CACHE_DIR}")<"
[ ! -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}")<"
[ "$(command ls "${TEST_CACHE_DIR}")" = "$(nvm_echo 'files'; nvm_echo "${TEST_SLUG}.tar.gz")" ] || die "no checksum tool: expected nothing to be downloaded, got >$(command ls "${TEST_CACHE_DIR}")<"
nvm_get_checksum_binary() { nvm_echo 'sha256sum'; }
# a downloader left running by an earlier install, which opens its output only once a later install is downloading
# (as curl does when the response body is late), must not be able to write to the archive that the later install verified
command rm -rf "${WORK}/.cache"
nvm_compare_checksum() { [ "$(command cat "$1")" = 'published' ]; }
nvm_download() {
while [ "$#" -gt 1 ] && [ "$1" != '-o' ]; do
shift
done
if [ ! -e "${WORK}/first-download" ]; then
nvm_echo "$2" > "${WORK}/first-download"
nvm_download_artifact node binary std v20.0.0 > "${WORK}/second-install" 2>/dev/null
nvm_echo "$?" >> "${WORK}/second-install"
if [ -e "${WORK}/late-open" ]; then
nvm_echo 'tampered' >&9
exec 9>&-
fi
command cat "${TEST_TARBALL}" > "${WORK}/cached-after-late-write"
else
# a failed `exec` redirection would end the shell; where the path is gone, curl would fail to open it
if [ -d "$(command dirname "$(command cat "${WORK}/first-download")")" ]; then
exec 9> "$(command cat "${WORK}/first-download")"
command touch "${WORK}/late-open"
fi
nvm_echo 'published' > "$2"
fi
}
try nvm_download_artifact node binary std v20.0.0
[ "$(command cat "${WORK}/second-install")" = "$(nvm_echo "${TEST_TARBALL}"; nvm_echo 0)" ] || die "late write: expected the second install to cache its download, got >$(command cat "${WORK}/second-install")<"
[ "$(command cat "${WORK}/cached-after-late-write")" = 'published' ] || die "late write: expected the verified archive in the cache to stay as it was, got >$(command cat "${WORK}/cached-after-late-write")<"
[ "${CAPTURED_EXIT_CODE}" = '6' ] || die "late write: expected the first install to reject its own download (exit code 6), got ${CAPTURED_EXIT_CODE}"
cleanup
@@ -70,4 +70,12 @@ EXPECTED_OUTPUT=''
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to give $EXPECTED_OUTPUT, got $OUTPUT"
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to exit with 0, got $EXIT_CODE"
# An unresolved installed-version check must not overwrite a caller's VERSION.
VERSION='caller-value'
nvm_resolve_alias() { [ "_${1-}" = '_nonexistent' ] || return 2; nvm_echo 'v123.4.5'; }
nvm_ensure_version_installed nonexistent >/dev/null 2>&1 && die 'expected missing version failure'
[ "${VERSION}" = 'caller-value' ] || die "VERSION leaked: ${VERSION}"
unset -f nvm_resolve_alias
unset VERSION
cleanup
@@ -0,0 +1,155 @@
#!/bin/sh
cleanup() {
if [ -n "${TEST_DIR-}" ] && [ -d "${TEST_DIR}" ]; then
rm -rf "${TEST_DIR}"
fi
}
die() { echo "$@" ; cleanup ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
TEST_DIR=''
TEST_DIR="$(mktemp -d)" && [ -n "${TEST_DIR}" ] && [ -d "${TEST_DIR}" ] || { TEST_DIR=''; die 'unable to create a temporary directory'; }
TEST_DIR="$(cd "${TEST_DIR}" && pwd -P)" && [ -n "${TEST_DIR}" ] || { TEST_DIR=''; die 'unable to resolve the temporary directory'; }
OUTSIDE="${TEST_DIR}/outside"
OUTSIDE_DIR="${TEST_DIR}/outside-dir"
[ "${#OUTSIDE}" -lt 90 ] || die "temporary path too long for a ustar name field: ${OUTSIDE}"
mkdir "${OUTSIDE_DIR}"
# args: value, width; writes the value NUL-padded to width
field() {
printf '%s' "$1"
dd if=/dev/zero bs=1 count="$(( $2 - ${#1} ))" 2>/dev/null
}
# `tar -c` strips a leading `/` and refuses some of these shapes,
# so write the member bytes directly.
# args: member name, typeflag, linkname, content; appends to ${TEST_DIR}/archive
member() {
{
field "$1" 100
field 0000755 8
field 0000000 8
field 0000000 8
field "$(printf '%011o' "${#4}")" 12
field 00000000000 12
printf ' '
printf '%s' "$2"
field "$3" 100
printf 'ustar'
printf '\000'
printf '00'
field '' 247
} > "${TEST_DIR}/header"
printf '%06o\000 ' "$(od -An -v -tu1 "${TEST_DIR}/header" | awk '{ for (i = 1; i <= NF; i++) s += $i } END { print s }')" \
| dd of="${TEST_DIR}/header" bs=1 seek=148 conv=notrunc 2>/dev/null
cat "${TEST_DIR}/header" >> "${TEST_DIR}/archive"
if [ -n "$4" ]; then
field "$4" 512 >> "${TEST_DIR}/archive"
fi
}
# args: output .tar.gz
finish() {
dd if=/dev/zero bs=512 count=2 2>/dev/null >> "${TEST_DIR}/archive"
gzip -n < "${TEST_DIR}/archive" > "$1"
rm -f "${TEST_DIR}/archive"
}
nlinks() { ls -ld "$1" | awk '{ print $2 }'; }
# args: name; extracts ${TEST_DIR}/name.tar.gz into ${TEST_DIR}/name, as callers do, stderr to ${TEST_DIR}/stderr
extract() {
mkdir -p "${TEST_DIR}/$1"
nvm_extract_tarball linux v0.10.0 "${TEST_DIR}/$1.tar.gz" "${TEST_DIR}/$1" 2>"${TEST_DIR}/stderr"
}
# args: name, expected stderr message
expect_refused() {
extract "$1" && die "$1: extraction succeeded"
case "$(cat "${TEST_DIR}/stderr")" in
*"$2"*) ;;
*) die "$1: unexpected output >$(cat "${TEST_DIR}/stderr")<" ;;
esac
[ ! -e "${TEST_DIR}/$1.extract" ] || die "$1: staging directory left behind"
}
printf 'ORIGINAL\n' > "${OUTSIDE}"
# a member that `--strip-components 1` would turn into an absolute path
member 'n/' 5 '' ''
member "n/${OUTSIDE}" 0 '' 'INJECTED'
finish "${TEST_DIR}/member.tar.gz"
extract member || die 'member: extraction failed'
[ "$(cat "${OUTSIDE}")" = 'ORIGINAL' ] || die 'member: wrote outside its target'
[ "$(cat "${TEST_DIR}/member${OUTSIDE}")" = 'INJECTED' ] || die 'member: not extracted inside its target'
[ ! -e "${TEST_DIR}/member.extract" ] || die 'member: staging directory left behind'
# a regular file written through a symlink to an outside directory
member 'n/' 5 '' ''
member 'n/l' 2 "${OUTSIDE_DIR}" ''
member 'n/l/written' 0 '' 'INJECTED'
finish "${TEST_DIR}/through-symlink.tar.gz"
extract through-symlink
[ ! -e "${OUTSIDE_DIR}/written" ] || die 'through-symlink: wrote outside its target'
# hard links whose target is, or becomes, outside the target directory
member 'n/' 5 '' ''
member 'n/linked' 1 "n/${OUTSIDE}" ''
finish "${TEST_DIR}/hardlink-stripped.tar.gz"
member 'n/' 5 '' ''
member 'n/linked' 1 "${OUTSIDE}" ''
finish "${TEST_DIR}/hardlink-absolute.tar.gz"
member 'n/' 5 '' ''
member 'n/linked' 1 'n/../../outside' ''
finish "${TEST_DIR}/hardlink-dotdot.tar.gz"
member 'n/' 5 '' ''
member 'n/l' 2 "${TEST_DIR}" ''
member 'n/linked' 1 'n/l/outside' ''
finish "${TEST_DIR}/hardlink-through-symlink.tar.gz"
for name in hardlink-stripped hardlink-absolute hardlink-dotdot hardlink-through-symlink; do
extract "${name}" && die "${name}: extraction succeeded"
[ "$(nlinks "${OUTSIDE}")" = 1 ] || die "${name}: linked a file outside its target"
[ ! -e "${TEST_DIR}/${name}.extract" ] || die "${name}: staging directory left behind"
done
# a hard link inside the archive
member 'n/' 5 '' ''
member 'n/a' 0 '' 'a'
member 'n/b' 1 'n/a' ''
finish "${TEST_DIR}/hardlink-internal.tar.gz"
expect_refused hardlink-internal 'hardlink-internal.tar.gz must not contain hard links'
# a legitimate archive: top-level directory renamed into place, dotfiles kept,
# even when the environment asks `ls` to decorate its output
mkdir -p "${TEST_DIR}/src/node-v0.10.0-linux-x64/bin" "${TEST_DIR}/legit/stale"
printf 'node\n' > "${TEST_DIR}/src/node-v0.10.0-linux-x64/bin/node"
printf 'hidden\n' > "${TEST_DIR}/src/node-v0.10.0-linux-x64/.hidden"
(cd "${TEST_DIR}/src" && tar -czf "${TEST_DIR}/legit.tar.gz" node-v0.10.0-linux-x64) || die 'unable to create legit archive'
CLICOLOR=1 CLICOLOR_FORCE=1 QUOTING_STYLE=shell-always LS_COLORS='di=01;34' extract legit || die "legit: extraction failed: $(cat "${TEST_DIR}/stderr")"
[ "$(cat "${TEST_DIR}/legit/bin/node")" = 'node' ] || die 'legit: bin/node missing'
[ "$(cat "${TEST_DIR}/legit/.hidden")" = 'hidden' ] || die 'legit: dotfile missing'
[ ! -e "${TEST_DIR}/legit/stale" ] || die 'legit: stale target contents kept'
[ ! -e "${TEST_DIR}/legit.extract" ] || die 'legit: staging directory left behind'
# more than one top-level entry
mkdir -p "${TEST_DIR}/src/other"
(cd "${TEST_DIR}/src" && tar -czf "${TEST_DIR}/two.tar.gz" node-v0.10.0-linux-x64 other) || die 'unable to create two-entry archive'
expect_refused two 'two.tar.gz must contain exactly one top-level directory'
# a top-level symlink to a directory
mkdir -p "${TEST_DIR}/link-src"
ln -s "${TEST_DIR}/src/node-v0.10.0-linux-x64" "${TEST_DIR}/link-src/node-v0.10.0-linux-x64"
(cd "${TEST_DIR}/link-src" && tar -czf "${TEST_DIR}/symlink.tar.gz" node-v0.10.0-linux-x64) || die 'unable to create symlink archive'
expect_refused symlink 'symlink.tar.gz must contain exactly one top-level directory'
cleanup
unset -f die cleanup field member finish nlinks extract expect_refused
unset TEST_DIR OUTSIDE OUTSIDE_DIR name
+103
View File
@@ -146,4 +146,107 @@ assert_uname_os 'FreeBSD host 14.0-STABLE' "${OS_RELEASE}" 'freebsd'
printf 'NAME=Helios\nID=helios\n' > "${OS_RELEASE}"
assert_uname_os 'SunOS host 5.11' "${OS_RELEASE}" 'sunos'
# a HarmonyOS kernel without the OpenHarmony userland is not an OS `nvm` knows
assert_uname_os 'HarmonyOS localhost HongMeng Kernel 1.12.0 #1 SMP Tue Jul 14 09:40:51 UTC 2026 aarch64 Toybox' "${MISSING_OS_RELEASE}" ''
# openharmony on aarch64 composes the slug a mirror has to serve; this runs on every host,
# and pins that `nvm_get_arch` gives `arm64`, not Alpine's `arm64-musl`
NVM_MOCK_UNAME=aarch64
export NVM_MOCK_UNAME
SLUG="$(nvm_get_os() { nvm_echo openharmony; }; PATH="${MOCK_BIN}:${PATH}" nvm_get_download_slug node binary v22.22.0)"
unset NVM_MOCK_UNAME
[ "${SLUG}" = 'node-v22.22.0-openharmony-arm64' ] || die "nvm_get_download_slug produced \"${SLUG}\", expected \"node-v22.22.0-openharmony-arm64\""
# OpenHarmony detection via chroot
MOCKS_DIR="$(pwd)/../../mocks"
setup_chroot() {
chroot_dir=$1
param_mock=$2
uname_mock=$3
# Directories
mkdir -p "${chroot_dir}/etc"
mkdir -p "${chroot_dir}/bin"
mkdir -p "${chroot_dir}/usr/bin"
mkdir -p "${chroot_dir}/lib64"
mkdir -p "${chroot_dir}/dev"
mkdir -p "${chroot_dir}/system/bin"
# Files and binaries
cp ../../../nvm.sh "${chroot_dir}/"
cp /bin/sh /usr/bin/dirname /usr/bin/grep "${chroot_dir}/usr/bin/"
cp "${uname_mock}" "${chroot_dir}/usr/bin/uname"
chmod +x "${chroot_dir}/usr/bin/uname"
ln -sf ../usr/bin/sh "${chroot_dir}/bin/sh"
# Fake OpenHarmony param binary
cp "${param_mock}" "${chroot_dir}/system/bin/param"
chmod +x "${chroot_dir}/system/bin/param"
# Libraries
for binary in /bin/sh /usr/bin/dirname /usr/bin/uname /usr/bin/grep; do
for lib in $(ldd $binary | awk '{print $3}' | grep "^/"); do
dir=$(dirname "${lib}")
mkdir -p "${chroot_dir}${dir}"
cp "${lib}" "${chroot_dir}${dir}/"
done
done
# Dynamic linker
cp /lib64/ld-linux-x86-64.so.2 "${chroot_dir}/lib64/"
# /dev/null
sudo mknod "${chroot_dir}/dev/null" c 1 3
}
# The chroot fixtures assume a glibc x86-64 layout (`ldd`, a fixed dynamic-linker path
# under /lib64), which macOS and musl Alpine do not have; skip the chroot checks there.
if [ -f "/etc/alpine-release" ] || ! nvm_has ldd || [ ! -e /lib64/ld-linux-x86-64.so.2 ]; then
echo "no glibc x86-64 layout; skipping chroot OpenHarmony checks"
else
CHROOT_UNAME_LINUX_PARAM_OPENHARMONY="${TEST_DIR}/uname_linux_param_openharmony"
CHROOT_UNAME_LINUX_PARAM_OTHER="${TEST_DIR}/uname_linux_param_other"
CHROOT_UNAME_HARMONYOS_PARAM_OPENHARMONY="${TEST_DIR}/uname_harmonyos_param_openharmony"
CHROOT_UNAME_HARMONYOS_PARAM_OTHER="${TEST_DIR}/uname_harmonyos_param_other"
CHROOT_UNAME_OSX_PARAM_OPENHARMONY="${TEST_DIR}/uname_osx_param_openharmony"
setup_chroot "${CHROOT_UNAME_LINUX_PARAM_OPENHARMONY}" "${MOCKS_DIR}/param_openharmony" "${MOCKS_DIR}/uname_linux_aarch64"
setup_chroot "${CHROOT_UNAME_LINUX_PARAM_OTHER}" "${MOCKS_DIR}/param_other" "${MOCKS_DIR}/uname_linux_aarch64"
setup_chroot "${CHROOT_UNAME_HARMONYOS_PARAM_OPENHARMONY}" "${MOCKS_DIR}/param_openharmony" "${MOCKS_DIR}/uname_harmonyos_aarch64"
setup_chroot "${CHROOT_UNAME_HARMONYOS_PARAM_OTHER}" "${MOCKS_DIR}/param_other" "${MOCKS_DIR}/uname_harmonyos_aarch64"
setup_chroot "${CHROOT_UNAME_OSX_PARAM_OPENHARMONY}" "${MOCKS_DIR}/param_openharmony" "${MOCKS_DIR}/uname_osx_amd64"
# Linux kernel with an OpenHarmony param -> openharmony
OS_UNAME_LINUX_PARAM_OPENHARMONY=$(sudo chroot "${CHROOT_UNAME_LINUX_PARAM_OPENHARMONY}" /bin/sh -c "NVM_DIR=/; export NVM_DIR; . ./nvm.sh && nvm_get_os")
if [ "${OS_UNAME_LINUX_PARAM_OPENHARMONY}" != "openharmony" ]; then
die "nvm_get_os produced \"${OS_UNAME_LINUX_PARAM_OPENHARMONY}\", expected \"openharmony\""
fi
# Linux kernel with an unrelated param stays linux
OS_UNAME_LINUX_PARAM_OTHER=$(sudo chroot "${CHROOT_UNAME_LINUX_PARAM_OTHER}" /bin/sh -c "NVM_DIR=/; export NVM_DIR; . ./nvm.sh && nvm_get_os")
if [ "${OS_UNAME_LINUX_PARAM_OTHER}" != "linux" ]; then
die "nvm_get_os produced \"${OS_UNAME_LINUX_PARAM_OTHER}\", expected \"linux\""
fi
# HarmonyOS kernel with an OpenHarmony param -> openharmony
OS_UNAME_HARMONYOS_PARAM_OPENHARMONY=$(sudo chroot "${CHROOT_UNAME_HARMONYOS_PARAM_OPENHARMONY}" /bin/sh -c "NVM_DIR=/; export NVM_DIR; . ./nvm.sh && nvm_get_os")
if [ "${OS_UNAME_HARMONYOS_PARAM_OPENHARMONY}" != "openharmony" ]; then
die "nvm_get_os produced \"${OS_UNAME_HARMONYOS_PARAM_OPENHARMONY}\", expected \"openharmony\""
fi
# HarmonyOS kernel with an unrelated param stays empty
OS_UNAME_HARMONYOS_PARAM_OTHER=$(sudo chroot "${CHROOT_UNAME_HARMONYOS_PARAM_OTHER}" /bin/sh -c "NVM_DIR=/; export NVM_DIR; . ./nvm.sh && nvm_get_os")
if [ "_${OS_UNAME_HARMONYOS_PARAM_OTHER}" != "_" ]; then
die "nvm_get_os produced \"${OS_UNAME_HARMONYOS_PARAM_OTHER}\", expected \"\""
fi
# an OS that `uname` already identified is never re-probed
OS_UNAME_OSX_PARAM_OPENHARMONY=$(sudo chroot "${CHROOT_UNAME_OSX_PARAM_OPENHARMONY}" /bin/sh -c "NVM_DIR=/; export NVM_DIR; . ./nvm.sh && nvm_get_os")
if [ "${OS_UNAME_OSX_PARAM_OPENHARMONY}" != "darwin" ]; then
die "nvm_get_os produced \"${OS_UNAME_OSX_PARAM_OPENHARMONY}\", expected \"darwin\""
fi
fi
cleanup
@@ -54,3 +54,30 @@ try_err nvm_install_latest_npm
EXPECTED="Unable to obtain npm version."
[ "${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
+11 -3
View File
@@ -42,9 +42,8 @@ nvm_is_valid_version v9.0.0-v8-canary201710301f8f3dcf36 || die "nvm_is_valid_ver
nvm_is_valid_version v8.16.2-test201910293843c56739f || die "nvm_is_valid_version v8.16.2-test201910293843c56739f did not return 0"
nvm_is_valid_version iojs-v3.2.1-nightly201508291a531b4e44 || die "nvm_is_valid_version iojs-v3.2.1-nightly201508291a531b4e44 did not return 0"
# `nvm_is_valid_version` must not fork a command for a plain version: mock
# `awk`, which the version comparisons used, and fail if it runs. (Prereleases
# still reach the comparison, which is why this checks a release version.)
# `nvm_is_valid_version` must not fork a command, since it checks what a symlinked `.nvmrc` points at:
# mock `awk`, which the version comparisons used, and fail if it runs.
TEST_DIR="$(pwd)/nvm_is_valid_version_tmp"
[ ! -e "${TEST_DIR}" ] && mkdir "${TEST_DIR}"
MOCK_BIN="${TEST_DIR}/bin"
@@ -58,5 +57,14 @@ chmod +x "${MOCK_BIN}/awk"
PATH="${MOCK_BIN}:${PATH}" nvm_is_valid_version v18.20.0 \
|| die 'nvm_is_valid_version v18.20.0 forked a command'
PATH="${MOCK_BIN}:${PATH}" nvm_is_valid_version v9.4.0-rc.1 \
|| die 'nvm_is_valid_version v9.4.0-rc.1 forked a command'
for VERSION in a.b.c-rc.1 1.2.3.4-rc.1 1..2-rc.1; do
OUTPUT="$(PATH="${MOCK_BIN}:${PATH}" nvm_is_valid_version "${VERSION}" 2>&1)" \
&& die "nvm_is_valid_version ${VERSION} did not return 1"
case "${OUTPUT}" in
*'awk was called'*) die "nvm_is_valid_version ${VERSION} forked a command" ;;
esac
done
rm -rf "${TEST_DIR}"
@@ -0,0 +1,25 @@
#!/bin/sh
die() { echo "$*" >&2; cleanup; exit 1; }
cleanup() { rm -rf "${TEST_DIR}"; }
\. ../../../nvm.sh --no-use
\. ../../common.sh
TEST_DIR="${PWD}/nvm_ls_hidden_noglob_tmp"
NVM_DIR="${TEST_DIR}"
export NVM_DIR
mkdir -p "${NVM_DIR}/versions/node/.hidden" "${NVM_DIR}/versions/node/v24.13.0/bin" || die 'could not create fixture'
make_echo "${NVM_DIR}/versions/node/v24.13.0/bin/node" 'v24.13.0' || die 'could not create fake node'
set -f
try nvm_ls 24
[ "_${CAPTURED_STDOUT}" = '_v24.13.0' ] || die "unexpected output with noglob: ${CAPTURED_STDOUT}"
case "$-" in *f*) ;; *) die 'nvm_ls changed noglob';; esac
set +f
try nvm_ls
case "${CAPTURED_STDOUT}" in *.hidden*) die "expected hidden entries to be skipped; got ${CAPTURED_STDOUT}" ;; esac
rm -rf "${NVM_DIR}/versions/node/v24.13.0"
try nvm_ls 24
[ "_${CAPTURED_STDERR}" = '_' ] || die "unexpected error for hidden-only directory: ${CAPTURED_STDERR}"
cleanup
@@ -0,0 +1,54 @@
#!/bin/sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
rm -rf "${TEST_DIR-}"
unset -f nvm_has_system_node nvm_has_system_iojs node
unset TEST_DIR NVM_DIR SYSTEM_CHECKS OUTPUT
}
: nvm.sh
\. ../../../nvm.sh
\. ../../common.sh
# an isolated NVM_DIR with known versions
TEST_DIR="${PWD}/nvm_ls_system_check_tmp"
for VERSION in v20.0.0 v24.13.0; do
mkdir -p "${TEST_DIR}/versions/node/${VERSION}/bin" || die "failed to create ${VERSION} dir"
make_echo "${TEST_DIR}/versions/node/${VERSION}/bin/node" "${VERSION}" || die "failed to create ${VERSION} node binary"
done
unset VERSION
NVM_DIR="${TEST_DIR}"
# each check runs `nvm deactivate` in a subshell, so count them
SYSTEM_CHECKS=0
nvm_has_system_node() { SYSTEM_CHECKS=$((SYSTEM_CHECKS + 1)); return 0; }
nvm_has_system_iojs() { SYSTEM_CHECKS=$((SYSTEM_CHECKS + 1)); return 1; }
node() { echo 'v18.0.0'; }
# a partial version never lists the system version, so it should not check for one
nvm_ls 24 > "${TEST_DIR}/output" || die '`nvm_ls 24` failed'
OUTPUT="$(cat "${TEST_DIR}/output")"
[ "_${OUTPUT}" = '_v24.13.0' ] || die "\`nvm_ls 24\` should output >v24.13.0<; got >${OUTPUT}<"
[ "${SYSTEM_CHECKS}" = 0 ] || die "\`nvm_ls 24\` should not check for a system version; checked ${SYSTEM_CHECKS} times"
nvm_ls iojs-v3 > "${TEST_DIR}/output"
[ "${SYSTEM_CHECKS}" = 0 ] || die "\`nvm_ls iojs-v3\` should not check for a system version; checked ${SYSTEM_CHECKS} times"
# these patterns still list it
nvm_ls > "${TEST_DIR}/output" || die '`nvm_ls` failed'
OUTPUT="$(cat "${TEST_DIR}/output")"
[ "_${OUTPUT}" = "_v20.0.0
v24.13.0
system v18.0.0" ] || die "\`nvm_ls\` should list the system version; got >${OUTPUT}<"
[ "${SYSTEM_CHECKS}" != 0 ] || die '`nvm_ls` should check for a system version'
SYSTEM_CHECKS=0
nvm_ls system > "${TEST_DIR}/output" || die '`nvm_ls system` failed'
OUTPUT="$(cat "${TEST_DIR}/output")"
[ "_${OUTPUT}" = '_system v18.0.0' ] || die "\`nvm_ls system\` should output >system v18.0.0<; got >${OUTPUT}<"
[ "${SYSTEM_CHECKS}" != 0 ] || die '`nvm_ls system` should check for a system version'
cleanup
@@ -0,0 +1,57 @@
#!/bin/sh
WORK="$PWD/ls_remote-cntrl-work.$$"
export HOME="$WORK/home"
export NVM_DIR="$HOME/.nvm"
cleanup() {
unset -f die cleanup nvm_download
rm -rf "$WORK"
}
die () { echo "$@" ; cleanup ; exit 1; }
mkdir -p "$NVM_DIR/alias"
: nvm.sh
\. ../../../nvm.sh
ESC="$(printf '\033')"
BEL="$(printf '\007')"
# a malicious/compromised mirror: the LTS codename field ($10) carries terminal
# escape sequences (an OSC window-title write and an SGR color change);
# a valid codename (Iron) is included to prove real rows are still listed;
# so are a UTF-8 C1 CSI and a right-to-left override, which are not ASCII control characters
nvm_download() {
printf 'version\tdate\tfiles\tnpm\tv8\tuv\tzlib\topenssl\tmodules\tlts\tsecurity\n'
printf 'v23.0.0\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\t-\t-\n'
printf 'v22.0.0\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\tJod\033]0;PWNED\007\033[31m\t-\n'
printf 'v21.0.0\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\tJod\302\23331m\t-\n'
printf 'v20.1.0\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\tIron\342\200\256\t-\n'
printf 'v20.0.0\t2026-01-01\tlinux-x64\t-\t-\t-\t-\t-\t-\tIron\t-\n'
}
OUTPUT="$(nvm_ls_remote 2>&1)" || true
case "${OUTPUT}" in
*"${ESC}"* | *"${BEL}"*) die "nvm_ls_remote printed control characters from the mirror's LTS codename: $(printf '%s' "${OUTPUT}" | od -c | head -5)" ;;
esac
case "${OUTPUT}" in
*'v21.0.0'* | *'v20.1.0'*) die "nvm_ls_remote listed a row with a malformed LTS codename: ${OUTPUT}" ;;
*'v20.0.0'*'Iron'*'v23.0.0'*) ;;
*) die "nvm_ls_remote did not list the valid rows: ${OUTPUT}" ;;
esac
if [ -f "$NVM_DIR/.lts-status" ] && nvm_grep -q "${ESC}" "$NVM_DIR/.lts-status"; then
die 'control characters from the mirror were recorded in .lts-status'
fi
# a checksum from the mirror is printed when it does not match; its control characters must not be
printf 'tarball' > "$WORK/tarball"
OUTPUT="$(nvm_compare_checksum "$WORK/tarball" "${ESC}]0;PWNED${BEL}${ESC}[31m" 2>&1)" && die 'nvm_compare_checksum accepted a mismatched checksum'
case "${OUTPUT}" in
*"${ESC}"* | *"${BEL}"*) die "nvm_compare_checksum printed control characters from the mirror's checksum: $(printf '%s' "${OUTPUT}" | od -c | head -5)" ;;
*"Checksums do not match"*"?]0;PWNED??[31m' expected."*) ;;
*) die "unexpected nvm_compare_checksum output: ${OUTPUT}" ;;
esac
cleanup
echo "nvm_ls_remote LTS codename control characters: passed"
@@ -0,0 +1,35 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
# these mocks must not be recorded as the LTS status of $NVM_DIR's versions
nvm_record_lts_status() { :; }
nvm_download() {
cat "$PWD/mocks/nodejs.org-dist-index.tab"
}
\. ../../common.sh
# no codename contains these characters literally, though most match them as a regex
for NVM_LTS in . 'i.on' 'ar.*' '(' '^i' 'n$'; do
try nvm_ls_remote
[ "_$CAPTURED_STDOUT" = "_N/A" ] || die "\`NVM_LTS='${NVM_LTS}' nvm_ls_remote\` should output N/A; got >$CAPTURED_STDOUT<"
[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "\`NVM_LTS='${NVM_LTS}' nvm_ls_remote\` should exit 3; got $CAPTURED_EXIT_CODE"
done
unset NVM_LTS
# a name matches every codename that contains it
OUTPUT="$(NVM_LTS=on nvm_ls_remote)"
CODENAMES="$(nvm_echo "$OUTPUT" | command awk '{ print $2 }' | command sort -u | command tr '\n' ' ')"
[ "_$CODENAMES" = "_Argon Boron Carbon Iron " ] || die "\`NVM_LTS=on nvm_ls_remote\` should list the Argon, Boron, Carbon and Iron lines; got >$CODENAMES<"
for NVM_LTS in iron ir; do
OUTPUT="$(nvm_ls_remote)"
[ -n "$OUTPUT" ] || die "\`NVM_LTS=${NVM_LTS} nvm_ls_remote\` output nothing"
OTHER_LINES="$(nvm_echo "$OUTPUT" | command awk '$2 != "Iron"')"
[ -z "$OTHER_LINES" ] || die "\`NVM_LTS=${NVM_LTS} nvm_ls_remote\` listed versions outside the Iron line: >$OTHER_LINES<"
done
@@ -0,0 +1,60 @@
#!/bin/sh
# Mocks are called indirectly by the sourced nvm functions.
# shellcheck disable=SC2329
die () { echo "$@"; exit 1; }
: nvm.sh
\. ../../../nvm.sh --no-use
\. ../../common.sh
nvm_record_lts_status() { :; }
export NVM_NODEJS_ORG_MIRROR='https://nodejs.org/dist'
export NVM_IOJS_ORG_MIRROR='https://iojs.org/dist'
# A failed request may have already written part of index.tab to stdout.
# Neither an empty response nor a partial one should look like a successful list.
for FLAVOR in node iojs; do
for PARTIAL in no yes; do
nvm_download() {
if [ "${PARTIAL}" = yes ]; then
cat "${PWD}/mocks/nodejs.org-dist-index.tab"
fi
return 60
}
try nvm_ls_remote_index_tab "${FLAVOR}" std ''
[ "${CAPTURED_EXIT_CODE}" = 3 ] || die "${FLAVOR}: failed download should return 3"
[ "${CAPTURED_STDOUT}" = 'N/A' ] || die "${FLAVOR}: failed download must not print partial versions"
MIRROR="$(nvm_get_mirror "${FLAVOR}" std)"
try_err nvm_ls_remote_index_tab "${FLAVOR}" std ''
[ "${CAPTURED_STDERR}" = "Failed to download version list from ${MIRROR}/index.tab" ] \
|| die "${FLAVOR}: missing download error: ${CAPTURED_STDERR}"
done
done
# A working mirror should still provide its versions when the other one fails,
# but the failure must remain visible on stderr.
nvm_download() {
case "$*" in
*https://nodejs.org/dist/index.tab*) return 60 ;;
*) cat "${PWD}/mocks/iojs.org-dist-index.tab" ;;
esac
}
try nvm_remote_versions
[ "${CAPTURED_EXIT_CODE}" = 3 ] || die 'partial list should preserve the failure status'
[ "${CAPTURED_STDOUT}" = "$(cat "${PWD}/mocks/nvm_ls_remote_iojs.txt")" ] \
|| die 'the working io.js mirror should still provide its versions'
try_err nvm_remote_versions
[ "${CAPTURED_STDERR}" = 'Failed to download version list from https://nodejs.org/dist/index.tab' ] \
|| die 'partial list should report the failed mirror'
# Custom mirrors may contain credentials; the new diagnostic must redact them.
export NVM_NODEJS_ORG_MIRROR='https://user:password@example.com/dist'
nvm_download() { return 60; }
try_err nvm_ls_remote
[ "${CAPTURED_STDERR}" = 'Failed to download version list from https://***@example.com/dist/index.tab' ] \
|| die 'the download error should redact mirror credentials'
unset -f nvm_download nvm_record_lts_status
@@ -35,6 +35,44 @@ for TARGET in .npmrc .git-credentials; do
[ -z "${CAPTURED_STDOUT}" ] || die "expected no version from a symlink to ${TARGET}; got \`${CAPTURED_STDOUT}\`"
done
# every local user can read a command's arguments, so the content is not passed in them either
MOCK_BIN="${TEST_DIR}/bin"
mkdir -p "${MOCK_BIN}" || die 'failed to create the mock bin dir'
for COMMAND in grep sed awk tr; do
{
echo '#!/bin/sh'
printf '%s\n' 'printf "%s\n" "$*" >> "${0%/*}/../arguments"'
echo 'PATH="${PATH#*:}"'
echo 'exec "${0##*/}" "$@"'
} > "${MOCK_BIN}/${COMMAND}"
chmod +x "${MOCK_BIN}/${COMMAND}"
done
printf 'SECRET=\n' > "${TEST_DIR}/home/wg.key"
printf 'a=b\nSECRET=c\nSECRET=d\n' > "${TEST_DIR}/home/.env"
printf 'a.b.c-SECRET\n' > "${TEST_DIR}/home/token"
printf '1.2.3.4-SECRET\n' > "${TEST_DIR}/home/token2"
for TARGET in wg.key .env token token2; do
rm -f "${NVMRC}"
ln -s "../home/${TARGET}" "${NVMRC}" || die 'failed to create the symlink'
: > "${TEST_DIR}/arguments"
CAPTURED_STDERR="$(set +x; PATH="${MOCK_BIN}:${PATH}" nvm_process_nvmrc "${NVMRC}" 2>&1 >/dev/null)" \
&& die "expected a symlink to ${TARGET} to be invalid"
[ "${CAPTURED_STDERR}" = "invalid .nvmrc! '${NVMRC}' is a symbolic link, so it must contain a version or an alias name; its content is not shown." ] || die "expected the symlink error for ${TARGET}; got \`${CAPTURED_STDERR}\`"
[ -s "${TEST_DIR}/arguments" ] || die 'expected the mocked commands to record their arguments'
! nvm_grep -q SECRET "${TEST_DIR}/arguments" || die "expected a symlink to ${TARGET} to not put its content in a command's arguments; got \`$(nvm_grep SECRET "${TEST_DIR}/arguments")\`"
done
# nor when the content is valid
printf 'SECRET=\n20\n' > "${TEST_DIR}/home/accepted"
rm -f "${NVMRC}"
ln -s ../home/accepted "${NVMRC}" || die 'failed to create the symlink'
: > "${TEST_DIR}/arguments"
CAPTURED_STDOUT="$(set +x; PATH="${MOCK_BIN}:${PATH}" nvm_process_nvmrc "${NVMRC}" 2>/dev/null)" || die 'expected a symlink to a valid version file to be valid'
[ "${CAPTURED_STDOUT}" = '20' ] || die "expected \`20\` from a symlink to a valid version file; got \`${CAPTURED_STDOUT}\`"
! nvm_grep -q SECRET "${TEST_DIR}/arguments" || die "expected a symlink to a valid version file to not put its content in a command's arguments; got \`$(nvm_grep SECRET "${TEST_DIR}/arguments")\`"
nvm alias nvmrc_symlink_alias v0.0.1 > /dev/null 2>&1 || die 'failed to create an alias'
# a deliberate symlink to another version file, in or above the project, still works
@@ -0,0 +1,78 @@
#!/bin/sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
rm -rf "${TEST_DIR-}"
unset TEST_DIR SWAP_FROM SWAP_TO SWAP_DONE
}
: nvm.sh
\. ../../../nvm.sh
\. ../../common.sh
TEST_DIR="${PWD}/nvm_process_nvmrc_swap_tmp"
mkdir -p "${TEST_DIR}/home" "${TEST_DIR}/project" "${TEST_DIR}/bin" || die 'failed to create test dirs'
printf 'https://user:SECRET@github.com\n' > "${TEST_DIR}/home/.git-credentials"
NVMRC="${TEST_DIR}/project/.nvmrc"
# `cat` is the first command `nvm_process_nvmrc` runs:
# the mock swaps `.nvmrc` once, as another user who can write the directory could, then records its arguments
export SWAP_FROM SWAP_TO SWAP_DONE
SWAP_TO="${NVMRC}"
SWAP_DONE="${TEST_DIR}/swapped"
{
echo '#!/bin/sh'
printf '%s\n' '[ -e "${SWAP_DONE}" ] || { : > "${SWAP_DONE}"; command mv -f "${SWAP_FROM}" "${SWAP_TO}"; }'
} > "${TEST_DIR}/bin/cat"
for COMMAND in cat grep sed awk tr find ls; do
{
[ "${COMMAND}" = cat ] || echo '#!/bin/sh'
printf '%s\n' 'printf "%s\n" "$*" >> "${0%/*}/../arguments"'
echo 'PATH="${PATH#*:}"'
echo 'exec "${0##*/}" "$@"'
} >> "${TEST_DIR}/bin/${COMMAND}"
chmod +x "${TEST_DIR}/bin/${COMMAND}"
done
check() {
: > "${TEST_DIR}/arguments"
rm -f "${SWAP_DONE}"
CAPTURED_EXIT_CODE=0
CAPTURED_STDOUT="$(set +x; PATH="${TEST_DIR}/bin:${PATH}" nvm_process_nvmrc "${NVMRC}" 2> "${TEST_DIR}/stderr")" || CAPTURED_EXIT_CODE=$?
CAPTURED_STDERR="$(command cat "${TEST_DIR}/stderr")"
[ -e "${SWAP_DONE}" ] || die "$1: expected the mocked \`cat\` to swap the file"
case "${CAPTURED_STDOUT}${CAPTURED_STDERR}" in
*SECRET*) die "$1: expected the content to not be shown; got \`${CAPTURED_STDOUT}${CAPTURED_STDERR}\`" ;;
esac
! nvm_grep -q SECRET "${TEST_DIR}/arguments" || die "$1: expected the content to not be in a command's arguments; got \`$(nvm_grep SECRET "${TEST_DIR}/arguments")\`"
}
# a regular file, swapped for a symlink before it is read
rm -f "${NVMRC}"
printf 'v20.0.0\n' > "${NVMRC}"
SWAP_FROM="${TEST_DIR}/project/link"
ln -s ../home/.git-credentials "${SWAP_FROM}" || die 'failed to create the symlink'
check 'a regular file swapped for a symlink'
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected the regular file's version; got exit code ${CAPTURED_EXIT_CODE}"
[ "${CAPTURED_STDOUT}" = v20.0.0 ] || die "expected the regular file's version; got \`${CAPTURED_STDOUT}\`"
# a symlink, swapped for a regular file before it is checked
rm -f "${NVMRC}"
ln -s ../home/.git-credentials "${NVMRC}" || die 'failed to create the symlink'
SWAP_FROM="${TEST_DIR}/project/regular"
printf 'v20.0.0\n' > "${SWAP_FROM}"
check 'a symlink swapped for a regular file'
[ "${CAPTURED_EXIT_CODE}" != 0 ] || die "expected a symlink swapped for a regular file to be invalid; got exit code ${CAPTURED_EXIT_CODE}"
# a hard link to another file is treated like a symlink
rm -f "${NVMRC}"
ln "${TEST_DIR}/home/.git-credentials" "${NVMRC}" || die 'failed to create the hard link'
try_err nvm_process_nvmrc "${NVMRC}"
[ "${CAPTURED_EXIT_CODE}" != 0 ] || die "expected a hard link to be invalid; got exit code ${CAPTURED_EXIT_CODE}"
case "${CAPTURED_STDERR}" in
*SECRET*) die "expected a hard link's content to not be shown; got \`${CAPTURED_STDERR}\`" ;;
esac
cleanup
@@ -0,0 +1,30 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
\. ../../common.sh
# keys that only match each other as a regex are distinct
for CONTENT in "$(printf '22\nnode-dist=x\nnode.dist=y')" "$(printf '22\nabc=x\na.c=y')" "$(printf '22\nab=x\na+b=y')"; do
try nvm_process_nvmrc_content "${CONTENT}"
[ "${CAPTURED_EXIT_CODE}" = '0' ] || die "distinct keys were rejected as duplicates in >${CONTENT}<; got exit code ${CAPTURED_EXIT_CODE}"
[ "${CAPTURED_STDOUT}" = '22' ] || die "expected the version 22 from >${CONTENT}<; got >${CAPTURED_STDOUT}<"
done
# keys with regex metacharacters are not passed to grep
try_err nvm_process_nvmrc_content "$(printf '22\na(=x\nb[=y')"
[ "${CAPTURED_EXIT_CODE}" = '0' ] || die "keys with regex metacharacters were rejected; got exit code ${CAPTURED_EXIT_CODE}"
[ -z "${CAPTURED_STDERR}" ] || die "expected no errors for keys with regex metacharacters; got >${CAPTURED_STDERR}<"
# duplicates are still rejected, including keys with regex metacharacters
for CONTENT in "$(printf '22\na=1\na=2')" "$(printf '22\na.c=1\na.c=2')" "$(printf '22\n[x=1\n[x=2')"; do
try_err nvm_process_nvmrc_content "${CONTENT}"
[ "${CAPTURED_EXIT_CODE}" = '1' ] || die "duplicate keys were accepted in >${CONTENT}<; got exit code ${CAPTURED_EXIT_CODE}"
case "${CAPTURED_STDERR}" in
'invalid .nvmrc!'*) ;;
*) die "expected the invalid .nvmrc message for >${CONTENT}<; got >${CAPTURED_STDERR}<" ;;
esac
done
@@ -0,0 +1,43 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
\. ../../common.sh
for KEY in a a.b 'a*' '(' '[' 'a\' 'a b'; do
CONTENT="20
${KEY}=1
other=2
${KEY} = 3"
try_err nvm_process_nvmrc_content "${CONTENT}"
[ "${CAPTURED_EXIT_CODE}" = 1 ] || die "expected a duplicate key \`${KEY}\` to be invalid; got exit code ${CAPTURED_EXIT_CODE}"
case "${CAPTURED_STDERR}" in
*'invalid .nvmrc!'*) ;;
*) die "expected the invalid .nvmrc message for a duplicate key \`${KEY}\`; got >${CAPTURED_STDERR}<" ;;
esac
try nvm_process_nvmrc_content "${CONTENT}"
[ -z "${CAPTURED_STDOUT}" ] || die "expected no version for a duplicate key \`${KEY}\`; got \`${CAPTURED_STDOUT}\`"
done
# keys are compared as they are written, not as patterns
for KEY in b ab A a. '*' '.*' '?' 'a|b' '[a]' 'a b' 'b a' 'b a'; do
for CONTENT in "20
a=1
${KEY}=2" "20
${KEY}=1
a=2"; do
try_err nvm_process_nvmrc_content "${CONTENT}"
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected the keys \`a\` and \`${KEY}\` to be distinct; got exit code ${CAPTURED_EXIT_CODE}"
case "${CAPTURED_STDERR}" in
*'invalid .nvmrc!'*) die "expected no error for the keys \`a\` and \`${KEY}\`; got >${CAPTURED_STDERR}<" ;;
esac
try nvm_process_nvmrc_content "${CONTENT}"
[ "${CAPTURED_STDOUT}" = '20' ] || die "expected \`20\` with the keys \`a\` and \`${KEY}\`; got \`${CAPTURED_STDOUT}\`"
done
done
+57
View File
@@ -0,0 +1,57 @@
#!/bin/sh
ORIG_NVM_DIR="${NVM_DIR}"
TMP_DIR=''
cleanup () {
case "${TMP_DIR}" in
/*) rm -rf "${TMP_DIR}" ;;
esac
NVM_DIR="${ORIG_NVM_DIR}"
export NVM_DIR
}
die () { echo "$@" ; cleanup ; exit 1; }
: nvm.sh
\. ../../../nvm.sh
TMP_DIR="$(mktemp -d)"
NVM_DIR="${TMP_DIR}/nvm"
export NVM_DIR
mkdir -p "${NVM_DIR}" || die 'could not create NVM_DIR'
[ "_$(nvm_resolve_lts_name on)" = '_on' ] || die "without recorded LTS status, the name should be kept; got >$(nvm_resolve_lts_name on)<"
row () {
printf '%s\t2024-01-01\tsrc\t-\t-\t-\t-\t-\t-\t%s\t-\n' "$1" "$2"
}
# not newest first, so the newest codename has to come from the versions
{ row v20.19.0 Iron; row v26.12.1 -; row v24.11.0 Krypton; row v4.9.1 Argon; row v24.0.0 -; row v22.11.0 Jod; row v8.17.0 Carbon; } | nvm_record_lts_status || die 'could not record LTS status'
check () {
ACTUAL="$(nvm_resolve_lts_name "$1")"
[ "_${ACTUAL}" = "_$2" ] || die "\`nvm_resolve_lts_name '$1'\` should print >$2<; got >${ACTUAL}<"
}
# the newest codename containing the name
check on krypton
check o krypton
check ar carbon
check arg argon
check ir iron
check iron iron
check j jod
# not a regex, and not a codename yet, so kept as given
check . .
check 'i.on' 'i.on'
check '(' '('
check nosuch nosuch
# names nvm resolves some other way
check '*' '*'
check -1 -1
check '' ''
# LTS names are lowercase; an uppercase one is kept, for `nvm_normalize_lts` to reject
check Iron Iron
cleanup
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
yes_creds() {
nvm_url_has_credentials "${1}" || die "nvm_url_has_credentials '${1}': expected success"
}
no_creds() {
! nvm_url_has_credentials "${1}" || die "nvm_url_has_credentials '${1}': expected failure"
}
yes_creds 'https://user:pw@mirror.example/dist'
yes_creds 'http://user:pw@127.0.0.1:8080/dist/index.tab'
yes_creds 'https://user@mirror.example'
yes_creds 'https://user:pw@[::1]:8080/dist'
yes_creds 'https://user:p@ss@mirror.example/dist'
yes_creds 'https://user:pw@mirror.example/a"b\c'
no_creds 'https://nodejs.org/dist/index.tab'
no_creds 'https://mirror.example/dist/@scope/index.tab'
no_creds 'https://mirror.example/user:pw@elsewhere.example/dist'
no_creds ''
no_creds '-o'
no_creds 'user:pw@mirror.example/dist'
no_creds 'ftp://user:pw@mirror.example/dist'
no_creds '/tmp/user:pw@mirror.example/node.tar.xz'
no_creds 'https://user:pw@mirror.example/a b'
no_creds "$(printf 'https://user:pw@mirror.example/a\nb')"
no_creds "$(printf 'https://user:pw@mirror.example/a\rb')"
no_creds "$(printf 'https://user:pw@mirror.example/a\033b')"
+62
View File
@@ -78,3 +78,65 @@ for PATTERN in v1.2 v1 1.2.3 v1.2.3- v1.2.3-.x v1.2.3-a..b v1.2.3.4 v1.2.3.; do
[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "nvm_version $PATTERN did not exit 0; got $CAPTURED_EXIT_CODE"
done
unset -f nvm_is_version_installed
# `node`/`stable` is the newest installed version, from one listing, once that is 1.0 or later
nvm_ls() {
case "$1" in
node) printf 'v0.12.18\nv20.0.0\nv22.1.0\n' ;;
*) die "\"nvm_version node\" must list the installed versions only once; got \"nvm_ls $1\"" ;;
esac
}
for PATTERN in node node- stable; do
try nvm_version "$PATTERN"
[ "_$CAPTURED_STDOUT" = "_v22.1.0" ] || die "\"nvm_version $PATTERN\" did not return the newest installed version; got $CAPTURED_STDOUT"
[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "\"nvm_version $PATTERN\" did not exit 0; got $CAPTURED_EXIT_CODE"
done
# a system node, which `nvm_ls` lists last, is not the newest installed version
nvm_ls() {
case "$1" in
node) printf 'v20.0.0\nv22.1.0\nsystem v19.0.0\n' ;;
*) die "\"nvm_version node\" with a system node must list the installed versions only once; got \"nvm_ls $1\"" ;;
esac
}
try nvm_version node
[ "_$CAPTURED_STDOUT" = "_v22.1.0" ] || die '"nvm_version node" with a system node did not skip it; got '"$CAPTURED_STDOUT"
# with only 0.x versions installed, `stable` is the newest even minor, so it falls back to `nvm_ls stable`
nvm_ls() {
case "$1" in
node) printf 'v0.10.48\nv0.11.16\n' ;;
*) echo "pattern: $1" ;;
esac
}
try nvm_version node
[ "_$CAPTURED_STDOUT" = "_pattern: stable" ] || die '"nvm_version node" with only 0.x versions did not fall back to "nvm_ls stable"; got '"$CAPTURED_STDOUT"
# nothing installed falls back too, so the result and exit code are unchanged
nvm_ls() {
case "$1" in
node) echo 'N/A'; return 3 ;;
*) echo 'N/A'; return 3 ;;
esac
}
try nvm_version node
[ "_$CAPTURED_STDOUT" = "_N/A" ] || die '"nvm_version node" with nothing installed did not return N/A; got '"$CAPTURED_STDOUT"
[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die '"nvm_version node" with nothing installed did not exit 3; got '"$CAPTURED_EXIT_CODE"
# an alias named `stable` takes precedence over the newest installed version
nvm_ls() {
case "$1" in
node) printf 'v20.0.0\nv22.1.0\n' ;;
*) echo "pattern: $1" ;;
esac
}
OLD_NVM_DIR="${NVM_DIR}"
NVM_DIR="$(mktemp -d)"
mkdir -p "${NVM_DIR}/alias"
echo v20.0.0 > "${NVM_DIR}/alias/stable"
try nvm_version node
rm -rf "${NVM_DIR}"
NVM_DIR="${OLD_NVM_DIR}"
[ "_$CAPTURED_STDOUT" = "_pattern: stable" ] || die '"nvm_version node" did not let an alias named "stable" take precedence; got '"$CAPTURED_STDOUT"
unset -f nvm_ls
@@ -0,0 +1,86 @@
#!/bin/sh
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
cd "${ORIG_PWD}" || :
PATH="${REAL_PATH:-${PATH}}"
nvm deactivate > /dev/null 2>&1
rm -rf "${TEST_DIR-}" "${NVM_DIR}/${TEST_VERSION}"
unset TEST_DIR TEST_VERSION ORIG_PWD REAL_PATH SWAP_TARGET
}
: nvm.sh
\. ../../../nvm.sh
\. ../../common.sh
ORIG_PWD="${PWD}"
TEST_VERSION='v0.2.4'
make_fake_node "${TEST_VERSION}" || die 'failed to create a fake node'
TEST_DIR="${PWD}/nvm_write_nvmrc_replace_tmp"
mkdir -p "${TEST_DIR}/project" "${TEST_DIR}/bin" "${TEST_DIR}/dir" || die 'failed to create test dirs'
# stand-ins for `tee` and `mv` that turn .nvmrc into a symlink just before the real command runs,
# as another user who can write the directory could
for CMD in tee mv; do
printf '%s\n' '#!/bin/sh' \
'rm -rf "${PWD}/.nvmrc" && ln -s "${SWAP_TARGET}" "${PWD}/.nvmrc" || exit 99' \
'PATH="${REAL_PATH}"' \
"exec ${CMD} \"\$@\"" > "${TEST_DIR}/bin/${CMD}"
chmod +x "${TEST_DIR}/bin/${CMD}"
done
cd "${TEST_DIR}/project" || die 'failed to enter the project dir'
export REAL_PATH="${PATH}"
# 1. a symlink to a file, swapped in after the check, does not get written through
echo 'KEEPME' > "${TEST_DIR}/target"
export SWAP_TARGET="${TEST_DIR}/target"
echo 'v0.0.1' > .nvmrc
PATH="${TEST_DIR}/bin:${REAL_PATH}" nvm_write_nvmrc "${TEST_VERSION}" > /dev/null 2>&1
PATH="${REAL_PATH}"
[ "$(cat "${TEST_DIR}/target")" = 'KEEPME' ] || die "expected a symlink swapped in after the check to not be written through; target is now \`$(cat "${TEST_DIR}/target")\`"
# 2. nor does a symlink to a directory get the file moved into it
rm -rf .nvmrc
export SWAP_TARGET="${TEST_DIR}/dir"
echo 'v0.0.1' > .nvmrc
PATH="${TEST_DIR}/bin:${REAL_PATH}" nvm_write_nvmrc "${TEST_VERSION}" > /dev/null 2>&1
PATH="${REAL_PATH}"
[ -z "$(ls -A "${TEST_DIR}/dir")" ] || die "expected nothing to be written into a symlinked directory; found \`$(ls -A "${TEST_DIR}/dir")\`"
[ "$(cat "${TEST_DIR}/target")" = 'KEEPME' ] || die 'expected the target to still be unchanged'
# 3. a hard link to .nvmrc keeps its content
rm -rf .nvmrc
echo 'KEEPME' > "${TEST_DIR}/hardlinked"
ln "${TEST_DIR}/hardlinked" .nvmrc || die 'failed to create the hard link'
try_err nvm_write_nvmrc "${TEST_VERSION}"
[ "${CAPTURED_EXIT_CODE}" = 0 ] || die "expected exit code 0; got ${CAPTURED_EXIT_CODE}: ${CAPTURED_STDERR}"
[ "$(cat .nvmrc)" = "${TEST_VERSION}" ] || die "expected .nvmrc to contain ${TEST_VERSION}; got \`$(cat .nvmrc)\`"
[ "$(cat "${TEST_DIR}/hardlinked")" = 'KEEPME' ] || die "expected a hard link to .nvmrc to be left alone; got \`$(cat "${TEST_DIR}/hardlinked")\`"
# 4. a new .nvmrc gets its mode from the umask
rm -f .nvmrc
(
umask 027
nvm_write_nvmrc "${TEST_VERSION}" > /dev/null 2>&1
) || die 'expected writing a new .nvmrc to succeed'
MODE="$(ls -l .nvmrc | cut -c1-10)"
[ "${MODE}" = '-rw-r-----' ] || die "expected .nvmrc to have mode -rw-r----- under umask 027; got ${MODE}"
# 5. a directory named .nvmrc is an error, and nothing is moved into it
rm -f .nvmrc
mkdir .nvmrc
try_err nvm_write_nvmrc "${TEST_VERSION}"
[ "${CAPTURED_EXIT_CODE}" = 3 ] || die "expected exit code 3 for a directory .nvmrc; got ${CAPTURED_EXIT_CODE}"
[ "${CAPTURED_STDERR}" = "Warning: Unable to write version number (${TEST_VERSION}) to .nvmrc" ] || die "expected the unable-to-write warning; got \`${CAPTURED_STDERR}\`"
[ -z "$(ls -A .nvmrc)" ] || die "expected nothing to be moved into a directory .nvmrc; found \`$(ls -A .nvmrc)\`"
rmdir .nvmrc
# 6. no temporary directories are left behind
LEFTOVER="$(ls -A "${NVM_DIR}" | grep '^\.nvmrc\.')"
[ -z "${LEFTOVER}" ] || die "expected no temporary directories left in \$NVM_DIR; found \`${LEFTOVER}\`"
cleanup
+33
View File
@@ -0,0 +1,33 @@
#!/bin/sh
NVM_ENV=testing \. ../../install.sh
die() { echo "$*" >&2; exit 1; }
TEST_ROOT="$(mktemp -d)" || die 'could not create test directory'
trap 'rm -rf "${TEST_ROOT}"' EXIT HUP INT TERM
SOURCE="${TEST_ROOT}/source"
git init -q "${SOURCE}" || die 'could not initialize source'
git -C "${SOURCE}" -c user.name=test -c user.email=test@example.invalid commit --allow-empty -qm fixture || die 'could not commit fixture'
git -C "${SOURCE}" tag v0.0.1 || die 'could not tag fixture'
nvm_source() { printf '%s\n' "${SOURCE}"; }
NVM_INSTALL_VERSION=v0.0.1
export NVM_INSTALL_VERSION
NVM_DIR="${TEST_ROOT}/fresh"
export NVM_DIR
install_nvm_from_git || die 'fresh install failed'
[ "$(git -C "${NVM_DIR}" remote get-url origin)" = "${SOURCE}" ] || die 'fresh install did not retain origin'
NVM_DIR="${TEST_ROOT}/existing"
export NVM_DIR
git init -q "${NVM_DIR}" || die 'could not initialize existing install'
git -C "${NVM_DIR}" remote add fork "${TEST_ROOT}/wrong" || die 'could not add fork'
git -C "${NVM_DIR}" remote add origin "${SOURCE}" || die 'could not add origin'
install_nvm_from_git || die 'existing install did not select matching origin'
[ "$(git -C "${NVM_DIR}" remote get-url fork)" = "${TEST_ROOT}/wrong" ] || die 'fork remote changed'
git -C "${NVM_DIR}" remote set-url origin "${TEST_ROOT}/wrong-origin" || die 'could not change origin'
git -C "${NVM_DIR}" remote add nvm-origin "${TEST_ROOT}/occupied" || die 'could not occupy alternate name'
install_nvm_from_git || die 'existing install did not add a matching remote'
[ "$(git -C "${NVM_DIR}" remote get-url nvm-origin-1)" = "${SOURCE}" ] || die 'new remote missing'
[ "$(git -C "${NVM_DIR}" remote get-url origin)" = "${TEST_ROOT}/wrong-origin" ] || die 'origin remote changed'
+21 -5
View File
@@ -4,13 +4,13 @@ cleanup () {
rm -rf "$npm_config_prefix/lib" >/dev/null 2>&1
unset npm_config_prefix
rm -f npm
[ -z "${FAKE_NPM_DIR-}" ] || rm -rf "${FAKE_NPM_DIR}"
[ -z "${WINDOWS_NPM_DIR-}" ] || rm -rf "${WINDOWS_NPM_DIR}"
PATH="$ORIGINAL_PATH"
NVM_DIR="$ORIGINAL_NVM_DIR"
unset -f setup cleanup die
unset message ORIGINAL_PATH ORIGINAL_NVM_DIR WINDOWS_NPM_DIR
unset message ORIGINAL_PATH ORIGINAL_NVM_DIR FAKE_NPM_DIR WINDOWS_NPM_DIR
}
die () { echo "$@" ; cleanup ; exit 1; }
@@ -55,9 +55,10 @@ message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm had only itself installed as a global module; got:\n${message}"
# Faking the absence of npm
PATH=".:$PATH"
touch npm
chmod +x npm
FAKE_NPM_DIR="$(mktemp -d)"
touch "${FAKE_NPM_DIR}/npm"
chmod +x "${FAKE_NPM_DIR}/npm"
PATH="${FAKE_NPM_DIR}:$PATH"
message=$(nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should have not printed a notice when npm was unavailable; got:\n${message}"
@@ -83,5 +84,20 @@ nvm_is_wsl() { return 1; }
message=$(nvm_check_global_modules)
[ -n "$message" ] || die 'nvm_check_global_modules should still warn about a Windows npm outside WSL, where it is the system node'
# npm must not apply the npmrc of the project that `$PWD` is in
cat <<'SH' >"${FAKE_NPM_DIR}/npm"
#!/bin/sh
case "$1" in
--version) echo '10.0.0' ;;
list) printf '%s\n' 'npm@10.0.0' "└── cwd@[$(pwd)]" ;;
esac
SH
PATH="${FAKE_NPM_DIR}:${ORIGINAL_PATH}"
message=$(nvm_check_global_modules)
case "$message" in
*"cwd@[/]"*) ;;
*) die "nvm_check_global_modules should run npm from \`/\`; got:\n${message}" ;;
esac
cleanup
+3
View File
@@ -0,0 +1,3 @@
if [ "$#" -eq 2 ] && [ "$1" = "get" ] && [ "$2" = "const.ohos.fullname" ]; then
echo "OpenHarmony-6.1.0.31"
fi
+3
View File
@@ -0,0 +1,3 @@
if [ "$#" -eq 2 ] && [ "$1" = "get" ] && [ "$2" = "const.ohos.fullname" ]; then
echo "NotOpenHarmony-1.2.3"
fi
+5
View File
@@ -0,0 +1,5 @@
if [ "_$1" = "_-m" ]; then
echo "aarch64"
else
echo "HarmonyOS localhost HongMeng Kernel 1.12.0 #1 SMP Tue Jul 14 09:40:51 UTC 2026 aarch64 Toybox"
fi