diff --git a/nvm.sh b/nvm.sh index 6e33c55b..d5c0826b 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3163,21 +3163,28 @@ nvm_cache_dir() { nvm_ls_cached() { local PATTERN PATTERN="${1-}" - local CACHE_BIN_DIR - CACHE_BIN_DIR="$(nvm_cache_dir)/bin" - if [ ! -d "${CACHE_BIN_DIR}" ]; then - return - fi + local NVM_CACHE_DIR + NVM_CACHE_DIR="$(nvm_cache_dir)" local NVM_OS NVM_OS="$(nvm_get_os)" local NVM_ARCH NVM_ARCH="$(nvm_get_arch)" local SUFFIX SUFFIX="${NVM_OS}-${NVM_ARCH}" - # shellcheck disable=SC2010 - command ls -1 "${CACHE_BIN_DIR}" \ - | nvm_grep "^node-v.*-${SUFFIX}\$" \ - | command sed "s/^node-\\(v[0-9][0-9.]*\\)-${SUFFIX}\$/\\1/" \ + { + if [ -d "${NVM_CACHE_DIR}/bin" ]; then + # shellcheck disable=SC2010 + command ls -1 "${NVM_CACHE_DIR}/bin" \ + | nvm_grep "^\\(node\\|iojs\\)-v[0-9][0-9.]*-${SUFFIX}\$" \ + | command sed "s/-${SUFFIX}\$//" + fi + if [ -d "${NVM_CACHE_DIR}/src" ]; then + # shellcheck disable=SC2010 + command ls -1 "${NVM_CACHE_DIR}/src" \ + | nvm_grep "^\\(node\\|iojs\\)-v[0-9][0-9.]*\$" + fi + } \ + | command sed 's/^node-//' \ | nvm_grep "$(nvm_ensure_version_prefix "${PATTERN}")" \ | command sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n } diff --git a/test/fast/Unit tests/nvm_offline_version b/test/fast/Unit tests/nvm_offline_version index 42b82d0b..4ca6e97f 100755 --- a/test/fast/Unit tests/nvm_offline_version +++ b/test/fast/Unit tests/nvm_offline_version @@ -40,9 +40,7 @@ try nvm_ls_cached "999.999" [ -z "$CAPTURED_STDOUT" ] \ || die "nvm_ls_cached '999.999' should return empty; got '$CAPTURED_STDOUT'" -# nvm_ls_cached can currently only see bin-cached node artifacts: bin-cached -# io.js, and src-cached anything, are invisible to it - and thus to -# `--offline` version resolution +# nvm_ls_cached should list bin- and src-cached artifacts, for node and io.js CACHE_DIR="$(nvm_cache_dir)" SUFFIX="$(nvm_get_os)-$(nvm_get_arch)" mkdir -p "${CACHE_DIR}/bin/node-v0.99.98-${SUFFIX}" "${CACHE_DIR}/bin/iojs-v0.99.97-${SUFFIX}" \ @@ -53,22 +51,22 @@ try nvm_ls_cached "v0.99.98" || die "nvm_ls_cached 'v0.99.98' should find the bin-cached node version; got '$CAPTURED_STDOUT'" try nvm_ls_cached "iojs-v0.99.97" -[ -z "$CAPTURED_STDOUT" ] \ - || die "nvm_ls_cached 'iojs-v0.99.97' should not see the bin-cached io.js version; got '$CAPTURED_STDOUT'" +[ "_$CAPTURED_STDOUT" = "_iojs-v0.99.97" ] \ + || die "nvm_ls_cached 'iojs-v0.99.97' should find the bin-cached io.js version; got '$CAPTURED_STDOUT'" try nvm_ls_cached "v0.99.96" -[ -z "$CAPTURED_STDOUT" ] \ - || die "nvm_ls_cached 'v0.99.96' should not see the src-cached node version; got '$CAPTURED_STDOUT'" +[ "_$CAPTURED_STDOUT" = "_v0.99.96" ] \ + || die "nvm_ls_cached 'v0.99.96' should find the src-cached node version; got '$CAPTURED_STDOUT'" try nvm_ls_cached "iojs-v0.99.95" -[ -z "$CAPTURED_STDOUT" ] \ - || die "nvm_ls_cached 'iojs-v0.99.95' should not see the src-cached io.js version; got '$CAPTURED_STDOUT'" +[ "_$CAPTURED_STDOUT" = "_iojs-v0.99.95" ] \ + || die "nvm_ls_cached 'iojs-v0.99.95' should find the src-cached io.js version; got '$CAPTURED_STDOUT'" -# ... and so nvm_offline_version can not resolve them +# ... and nvm_offline_version should resolve them try nvm_offline_version "iojs-v0.99.95" -[ "_$CAPTURED_STDOUT" = "_N/A" ] \ - || die "nvm_offline_version 'iojs-v0.99.95' should not resolve the src-cached io.js version; got '$CAPTURED_STDOUT'" -[ "_$CAPTURED_EXIT_CODE" = "_3" ] \ - || die "nvm_offline_version 'iojs-v0.99.95' should exit 3; got '$CAPTURED_EXIT_CODE'" +[ "_$CAPTURED_STDOUT" = "_iojs-v0.99.95" ] \ + || die "nvm_offline_version 'iojs-v0.99.95' should resolve the src-cached io.js version; got '$CAPTURED_STDOUT'" +[ "_$CAPTURED_EXIT_CODE" = "_0" ] \ + || die "nvm_offline_version 'iojs-v0.99.95' should exit 0; got '$CAPTURED_EXIT_CODE'" cleanup