Skip to content
Myr

Merge pull request #382 from koenpunt/version-normalizing

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Fix nvm ls for v* numbers

authored by Jordan Harband · committed by Jordan Harband · parents 625e548, a34c080 · Browse files · 2 files+26 added−17 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+26 added−17 removed

  • tests:+3 added−1 removed
  • other:+23 added−16 removed

2 files+26 added−17 removed

modified:test/fast/Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.+3 added-1 removed
5 unmodified lines
6. ../../../nvm.sh78# The result should contain only the appropriate version numbers.9nvm ls 0.2 | grep v0.2.3 &&10nvm ls 0.1 | grep -v v0.2.310nvm ls 0.1 | grep -v v0.2.3 &&11nvm ls 0.1 | grep v0.1.3 &&12nvm ls v0.2 | grep v0.2.3
modified:nvm.sh+23 added-16 removed
68 unmodified lines
69 return70 fi71}7273nvm_normalize_version() {74 echo "$1" | sed -e 's/^v//' | awk -F. '{ printf("%d%03d%03d\n", $1,$2,$3); }'75}7677nvm_format_version() {78 echo "$1" | sed -e 's/^\([0-9]\)/v\1/g'79}80 81nvm_binary_available() {82 # binaries started with node 0.8.683 local MINIMAL="0.8.6"84 local VERSION=$185 [ $(nvm_normalize_version $VERSION) -ge $(nvm_normalize_version $MINIMAL) ]86}8788nvm_ls() {89 local PATTERN=$190 local VERSIONS=''91 if [ "$PATTERN" = 'current' ]; then
8 unmodified lines
100 # If it looks like an explicit version, don't do anything funny101 if [ `expr "$PATTERN" : "v[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*$"` != 0 ]; then102 VERSIONS="$PATTERN"103 else89 VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "v$PATTERN*" -exec basename '{}' ';' \104 VERSIONS=`find "$NVM_DIR/" -maxdepth 1 -type d -name "$(nvm_format_version $PATTERN)*" -exec basename '{}' ';' \105 | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n`106 fi107 if [ -z "$VERSIONS" ]; then108 echo "N/A"
7 unmodified lines
116 local PATTERN=$1117 local VERSIONS118 local GREP_OPTIONS=''119 if [ -n "$PATTERN" ]; then105 if echo "${PATTERN}" | \grep -v '^v' ; then106 PATTERN=v$PATTERN107 fi120 PATTERN=`nvm_format_version "$PATTERN"`121 else122 PATTERN=".*"123 fi124 VERSIONS=`curl -s $NVM_NODEJS_ORG_MIRROR/ \
154 unmodified lines
279 # skip binary install if no binary option specified.280 if [ $nobinary -ne 1 ]; then281 # shortcut - try the binary if possible.282 if [ -n "$os" ]; then270 binavail=271 # binaries started with node 0.8.6272 case "$VERSION" in273 v0.8.[012345]) binavail=0 ;;274 v0.[1234567].*) binavail=0 ;;275 *) binavail=1 ;;276 esac277 if [ $binavail -eq 1 ]; then283 if nvm_binary_available "$VERSION"; then284 t="$VERSION-$os-$arch"285 url="$NVM_NODEJS_ORG_MIRROR/$VERSION/node-${t}.tar.gz"286 sum=`curl -s $NVM_NODEJS_ORG_MIRROR/$VERSION/SHASUMS.txt | \grep node-${t}.tar.gz | awk '{print $1}'`287 local tmpdir="$NVM_DIR/bin/node-${t}"
68 unmodified lines
356 fi357 ;;358 "uninstall" )359 [ $# -ne 2 ] && nvm help && return360 PATTERN=`nvm_format_version $2`354 if [ "$2" = `nvm_version` ]; then355 echo "nvm: Cannot uninstall currently-active node version, $2."361 if [[ $PATTERN == `nvm_version` ]]; then362 echo "nvm: Cannot uninstall currently-active node version, $PATTERN."363 return 1364 fi358 VERSION=`nvm_version $2`359 if [ ! -d "$NVM_DIR/$VERSION" ]; then365 VERSION=`nvm_version $PATTERN`366 if [ ! -d $NVM_DIR/$VERSION ]; then367 echo "$VERSION version is not installed..."368 return;369 fi370
196 unmodified lines