Compare commits

...

4 Commits

Author SHA1 Message Date
Charlie Hileman
898c9c6fab
Merge cf9beb7f86ba3c806108ee79fe2f9fae26171219 into 99352a64d25ce27d49ff6a449663ce3d7c12e5b5 2025-04-10 13:19:54 -07:00
Toni Viemerö
99352a64d2
[Fix] nvm_install_latest_npm: fix node version detection 2025-04-09 08:16:05 +03:00
Jordan Harband
cf9beb7f86
[Tests] add some WIP tests 2020-01-12 13:29:35 -08:00
Charlie Hileman
9222739d18
[Fix] nvm_tree_contains_path: handle symbolic links
Co-Authored-By: Charlie Hileman <aiquicorp@gmail.com>
Co-Authored-By: Jordan Harband <ljharb@gmail.com>
2020-01-08 12:06:49 -05:00
2 changed files with 19 additions and 7 deletions

20
nvm.sh
View File

@ -356,19 +356,19 @@ nvm_install_latest_npm() {
if [ $NVM_IS_19_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.5.0; then if [ $NVM_IS_19_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.5.0; then
NVM_IS_20_5_OR_ABOVE=1 NVM_IS_20_5_OR_ABOVE=1
fi fi
local NVM_IS_20_17_or_ABOVE local NVM_IS_20_17_OR_ABOVE
NVM_IS_20_17_or_ABOVE=0 NVM_IS_20_17_OR_ABOVE=0
if [ $NVM_IS_20_5_OR_ABOVE -eq 1 ] && nvm_version_greater 20.17.0 "${NODE_VERSION}"; then if [ $NVM_IS_20_5_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 20.17.0; then
NVM_IS_20_17_or_ABOVE=1 NVM_IS_20_17_OR_ABOVE=1
fi fi
local NVM_IS_21_OR_ABOVE local NVM_IS_21_OR_ABOVE
NVM_IS_21_OR_ABOVE=0 NVM_IS_21_OR_ABOVE=0
if [ $NVM_IS_20_17_or_ABOVE -eq 1 ] && nvm_version_greater 21.0.0 "${NODE_VERSION}"; then if [ $NVM_IS_20_17_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 21.0.0; then
NVM_IS_21_OR_ABOVE=1 NVM_IS_21_OR_ABOVE=1
fi fi
local NVM_IS_22_9_OR_ABOVE local NVM_IS_22_9_OR_ABOVE
NVM_IS_22_9_OR_ABOVE=0 NVM_IS_22_9_OR_ABOVE=0
if [ $NVM_IS_21_OR_ABOVE -eq 1 ] && nvm_version_greater 22.9.0 "${NODE_VERSION}"; then if [ $NVM_IS_21_OR_ABOVE -eq 1 ] && nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 22.9.0; then
NVM_IS_22_9_OR_ABOVE=1 NVM_IS_22_9_OR_ABOVE=1
fi fi
@ -420,7 +420,7 @@ nvm_install_latest_npm() {
nvm_echo '* `npm` `v9.x` is the last version that works on `node` `< v18.17`, `v19`, or `v20.0` - `v20.4`' nvm_echo '* `npm` `v9.x` is the last version that works on `node` `< v18.17`, `v19`, or `v20.0` - `v20.4`'
$NVM_NPM_CMD install -g npm@9 $NVM_NPM_CMD install -g npm@9
elif \ elif \
[ $NVM_IS_20_17_or_ABOVE -eq 0 ] \ [ $NVM_IS_20_17_OR_ABOVE -eq 0 ] \
|| { [ $NVM_IS_21_OR_ABOVE -eq 1 ] && [ $NVM_IS_22_9_OR_ABOVE -eq 0 ]; } \ || { [ $NVM_IS_21_OR_ABOVE -eq 1 ] && [ $NVM_IS_22_9_OR_ABOVE -eq 0 ]; } \
; then ; then
nvm_echo '* `npm` `v10.x` is the last version that works on `node` `< v20.17`, `v21`, or `v22.0` - `v22.8`' nvm_echo '* `npm` `v10.x` is the last version that works on `node` `< v20.17`, `v21`, or `v22.0` - `v22.8`'
@ -478,6 +478,12 @@ nvm_tree_contains_path() {
previous_pathdir="${node_path}" previous_pathdir="${node_path}"
local pathdir local pathdir
pathdir=$(dirname "${previous_pathdir}") pathdir=$(dirname "${previous_pathdir}")
# get real directory in case of symbolic links
if [ -d "${pathdir-}" ]; then
pathdir="$(nvm_cd -P "${pathdir}" && pwd)"
fi
while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] && while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do [ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
previous_pathdir="${pathdir}" previous_pathdir="${pathdir}"

View File

@ -1,6 +1,8 @@
#!/bin/sh #!/bin/sh
cleanup () { cleanup () {
rm tmp3/tmp2
rmdir tmp3
rm tmp/node rm tmp/node
rmdir tmp rmdir tmp
rm tmp2/node rm tmp2/node
@ -14,6 +16,8 @@ mkdir -p tmp
touch tmp/node touch tmp/node
mkdir -p tmp2 mkdir -p tmp2
touch tmp2/node touch tmp2/node
mkdir -p tmp3
ln -s tmp2 tmp3/
[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args' [ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args'
[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args' [ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args'
@ -28,4 +32,6 @@ nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'
nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"' nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'
nvm_tree_contains_path tmp2 tmp3 && die 'no idea'
cleanup cleanup