File tree 1 file changed +9
-8
lines changed
1 file changed +9
-8
lines changed Original file line number Diff line number Diff line change @@ -457,17 +457,18 @@ cdnvm(){
457
457
declare nvm_version
458
458
nvm_version= $( < " $nvm_path " /.nvmrc)
459
459
460
- # Add the `v` suffix if it does not exists in the .nvmrc file
461
- if [[ $nvm_version != v* && $nvm_version != lts/* && $nvm_version != iojs* && $nvm_version != node && $nvm_version != system && $nvm_version != stable && $nvm_version != default ]]; then
462
- nvm_version=" v" " $nvm_version "
463
- fi
460
+ declare locally_resolved_nvm_version
461
+ # `nvm ls` will check all locally-available versions
462
+ # If there are multiple matching versions, take the latest one
463
+ # Remove the `->` and `*` characters and spaces
464
+ # `locally_resolved_nvm_version` will be `N/A` if no local versions are found
465
+ locally_resolved_nvm_version= $( nvm ls --no-colors $( < " ./.nvmrc" ) | tail -1 | tr -d ' \->*' | tr -d ' [:space:]' )
464
466
465
467
# If it is not already installed, install it
466
- if [[ $( nvm ls " $nvm_version " | tr -d ' [:space:]' ) == " N/A" ]]; then
468
+ # `nvm install` will implicitly use the newly-installed version
469
+ if [[ " $locally_resolved_nvm_version " == " N/A" ]]; then
467
470
nvm install " $nvm_version " ;
468
- fi
469
-
470
- if [[ $( nvm current) != " $nvm_version " ]]; then
471
+ elif [[ $( nvm current) != " $locally_resolved_nvm_version " ]]; then
471
472
nvm use " $nvm_version " ;
472
473
fi
473
474
fi
You can’t perform that action at this time.
0 commit comments