`nvm reinstall-packages 99` resolved the version to `N/A` and kept going:
it told the user to run `nvm install N/A`,
printed "Reinstalling global packages from N/A..." and exited 0.
Only the case of an installed version excluded by `--only` returned early.
Now any unresolved version prints "Version '99' is not installed." and returns 3,
like `nvm install --reinstall-packages-from=`,
which already requires an installed version.
Assisted-by: Claude Code <noreply@anthropic.com>
Signed-off-by: thejesh23 <35212698+thejesh23@users.noreply.github.com>
Sourcing nvm.sh fails when the caller has made readonly a variable that nvm.sh declares as a local,
such as `readonly VERSION` in a CI build script:
bash rejects the `local`, and dash exits.
Prefix the locals that sourcing and its `nvm use` reach.
The test derives the unprefixed local names from nvm.sh,
so a new collision fails it.
`nvm_install_default_packages` reported an invalid default-packages file by assigning `nvm`'s `EXIT_CODE` without declaring it.
It now declares its own, and `nvm install` uses its return status instead,
except 3, which means npm failed to install the packages and,
as before, does not fail the install.
Fixes#3584
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>
`nvm prune` uninstalls every version except the newest install per major
(per minor with `--minor`, and always per minor for `v0.x`),
the current version, the `$NVM_DIR/current` symlink target,
and anything an alias resolves to.
It lists what it will remove and asks first;
`--dry-run` only lists, and `--force` skips the prompt.
Co-authored-by: Guillermo Esguerra <gesguerrab@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
Exercise both argument orders and multiple job counts against the existing fake source fixture,
checking the actual build and install make arguments.
Use an isolated offline cache and a conflicting inherited job count to catch regressions that a successful real compilation alone cannot detect.
Keep a real source build with explicit jobs in each installation suite,
but remove the redundant serial compilation and make installation failures and version mismatches fail the test immediately.
Parse words before the cursor once to offer flags, versions, and aliases
in the positions that accept them. Distinguish install options before
and after the version, and leave run and exec arguments to the shell.
Match local names literally. Account for Readline splitting at `=` and
quoting common prefixes. Give zsh the same candidates as raw strings so
its line editor can match, quote, and close arguments in its own syntax.
Check the offered flags against nvm help and cover argument boundaries,
including the actual arguments submitted by zsh after Tab completion.
Co-authored-by: Peter Dave Hello <hsu@peterdavehello.org>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
A `type` function or alias defined before nvm is sourced
hijacked `nvm_has` and `nvm_command_info`.
`nvm_has` now uses `command -v`;
`nvm_command_info` needs `type`'s output,
so it uses `builtin type` in zsh,
whose `command type` runs an external `type` that can't see shell functions.
Since `command -v` makes dash hash the command,
`nvm_command_info` also parses dash's and ksh's "tracked alias" output.
Fixes#2352.
`cdnvm` calls `command cd`,
which skips any `cd` function defined by another tool,
like the one `rvm` uses to switch ruby versions.
Salvaged from #1066, which predates the README's `cdnvm` snippet.
Co-authored-by: Mike Milkman <mik356ua@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>
A trailing space (or tab) left by an editor, or an indented line,
in `$NVM_DIR/default-packages` tripped the "multiple space-separated values" check,
so the whole file was rejected and no default packages were installed after `nvm install`,
with an error naming the wrong problem.
Trim blanks around each line before checking it,
as is already done for a trailing `\r`;
a line with two values is still rejected.
Assisted-by: Claude Code <noreply@anthropic.com>
Signed-off-by: thejesh23 <35212698+thejesh23@users.noreply.github.com>
About 1.4% of WSL jobs freeze the runner while setup-wsl starts WSL2
(actions/runner-images#14938):
no step ever finishes, no step timeout fires,
and GitHub drops the job as "lost communication" after 45 minutes,
holding up nearly every run.
A job-level `timeout-minutes` is enforced by the server, so it still applies.
Ubuntu's images already ship bash, git, curl, wget and ca-certificates,
so its apt step only upgrades them,
and a slow `archive.ubuntu.com` has stretched that to 30 minutes.
When they are present, give the upgrade a minute and carry on without it;
otherwise retry 3 times with short delays instead of 8 over 10 minutes.
Resolving `default -> lts/*` at startup walks default -> lts/* -> lts/<name> -> version, and each `nvm_alias` step forked: `$(nvm_normalize_lts)` even when nothing is rewritten, `echo | tr` to check for lowercase, and `$(nvm_version_dir old)` inside `nvm_alias_path`.
- `nvm_alias_path`: use `${NVM_DIR}` directly, as `nvm_version_dir old` does
- `nvm_normalize_lts`: check for uppercase with a `case` pattern instead of `tr`
- `nvm_alias`: only use a subshell for `lts/-N`, the one form that is rewritten
Assisted-by: Claude Opus 5.5 <noreply@anthropic.com>
`$SHELL` is the account's login shell,
so when a terminal runs a different shell,
like zsh from Terminal's settings without `chsh`,
the installer wrote to the other shell's profile.
Prefer the shell that ran the installer,
but only when it is a login shell,
since a script that runs the installer,
like a bash dotfiles bootstrap,
isn't the user's shell.
Fixes#592.
Closes#611, whose idea this is.
- 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>
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>
`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>
`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>
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
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.
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>
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.
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>
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.
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>
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.
`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 `?`.
`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 `/`.