[Fix] install.sh: update from nvm's remote; nvm_ls: list versions without globs; nvm_ensure_version_installed: do not leak VERSION
`install.sh`: an existing install now fetches from the remote whose URL is nvm's source, adding one when none matches, instead of always fetching `origin`; fresh installs still name it `origin`. The remote's URL is read with `git config`, since `git remote get-url` needs git 2.7. `nvm_ls`: `find` lists each version directory's non-hidden subdirectories itself, so it works under `set -f`, which disables the globs it was given; the directories only need to exist. `nvm_ensure_version_installed`: the resolved alias was assigned to `VERSION` without declaring it local. Co-authored-by: dajiaohuang <mikewushuwen@outlook.com> Co-authored-by: Jordan Harband <ljharb@gmail.com>
This commit is contained in:
1 parent
a4fadf1eae
commit
dbda4b9387
6 files changed
+109
-64
No files matched your search
@@ -1,38 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
cleanup() {
|
||||
rm -rf "${TEST_DIR}"
|
||||
}
|
||||
|
||||
die() {
|
||||
echo "$@"
|
||||
cleanup
|
||||
exit 1
|
||||
}
|
||||
|
||||
: nvm.sh
|
||||
\. ../../../nvm.sh
|
||||
|
||||
TEST_DIR="$(mktemp -d)"
|
||||
|
||||
# glob characters and a space in the path are matched literally
|
||||
DIR="${TEST_DIR}/a [b] *"
|
||||
|
||||
! nvm_dir_has_entries "${DIR}" || die 'a missing directory has no entries'
|
||||
|
||||
mkdir "${DIR}"
|
||||
! nvm_dir_has_entries "${DIR}" || die 'an empty directory has no entries'
|
||||
|
||||
touch "${DIR}/.hidden"
|
||||
! nvm_dir_has_entries "${DIR}" || die 'a directory with only dotfiles has no entries, as with `ls`'
|
||||
|
||||
ln -s "${TEST_DIR}/nonexistent" "${DIR}/broken"
|
||||
nvm_dir_has_entries "${DIR}" || die 'a broken symlink is an entry'
|
||||
rm "${DIR}/broken"
|
||||
|
||||
mkdir "${DIR}/v1.0.0"
|
||||
nvm_dir_has_entries "${DIR}" || die 'a directory with a subdirectory has entries'
|
||||
|
||||
! nvm_dir_has_entries "${TEST_DIR}/a [b] " || die 'the directory name is not a pattern'
|
||||
|
||||
cleanup
|
||||
@@ -70,4 +70,12 @@ EXPECTED_OUTPUT=''
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to give $EXPECTED_OUTPUT, got $OUTPUT"
|
||||
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to exit with 0, got $EXIT_CODE"
|
||||
|
||||
# An unresolved installed-version check must not overwrite a caller's VERSION.
|
||||
VERSION='caller-value'
|
||||
nvm_resolve_alias() { [ "_${1-}" = '_nonexistent' ] || return 2; nvm_echo 'v123.4.5'; }
|
||||
nvm_ensure_version_installed nonexistent >/dev/null 2>&1 && die 'expected missing version failure'
|
||||
[ "${VERSION}" = 'caller-value' ] || die "VERSION leaked: ${VERSION}"
|
||||
unset -f nvm_resolve_alias
|
||||
unset VERSION
|
||||
|
||||
cleanup
|
||||
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
|
||||
die() { echo "$*" >&2; cleanup; exit 1; }
|
||||
cleanup() { rm -rf "${TEST_DIR}"; }
|
||||
|
||||
\. ../../../nvm.sh --no-use
|
||||
\. ../../common.sh
|
||||
|
||||
TEST_DIR="${PWD}/nvm_ls_hidden_noglob_tmp"
|
||||
NVM_DIR="${TEST_DIR}"
|
||||
export NVM_DIR
|
||||
mkdir -p "${NVM_DIR}/versions/node/.hidden" "${NVM_DIR}/versions/node/v24.13.0/bin" || die 'could not create fixture'
|
||||
make_echo "${NVM_DIR}/versions/node/v24.13.0/bin/node" 'v24.13.0' || die 'could not create fake node'
|
||||
|
||||
set -f
|
||||
try nvm_ls 24
|
||||
[ "_${CAPTURED_STDOUT}" = '_v24.13.0' ] || die "unexpected output with noglob: ${CAPTURED_STDOUT}"
|
||||
case "$-" in *f*) ;; *) die 'nvm_ls changed noglob';; esac
|
||||
set +f
|
||||
try nvm_ls
|
||||
case "${CAPTURED_STDOUT}" in *.hidden*) die "expected hidden entries to be skipped; got ${CAPTURED_STDOUT}" ;; esac
|
||||
rm -rf "${NVM_DIR}/versions/node/v24.13.0"
|
||||
try nvm_ls 24
|
||||
[ "_${CAPTURED_STDERR}" = '_' ] || die "unexpected error for hidden-only directory: ${CAPTURED_STDERR}"
|
||||
cleanup
|
||||
Reference in new issue
Block a user