Add `nvm_ls_remote_iojs` and `nvm ls-remote` support for iojs.

master
Jordan Harband 2015-01-13 02:14:29 -08:00
parent 5143de9653
commit d70f0357f5
2 changed files with 76 additions and 6 deletions

48
nvm.sh
View File

@ -71,6 +71,13 @@ if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then
export NVM_NODEJS_ORG_MIRROR="https://nodejs.org/dist" export NVM_NODEJS_ORG_MIRROR="https://nodejs.org/dist"
fi fi
if [ -z "$NVM_IOJS_ORG_MIRROR" ]; then
export NVM_IOJS_ORG_MIRROR="https://iojs.org/dist"
fi
if [ -z "$NVM_IOJS_ORG_VERSION_LISTING" ]; then
export NVM_IOJS_ORG_VERSION_LISTING="$NVM_IOJS_ORG_MIRROR/index.tab"
fi
nvm_tree_contains_path() { nvm_tree_contains_path() {
local tree local tree
tree="$1" tree="$1"
@ -490,7 +497,28 @@ nvm_ls_remote() {
return 3 return 3
fi fi
echo "$VERSIONS" echo "$VERSIONS"
return }
nvm_ls_remote_iojs() {
local PATTERN
PATTERN="$1"
local VERSIONS
if [ -n "$PATTERN" ]; then
PATTERN="$(nvm_ensure_version_prefix $(nvm_strip_iojs_prefix "$PATTERN"))"
else
PATTERN=".*"
fi
VERSIONS="$(nvm_download -L -s $NVM_IOJS_ORG_VERSION_LISTING -o - \
| command sed 1d \
| command sed "s/^/$(nvm_iojs_prefix)-/" \
| command cut -f1 \
| command grep -w "$PATTERN" \
| command sort)"
if [ -z "$VERSIONS" ]; then
echo "N/A"
return 3
fi
echo "$VERSIONS"
} }
nvm_checksum() { nvm_checksum() {
@ -1083,11 +1111,19 @@ nvm() {
return $NVM_LS_EXIT_CODE return $NVM_LS_EXIT_CODE
;; ;;
"ls-remote" | "list-remote" ) "ls-remote" | "list-remote" )
local NVM_LS_EXIT_CODE local NVM_LS_REMOTE_OUTPUT
NVM_LS_OUTPUT=$(nvm_ls_remote "$2") local NVM_LS_REMOTE_EXIT_CODE
NVM_LS_EXIT_CODE=$? NVM_LS_REMOTE_OUTPUT=$(nvm_ls_remote "$2")
nvm_print_versions "$NVM_LS_OUTPUT" NVM_LS_REMOTE_EXIT_CODE=$?
return $NVM_LS_EXIT_CODE nvm_print_versions "$NVM_LS_REMOTE_OUTPUT"
local NVM_LS_REMOTE_IOJS_OUTPUT
local NVM_LS_REMOTE_IOJS_EXIT_CODE
NVM_LS_REMOTE_IOJS_OUTPUT=$(nvm_ls_remote_iojs "$2")
NVM_LS_REMOTE_IOJS_EXIT_CODE=$?
nvm_print_versions "$NVM_LS_REMOTE_IOJS_OUTPUT"
return $NVM_LS_REMOTE_EXIT_CODE && $NVM_LS_REMOTE_IOJS_EXIT_CODE
;; ;;
"current" ) "current" )
nvm_version current nvm_version current

View File

@ -0,0 +1,34 @@
#!/bin/sh
die () { echo $@ ; cleanup ; exit 1; }
cleanup() {
unset -f nvm_download
}
. ../../../nvm.sh
# sample output at the time the test was written
nvm_download() {
echo 'version date files npm v8 uv zlib openssl modules'
echo 'v1.0.1 2015-01-14 linux-armv7l,linux-x64,linux-x86,osx-x64-tar,win-x64-exe,win-x64-msi,win-x86-exe,win-x86-msi'
echo 'v1.0.0 2015-01-14 linux-armv7l,linux-x64,linux-x86,osx-x64-tar,win-x64-exe,win-x64-msi,win-x86-exe,win-x86-msi'
}
OUTPUT="$(nvm_ls_remote_iojs foo)"
EXIT_CODE="$(nvm_ls_remote_iojs foo >/dev/null 2>&1 ; echo $?)"
[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"
[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"
OUTPUT="$(nvm_ls_remote_iojs)"
EXPECTED_OUTPUT="$(nvm_download | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | sed -e 's/^/iojs-/')"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote_iojs did not output expected sorted versions; got $(echo "$OUTPUT") expected $(echo "$EXPECTED_OUTPUT")"
OUTPUT="$(nvm_ls_remote_iojs 1.0)"
EXPECTED_OUTPUT="iojs-v1.0.0
iojs-v1.0.1"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote_iojs 1.0 did not output 1.0.x versions; got $OUTPUT"
cleanup