Skip to content
Myr

[Fix] `use`: Prepend instead of changing if shadowed by system dirs (fixes #1652)

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

authored by Xandor Schiefer · committed by Jordan Harband · parent 0cdc184 · Browse files · 2 files+23 added−2 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+23 added−2 removed

  • tests:+14 added−0 removed
  • other:+9 added−2 removed

2 files+23 added−2 removed

modified:test/fast/Unit tests/nvm_change_path+14 added
39 unmodified lines
40# Old version dir41NEW_PATH=`nvm_change_path "$EMPTY_PATH" "/bin" "$NVM_DIR/v0.1.2"`4243[ "$NEW_PATH" = "$NVM_DIR/v0.1.2/bin" ] || die "Not correctly prepended: $NEW_PATH "444546# https://github.com/creationix/nvm/issues/1652#issuecomment-34257122347MAC_OS_NESTED_SESSION_PATH=/usr/bin:/usr/local/bin:$NVM_DIR/versions/node/v4.5.0/bin4849# New version dir50NEW_PATH=`nvm_change_path "$MAC_OS_NESTED_SESSION_PATH" "/bin" "$NVM_DIR/versions/node/v7.1.0"`5152[ "$NEW_PATH" = "$NVM_DIR/versions/node/v7.1.0/bin:/usr/bin:/usr/local/bin:$NVM_DIR/versions/node/v4.5.0/bin" ] || die "Not correctly changed: $NEW_PATH "5354# Old version dir55NEW_PATH=`nvm_change_path "$MAC_OS_NESTED_SESSION_PATH" "/bin" "$NVM_DIR/v0.1.2"`5657[ "$NEW_PATH" = "$NVM_DIR/v0.1.2/bin:/usr/bin:/usr/local/bin:$NVM_DIR/versions/node/v4.5.0/bin" ] || die "Not correctly changed: $NEW_PATH "
modified:nvm.sh+9 added-2 removed
636 unmodified lines
637 # path638 elif ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/[^/]*${2-}" \639 && ! nvm_echo "${1-}" | nvm_grep -q "${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then640 nvm_echo "${3-}${2-}:${1-}"641 # if the initial path contains BOTH an nvm path (checked for above) and642 # that nvm path is preceded by a system binary path, just prepend the643 # supplementary path instead of replacing it.644 # https://github.com/creationix/nvm/issues/1652#issuecomment-342571223645 elif nvm_echo "${1-}" | nvm_grep -Eq "(^|:)(/usr(/local)?)?${2-}:.*${NVM_DIR}/[^/]*${2-}" \646 || nvm_echo "${1-}" | nvm_grep -Eq "(^|:)(/usr(/local)?)?${2-}:.*${NVM_DIR}/versions/[^/]*/[^/]*${2-}"; then647 nvm_echo "${3-}${2-}:${1-}"648 # use sed to replace the existing nvm path with the supplementary path. This649 # preserves the order of the path.650 else651 nvm_echo "${1-}" | command sed \645 -e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#g" \646 -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#g"652 -e "s#${NVM_DIR}/[^/]*${2-}[^:]*#${3-}${2-}#" \653 -e "s#${NVM_DIR}/versions/[^/]*/[^/]*${2-}[^:]*#${3-}${2-}#"654 fi655}656657nvm_binary_available() {
3006 unmodified lines