Compare commits

...

4 Commits

7 changed files with 75 additions and 18 deletions

View File

@ -207,7 +207,7 @@ If you're running a system without prepackaged binary available, which means you
- [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell - [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup - [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell - [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
- [fnm](https://github.com/fisherman/fnm) - [fisherman](https://github.com/fisherman/fisherman)-based version manager for fish - [nvm.fish](https://github.com/jorgebucaran/nvm.fish) - Node.js version manager lovingly made for Fish
- [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used. - [fish-nvm](https://github.com/FabioAntunes/fish-nvm) - Wrapper around nvm for fish, delays sourcing nvm until it's actually used.
**Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket: **Note:** We still have some problems with FreeBSD, because there is no official pre-built binary for FreeBSD, and building from source may need [patches](https://www.freshports.org/www/node/files/patch-deps_v8_src_base_platform_platform-posix.cc); see the issue ticket:

21
nvm.sh
View File

@ -891,6 +891,10 @@ nvm_normalize_lts() {
fi fi
;; ;;
*) *)
if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then
nvm_err 'LTS names must be lowercase'
return 3
fi
nvm_echo "${LTS}" nvm_echo "${LTS}"
;; ;;
esac esac
@ -1249,7 +1253,9 @@ nvm_alias() {
nvm_err 'An alias is required.' nvm_err 'An alias is required.'
return 1 return 1
fi fi
ALIAS="$(nvm_normalize_lts "${ALIAS}")" if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then
return $?
fi
if [ -z "${ALIAS}" ]; then if [ -z "${ALIAS}" ]; then
return 2 return 2
@ -1652,7 +1658,9 @@ $VERSION_LIST
EOF EOF
if [ -n "${LTS-}" ]; then if [ -n "${LTS-}" ]; then
LTS="$(nvm_normalize_lts "lts/${LTS}")" if ! LTS="$(nvm_normalize_lts "lts/${LTS}")"; then
return $?
fi
LTS="${LTS#lts/}" LTS="${LTS#lts/}"
fi fi
@ -3417,9 +3425,11 @@ nvm() {
;; ;;
esac esac
local EXIT_CODE
VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")" VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")"
EXIT_CODE="$?"
if [ "${VERSION}" = 'N/A' ]; then if [ "${VERSION}" = 'N/A' ] || [ $EXIT_CODE -ne 0 ]; then
local LTS_MSG local LTS_MSG
local REMOTE_CMD local REMOTE_CMD
if [ "${LTS-}" = '*' ]; then if [ "${LTS-}" = '*' ]; then
@ -3428,6 +3438,10 @@ nvm() {
elif [ -n "${LTS-}" ]; then elif [ -n "${LTS-}" ]; then
LTS_MSG="(with LTS filter '${LTS}') " LTS_MSG="(with LTS filter '${LTS}') "
REMOTE_CMD="nvm ls-remote --lts=${LTS}" REMOTE_CMD="nvm ls-remote --lts=${LTS}"
if [ -z "${provided_version}" ]; then
nvm_err "Version with LTS filter '${LTS}' not found - try \`${REMOTE_CMD}\` to browse available versions."
return 3
fi
else else
REMOTE_CMD='nvm ls-remote' REMOTE_CMD='nvm ls-remote'
fi fi
@ -3492,7 +3506,6 @@ nvm() {
FLAVOR="$(nvm_node_prefix)" FLAVOR="$(nvm_node_prefix)"
fi fi
local EXIT_CODE
EXIT_CODE=0 EXIT_CODE=0
if nvm_is_version_installed "${VERSION}"; then if nvm_is_version_installed "${VERSION}"; then

View File

@ -0,0 +1,35 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
nvm_download() {
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
cat "${REMOTE}"
elif [ "$*" = "-L -s $(nvm_get_mirror iojs)/index.tab -o -" ]; then
cat "${REMOTE_IOJS}"
else
nvm_err "unknown nvm_download call: $*"
return 42
fi
}
nvm_install_binary() {
return 42
}
nvm_install_source() {
return 42
}
ACTUAL="$(nvm install lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "Expected exit code of 3, got ${EXIT_CODE}"
EXPECTED="LTS names must be lowercase
Version with LTS filter 'ARGON' not found - try \`nvm ls-remote --lts=ARGON\` to browse available versions."
[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"

View File

@ -1,7 +1,5 @@
#!/bin/sh #!/bin/sh
set -e
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
cleanup() { cleanup() {
@ -56,6 +54,14 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
INDEX=$(($INDEX + 1)) INDEX=$(($INDEX + 1))
done done
OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "nvm ls-remote lts/ARGON did not exit 3, got '${EXIT_CODE}'"
EXPECTED_OUTPUT="LTS names must be lowercase
N/A"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt" REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() { nvm_ls_remote() {
cat "${REMOTE}" cat "${REMOTE}"

View File

@ -6,7 +6,7 @@ cleanup () {
nvm cache clear nvm cache clear
nvm deactivate nvm deactivate
rm -rf ${NVM_DIR}/v* rm -rf ${NVM_DIR}/v*
nvm unalias default nvm unalias default || true
} }
die () { >&2 echo "$@" ; cleanup ; exit 1; } die () { >&2 echo "$@" ; cleanup ; exit 1; }

View File

@ -16,6 +16,9 @@ ACTUAL="$(nvm_normalize_lts "lts/*")"
EXPECTED='lts/*' EXPECTED='lts/*'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
if ACTUAL="$(nvm_normalize_lts lts/ARGON)"; then
die "expected failure, got >${ACTUAL}<"
fi
MOCKS_DIR="../Unit tests/mocks" MOCKS_DIR="../Unit tests/mocks"
STAR="$(cat "$MOCKS_DIR/lts-star.txt")" STAR="$(cat "$MOCKS_DIR/lts-star.txt")"

View File

@ -9,20 +9,20 @@ die () { echo "$@" ; exit 1; }
nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default' nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default'
set +ex # needed for stderr set +ex # needed for stderr
OUTPUT="$(nvm install --lts 3 2>&1)" OUTPUT="$(nvm install --lts 0.12 2>&1)"
EXIT_CODE="$?"
set -ex set -ex
EXIT_CODE="$(nvm install --lts 3 >/dev/null 2>&1 && echo $? || echo $?)" EXPECTED_OUTPUT="Version '0.12' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
EXPECTED_OUTPUT="Version '3' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions." [ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 0.12\` did not exit with 3, got >${EXIT_CODE}<"
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 3\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
set +ex # needed for stderr set +ex # needed for stderr
OUTPUT="$(nvm install --lts=argon 3 2>&1)" OUTPUT="$(nvm install --lts=argon 0.12 2>&1)"
set -ex EXIT_CODE="$?"
EXIT_CODE="$(nvm install --lts=argon 3 >/dev/null 2>&1 && echo $? || echo $?)" set -x
EXPECTED_OUTPUT="Version '3' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions." EXPECTED_OUTPUT="Version '0.12' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 3\` did not exit with 3, got >${EXIT_CODE}<" [ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 0.12\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 0.12\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed' nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed'