Files
nvm/nvm-exec
T
Jordan Harband 39fca6c905 [Fix] nvm use, nvm-exec: stop option parsing at --
`nvm use` treated `--` as a no-op and kept parsing options after it,
so `nvm use -- -w` enabled `--save`,
fell back to `.nvmrc`,
and rewrote it with the resolved version;
`--delete-prefix` and unknown `--*` arguments after
`--` were likewise acted on or silently dropped.

Now the argument after `--` is taken as the version and option parsing stops there;
a lone `--` still falls back to `.nvmrc`.
`nvm-exec` now passes `NODE_VERSION` after `--`,
so its value is always treated as a version and never as an option

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-4RO8S9N0; the scanner correctly classified it as not a vulnerability.
2026-10-22 20:10:42 -07:00

23 lines
613 B
Bash
Executable File

#!/usr/bin/env bash
DIR="$(command cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
unset NVM_CD_FLAGS
# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use
if [ -n "$NODE_VERSION" ]; then
nvm use -- "$NODE_VERSION" > /dev/null || exit 127
else
{ NVM_RC_VERSION="$(nvm_rc_version 3>&1 1>&4)"; } 4>&1 && nvm_ensure_version_installed "$NVM_RC_VERSION";
if ! nvm use >/dev/null 2>&1; then
nvm_err 'nvm-exec: unable to select a node version'
# shellcheck disable=SC2016
nvm_err ' Set `NODE_VERSION` (e.g. `NODE_VERSION=default`), or add an `.nvmrc` file.'
exit 127
fi
fi
exec "$@"