Jake Lodwick and Jordan Harband
d22bf7f538
[Refactor] nvm_alias, nvm_resolve_alias: use builtins
...
[Tests] `nvm_alias`, `nvm_resolve_alias`: add edge-case tests
nvm_alias() used a sed/awk pipeline to strip comments and blank lines from alias files that almost always contain a single word.
A while-read loop with parameter expansion does the same filtering more directly.
nvm_resolve_alias() piped nvm_alias through head and tail to extract one line, and used printf/grep for cycle detection.
Parameter expansion and a case statement replace both without the extra plumbing.
All replacements are POSIX (read -r, case, IFS=, parameter expansion).
As a side effect, this also removes 4 external process invocations during shell init.
[Fix] `nvm_resolve_alias`: detect cycles via newline-anchored `case`
The original commit referenced above changed SEEN_ALIASES from `\n`-delimited
storage (interpreted by `printf '%b' | nvm_grep -e "^${name}$"`) to space-
delimited but left the line-anchored grep in place — without newlines in
the haystack the anchored pattern can never match, so cycles never break.
Switch to literal-newline storage and a `case` pattern anchored on those
newlines. Newline anchoring also handles alias names containing spaces,
which token-based patterns false-positive on (e.g. lookup of `bar` matches
substring " bar " inside " foo bar midway " when the chain visits the
multi-token alias `foo bar`).
New test file covers self-loop, multi-hop loop, cycle through a
space-bearing alias name, and a non-cycle through a space-bearing
alias name. Existing `test/fast/Aliases/circular/` fixtures continue
to pass.
2026-02-17 13:44:31 -07:00
Jordan Harband
dd61ae4bc8
[Robustness] nvm_alias: explicitly succeed when the alias file is unreadable
...
The sed/awk pipeline exits with awk's status,
so an existing-but-unreadable alias file produces empty output with status 0 - but only by accident,
alongside sed's read error on stderr.
Make that contract explicit:
a nonzero status here would flip `nvm_ensure_default_set` from "default is already set" to recreating it,
silently overwriting a write-only default alias.
2026-07-09 15:43:56 -07:00
Jordan Harband
d200a21559
[Fix] nvm_normalize_lts: only reject uppercase for LTS names, not regular aliases
...
Code scanning - action / CodeQL-Build (push) Has been cancelled
Tests: `nvm install-latest-npm` / matrix (push) Has been cancelled
Tests: linting / eclint (push) Has been cancelled
Tests: linting / dockerfile_lint (push) Has been cancelled
Tests: linting / doctoc (push) Has been cancelled
Tests: linting / test_naming (push) Has been cancelled
Tests: nvm install with set -e / matrix (push) Has been cancelled
Tests: release process / release (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (bash_completion, bash) (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (install.sh, bash) (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (nvm-exec, bash) (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (nvm.sh, bash) (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (nvm.sh, dash) (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (nvm.sh, ksh) (push) Has been cancelled
Tests: fast / fast (bash, gawk) (push) Has been cancelled
Tests: fast / fast (dash, gawk) (push) Has been cancelled
Tests: fast / fast (sh, gawk) (push) Has been cancelled
Tests: fast / fast (zsh, gawk) (push) Has been cancelled
Tests: fast / fast (bash, mawk) (push) Has been cancelled
Tests: fast / fast (dash, mawk) (push) Has been cancelled
Tests: fast / fast (sh, mawk) (push) Has been cancelled
Tests: fast / fast (zsh, mawk) (push) Has been cancelled
Tests: installation_iojs / installation_iojs without curl (bash) (push) Has been cancelled
Tests: installation_iojs / installation_iojs without curl (dash) (push) Has been cancelled
Tests: installation_iojs / installation_iojs without curl (sh) (push) Has been cancelled
urchin tests / tests (bash, slow) (push) Has been cancelled
Tests: installation_iojs / installation_iojs without curl (zsh) (push) Has been cancelled
Tests: installation_node / installation_node (bash) (push) Has been cancelled
Tests: installation_node / installation_node (bash, without curl) (push) Has been cancelled
Tests: installation_node / installation_node (dash) (push) Has been cancelled
Tests: installation_node / installation_node (dash, without curl) (push) Has been cancelled
Tests: installation_node / installation_node (sh) (push) Has been cancelled
Tests: installation_node / installation_node (zsh) (push) Has been cancelled
Tests: installation_node / installation_node (zsh, without curl) (push) Has been cancelled
Tests: xenial / xenial (bash) (push) Has been cancelled
urchin tests / tests (bash, sourcing) (push) Has been cancelled
Tests: xenial / xenial (dash) (push) Has been cancelled
Tests: xenial / xenial (sh) (push) Has been cancelled
Tests: xenial / xenial (zsh) (push) Has been cancelled
urchin tests / tests (bash, install_script) (push) Has been cancelled
urchin tests / tests (dash, installation_iojs) (push) Has been cancelled
urchin tests / tests (dash, sourcing) (push) Has been cancelled
urchin tests / tests (sh, installation_iojs) (push) Has been cancelled
urchin tests / tests (sh, slow) (push) Has been cancelled
urchin tests / tests (sh, sourcing) (push) Has been cancelled
urchin tests / tests (zsh, installation_iojs) (push) Has been cancelled
urchin tests / tests (zsh, slow) (push) Has been cancelled
urchin tests / tests (zsh, sourcing) (push) Has been cancelled
update readme TOC / update readme TOC (push) Has been cancelled
Tests on Windows: `nvm install` / MSYS nvm install (--default 12) (push) Has been cancelled
Tests on Windows: `nvm install` / MSYS nvm install (--lts) (push) Has been cancelled
Tests on Windows: `nvm install` / MSYS nvm install (--no-progress 10) (push) Has been cancelled
Tests on Windows: `nvm install` / Cygwin nvm install (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 10, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 10, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 12, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 12, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 14, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 14, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 16, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 16, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 18, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 18, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 21, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 21, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-18.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Debian) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Ubuntu-20.04) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, --lts, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 10, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 11, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 12, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 14, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 16, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 18, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (, 21, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, --lts, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 10, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 11, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 12, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 16, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 18, Alpine) (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 21, Alpine) (push) Has been cancelled
Tests: nvm install with set -e / test (push) Has been cancelled
Tests: nvm install with set -e / finisher (push) Has been cancelled
Tests: `nvm install-latest-npm` / nvm install-latest-npm (push) Has been cancelled
Tests: linting / all linting (push) Has been cancelled
Tests: shellcheck / shellcheck (push) Has been cancelled
Tests: fast / all fast tests (push) Has been cancelled
Tests: installation_iojs / all installation_iojs tests (push) Has been cancelled
Tests: xenial / all xenial tests (push) Has been cancelled
urchin tests / all test suites, all shells (push) Has been cancelled
Tests on Windows: `nvm install` / tests, on windows (push) Has been cancelled
urchin tests / tests (bash, installation_iojs) (push) Has been cancelled
Tests: shellcheck / shellcheck_matrix (nvm.sh, sh) (push) Has been cancelled
Tests: installation_node / installation_node (sh, without curl) (push) Has been cancelled
urchin tests / tests (dash, slow) (push) Has been cancelled
Tests on Windows: `nvm install` / MSYS fail prefix nvm install (push) Has been cancelled
Tests on Windows: `nvm install` / WSL nvm install (script, 14, Debian) (push) Has been cancelled
Tests: installation_node / all installation_node tests (push) Has been cancelled
The lowercase check was in the `*` catch-all branch of the `case` statement, rejecting any alias name with uppercase characters.
This prevented creating or reading uppercase aliases like `TESTY`.
The check should only apply to `lts/*` patterns, since LTS codenames are always lowercase.
Fixes #3764 .
Bug introduced in https://github.com/nvm-sh/nvm/commit/9fb9dec710e2c8d3aecb24c2a7c9f9fb45b1435b as part of fixing #3417 .
2026-03-26 10:18:40 -07:00
Jordan Harband
d2fca5f0ec
[Fix] nvm_resolve_local_alias: avoid using variable as printf format string
...
Using a variable as the format string means `%` characters in alias names would be interpreted as format specifiers.
Use `%b` format with the variable as an argument to safely interpret `\n` escapes.
Bug introduced in https://github.com/nvm-sh/nvm/commit/9b91734f0b6a210f0c6655b0cd25ea288d9ae376 .
2026-03-14 10:16:25 -07:00
Jordan Harband
a27a8b7da8
[Fix] nvm alias: fix colors not showing by default
...
Colors were lost because `nvm_has_colors` checks `[ -t 1 ]`, which is false inside the `(...) | sort` pipeline in `nvm_list_aliases`.
Evaluate `nvm_has_colors` before the pipe and propagate via `NVM_HAS_COLORS`, matching the approach used by `nvm_print_versions`.
Bug introduced in https://github.com/nvm-sh/nvm/commit/35212c134652197c779dffd42b9567a270355987 .
2026-03-13 16:13:41 -04:00
Jordan Harband
14d01c6877
[Tests] add try/try_err helpers; convert tests to use them
...
Add `try` and `try_err` helper functions to `test/common.sh` that capture stdout/stderr and exit code from a single invocation, eliminating duplicate command executions in tests.
Convert all existing tests that used the `OUTPUT`/`EXIT_CODE` double-invocation pattern to use the new helpers.
Also fixes a pre-existing bug in the `nvm_die_on_prefix` test where ASCII apostrophes were used instead of U+2019 to match nvm.sh output.
2026-03-13 15:26:07 -04:00
Jordan Harband
35212c1346
[Fix] nvm_has_colors: also check if stdout is a terminal
2026-01-27 10:31:07 -08:00
Jordan Harband
c451e7a4c8
[Tests] set $_ before sourcing nvm.sh in fast tests
...
nvm.sh uses `NVM_SCRIPT_SOURCE="$_"` to detect its source location.
Adding `: nvm.sh` before each source line ensures `$_` is set correctly, preventing breakage when the previous command (e.g., `set -ex`) overwrites it.
2026-01-26 21:41:57 -08:00
Jordan Harband and Yash Singh
29dce5edfd
[New] allow .nvmrc files to support comments
...
In theory, `npx nvmrc` can now be used to validate an `.nvmrc` file that `nvm` will support. Allowances have been made for future extensibility, and aliases may no longer contain a `#`.
Fixes #3336 . Closes #2288 .
Co-authored-by: Jordan Harband <ljharb@gmail.com >
Co-authored-by: Yash Singh <saiansh2525@gmail.com >
2024-06-07 10:13:00 -07:00
Jordan Harband
6743aef70c
[New] nvm_resolve_alias: only resolve one line of a multiline alias file
2023-10-23 14:41:14 -07:00
Jordan Harband
8241287349
[New] aliases: skip leading blank lines in alias file
2023-10-23 14:06:19 -07:00
Jordan Harband
ce35311657
[Tests] force the NVM_DIR to the expected location, for tests
2022-12-27 21:40:48 -08:00
Jordan Harband
4c4b0d64ed
[Tests] fix nvm_list_aliases test to use mocks for LTS aliases
2022-10-26 10:31:26 -07:00
Jordan Harband
5cc74a6736
[Tests] fix failing test
2021-12-17 13:21:29 -08:00
Jordan Harband
430860a8be
[Fix] nvm alias/nvm_list_aliases: support lts/ aliases
...
See #2692
2021-12-16 15:54:38 -08:00
Jordan Harband
5b77f7d023
[Fix] nvm ls/nvm alias/nvm_list_aliases: zsh: when no LTS aliases, no error
...
Fixes #2575 .
2021-09-01 10:06:32 -07:00
nmarghetti and Jordan Harband
9849bf494d
[meta] Rename some files to be more cross platform
2021-01-04 00:49:05 +01:00
6848c16d53
[New] Added set-colors command. See details below:
...
This command allows users to replace default colors with their own custom colors.
- top-level commands modified: alias, ls, ls-remote
- helper functions added: nvm_echo_with_colors, nvm_err_with_colors,
nvm_set_colors, nvm_get_colors, nvm_print_color_code
- functions modified: nvm_print_formatted_alias, nvm_print_versions, nvm_print_alias_path (implicitly), nvm_print_default_alias (implicitly), nvm_list_aliases (implicitly)
We added tests and info on using this command to the README!
Co-authored-by: Dena Burd <29719099+gitburd@users.noreply.github.com >
Co-authored-by: Naomi Quinones <52065567+naomiquinones@users.noreply.github.com >
2020-08-17 14:56:13 -07:00
Jordan Harband
73a513c389
[Fix] allow nvm unalias x when x is a default alias, but shadowed
...
Fixes #2122 .
2019-11-12 11:16:08 -08:00
Lucas Kellner and Jordan Harband
02997b0753
[Docs] unalias: add more specific error message for builtin aliases
2019-01-23 16:39:57 -08:00
Joshua Li and Jordan Harband
0cdc184168
[Fix] Improve nvm_is_version_installed to check for a node executable instead of root dir
2018-05-31 15:26:30 -07:00
Joshua Li and Jordan Harband
a5f42d9cea
[Tests] update most mkdirs to use make_fake_{node,iojs}
2018-06-13 10:38:19 -07:00
Peter Dave Hello
2cd2c0f72e
Remove useless trailing newlines
2018-02-26 01:01:30 +08:00
Peter Dave Hello and Jordan Harband
c6866eeb37
[Test] "nvm alias" lts test bug fix
2017-04-02 14:34:04 +08:00
Peter Dave Hello and Jordan Harband
f7763c8ba9
[Tests] die() in tests should quote "$@" for echo
2016-11-07 03:34:36 +08:00
Qiangjun Ran and Jordan Harband
cadbbced20
[Tests] Replace all dots with backslash dots
2016-11-03 23:44:59 -07:00
Jordan Harband
f0668fd577
[Tests] nvm alias --lts: add tests
2016-06-26 15:11:37 -07:00
Jordan Harband
73aa35f508
[Tests] use $NVM_DIR instead of relative paths
2016-06-26 15:52:26 -07:00
Jordan Harband
eeaddf9ab0
Don’t restrict colors to TTYs.
...
This restriction prevents subcommands from producing colors and passing them up the tree to the actual TTY.
2016-05-08 21:24:24 -07:00
Jordan Harband
379d079c30
[Tests] Ensure color codes are stripped in alias tests.
2016-04-27 17:05:33 -07:00
Jordan Harband
677c69dda0
nvm alias: explicitly forbid user aliases in subdirs.
2016-04-26 23:07:10 -07:00
Jordan Harband
3d764e6833
Add nvm_ensure_default_set
2015-04-05 16:49:29 -07:00
Jordan Harband
2b63f37f8d
Make nvm_resolve_local_alias not return N/A - that should be done as shallowly as possible.
2015-03-14 10:55:31 -07:00
Jordan Harband
7d22e0c458
Separate nvm_resolve_alias's nvm_version behavior into nvm_resolve_local_alias.
2015-02-21 16:10:42 -08:00
Jordan Harband
3190effedd
Add support for node and iojs implicit aliases.
2015-02-10 23:43:47 -08:00
Tobias Witt
cba5094652
Provide test case for testing the noclobber option from zsh
...
This tests the absence of the bug from #615
2015-01-23 09:29:13 +01:00
Jordan Harband
9b91734f0b
Show "∞" when there's a circular alias reference.
2014-10-22 18:15:21 -07:00
Jordan Harband
7a339bdd3c
Adding nvm_resolve_alias
2014-10-22 01:30:40 -07:00
Jordan Harband
08aa09e664
Prevent test pollution.
2014-10-22 01:26:39 -07:00
Jordan Harband
8f76b35370
Fix nvm alias tests to have both stable and unstable mocks.
2014-10-10 23:46:25 -04:00
Jordan Harband
5dc7af6285
Make nvm alias list implicit "stable" and "unstable" aliases when they're not already aliases.
2014-09-29 00:09:17 -07:00
Jordan Harband
fda05fb64b
Remove trailing whitespace.
2014-09-29 14:26:19 -07:00
Jordan Harband
3c66c20570
Improving "nvm alias" tests to test for all cases.
2014-09-28 10:07:50 -07:00
Jordan Harband
59bfdb9863
Making sure fast alias tests do their own teardown.
2014-09-28 09:54:35 -07:00
Thomas Levine
a27d39139b
tests from readme
...
fast tests
alias
unalias
more alias tests
tests
document testing
warn not to run while testing
chmod +x deactivate
specify the version (commit) of urchin
installation test
run
tests for ls
switch unsetopt to the thing creationix has
rename tests
urchin log
adjust urchin version
2012-10-11 16:12:50 -04:00