Compare commits

..

12 Commits

Author SHA1 Message Date
Jahir Raihan Joy
d04a122e86 Merge 6375e4ed79 into 0d53381666 2024-08-23 17:45:35 +01:00
Jordan Harband
0d53381666 [Tests] move sourcing suite to GHA 2024-08-22 13:30:55 -07:00
Jordan Harband
df70535248 [Fix] nvm_auto: Fix bug introduced in c31a867 2024-08-21 10:54:19 -07:00
Jordan Harband
c31a867c46 [Fix] --save: avoid a conflict with set -e
Fixes #3405.
2024-08-10 15:52:24 +12:00
Jordan Harband
a8c418558a [Refactor] --save: clean up some usage 2024-08-20 16:21:45 -07:00
Jordan Harband
d5e2c92a25 [Fix] nvm_has_colors: avoid an aliased tput
Fixes #3413
2024-08-20 09:23:45 -07:00
Jordan Harband
81f18bc445 [patch] install.sh: fix node capitalization 2024-08-09 13:46:16 +12:00
Jordan Harband
4beab63631 [Fix] declare an unbound variable
Fixes #3402
2024-08-07 17:38:37 +12:00
Jordan Harband
14acd3dcdd [Fix] nvm install -b: do not attempt to download source on a failed binary download with -b
Fixes #3399
2024-08-01 10:35:37 -07:00
Jordan Harband
271720ebfc [Fix] nvm install -b: when no binary is available, fail and output a clear message 2024-08-01 13:57:22 -07:00
Jordan Harband
423ee82b4c [Tests] fix nvm ls-remote unit test 2024-08-01 10:22:28 -07:00
Jahir Raihan Joy
6375e4ed79 converted tree path to canonical form for case-insensitive comp 2024-05-09 16:24:33 +06:00
15 changed files with 289 additions and 92 deletions

104
.github/workflows/nvm-install-test.yml vendored Normal file
View File

@@ -0,0 +1,104 @@
name: 'Tests: nvm install with set -e'
on:
pull_request:
push:
workflow_dispatch:
inputs:
ref:
description: 'git ref to use'
required: false
default: 'HEAD'
jobs:
matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- id: matrix
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.ref }}" ]; then
echo "matrix=\"[\"${{ github.event.inputs.ref }}\"]\"" >> $GITHUB_OUTPUT
else
TAGS="$((echo "HEAD" && git tag --sort=-v:refname --merged HEAD --format='%(refname:strip=2) %(creatordate:short)' | grep '^v' | while read tag date; do
if [ "$(uname)" == "Darwin" ]; then
timestamp=$(date -j -f "%Y-%m-%d" "$date" +%s)
threshold=$(date -j -v-4y +%s)
else
timestamp=$(date -d "$date" +%s)
threshold=$(date -d "4 years ago" +%s)
fi
if [ $timestamp -ge $threshold ]; then echo "$tag"; fi
done) | xargs)"
echo $TAGS
TAGS_JSON=$(printf "%s\n" $TAGS | jq -R . | jq -sc .)
echo "matrix=${TAGS_JSON}" >> $GITHUB_OUTPUT
fi
test:
needs: [matrix]
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.ref == 'v0.40.0' }} # https://github.com/nvm-sh/nvm/issues/3405
strategy:
fail-fast: false
matrix:
ref: ${{ fromJson(needs.matrix.outputs.matrix) }}
has-nvmrc:
- 'no nvmrc'
- 'nvmrc'
shell-level:
- 1 shlvl
- 2 shlvls
steps:
- uses: actions/checkout@v4
- name: resolve HEAD to sha
run: |
if [ '${{ matrix.ref }}' = 'HEAD' ]; then
REF="$(git rev-parse HEAD)"
else
REF="${{ matrix.ref }}"
fi
echo "resolved ref: ${REF}"
echo "ref="$REF"" >> $GITHUB_ENV
- run: echo $- # which options are set
- run: echo node > .nvmrc
if: ${{ matrix.has-nvmrc == 'nvmrc' }}
- run: curl -I --compressed -v https://nodejs.org/dist/
- name: 'install nvm'
run: |
set -e
export NVM_INSTALL_VERSION="${ref}"
curl -o- "https://raw.githubusercontent.com/nvm-sh/nvm/${ref}/install.sh" | bash
- name: nvm --version
run: |
set +e
. $NVM_DIR/nvm.sh && nvm --version
- name: nvm install in 1 shell level, ${{ matrix.has-nvmrc }}
if: ${{ matrix.shell-level == '1 shlvl' }}
run: |
set -ex
. $NVM_DIR/nvm.sh
echo nvm.sh sourced
nvm --version
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
nvm install
fi
- name: nvm install in 2 shell levels, ${{ matrix.has-nvmrc }}
if: ${{ matrix.shell-level == '2 shlvls' }}
run: |
if [ '${{ matrix.has-nvmrc }}' == 'nvmrc' ]; then
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version && nvm install"
else
bash -c "set -ex && . $NVM_DIR/nvm.sh && echo nvm.sh sourced && nvm --version"
fi
finisher:
runs-on: ubuntu-latest
needs: [test]
steps:
- run: true

View File

@@ -19,13 +19,24 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
include: exclude:
- shell: bash - shell: sh
suite: install_script suite: install_script
# shell: - shell: dash
# - bash suite: install_script
# suite: - shell: zsh
# - install_script suite: install_script
- shell: ksh
suite: install_script
suite:
- install_script
- sourcing
shell:
- sh
- bash
- dash
- zsh
# - ksh
steps: steps:
- name: Harden Runner - name: Harden Runner
@@ -37,7 +48,13 @@ jobs:
raw.githubusercontent.com:443 raw.githubusercontent.com:443
nodejs.org:443 nodejs.org:443
iojs.org:443 iojs.org:443
azure.archive.ubuntu.com:80
packages.microsoft.com:443
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- run: sudo apt-get update; sudo apt-get install ${{ matrix.shell }}
if: matrix.shell == 'zsh' || matrix.shell == 'ksh'
# zsh (https://github.com/actions/runner-images/issues/264) and ksh are not in the ubuntu image
shell: bash
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }} - run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: curl --version - run: curl --version
- run: wget --version - run: wget --version
@@ -48,6 +65,7 @@ jobs:
skip-ls-check: true skip-ls-check: true
shell-command: echo installed shell-command: echo installed
- run: npm ls urchin - run: npm ls urchin
- run: npx which urchin
- run: env - run: env
- run: make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }} - run: make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }}

View File

@@ -87,11 +87,6 @@ env:
- SHELL=bash TEST_SUITE=fast - SHELL=bash TEST_SUITE=fast
- SHELL=zsh TEST_SUITE=fast - SHELL=zsh TEST_SUITE=fast
# - SHELL=ksh TEST_SUITE=fast # - SHELL=ksh TEST_SUITE=fast
- SHELL=sh TEST_SUITE=sourcing
- SHELL=dash TEST_SUITE=sourcing
- SHELL=bash TEST_SUITE=sourcing
- SHELL=zsh TEST_SUITE=sourcing
# - SHELL=ksh TEST_SUITE=sourcing
- SHELL=sh TEST_SUITE=slow - SHELL=sh TEST_SUITE=slow
- SHELL=dash TEST_SUITE=slow - SHELL=dash TEST_SUITE=slow
- SHELL=bash TEST_SUITE=slow - SHELL=bash TEST_SUITE=slow

View File

@@ -43,7 +43,7 @@ $(SHELL_TARGETS):
@shell='$@'; shell=$${shell##*-}; \ @shell='$@'; shell=$${shell##*-}; \
which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \ which "$$shell" >/dev/null || { printf '\033[0;31m%s\033[0m\n' "WARNING: Cannot test with shell '$$shell': not found." >&2; exit 0; } && \
printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \ printf '\n\033[0;34m%s\033[0m\n' "Running tests in $$shell"; \
[ -z "$$TRAVIS_BUILD_DIR" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \ [ -z "$$TRAVIS_BUILD_DIR" ] && [ -z "$$GITHUB_ACTIONS" ] && for v in $$(set | awk -F'=' '$$1 ~ "^NVM_" { print $$1 }'); do unset $$v; done && unset v; \
for suite in $(TEST_SUITE); do \ for suite in $(TEST_SUITE); do \
echo "Running test suite: $$suite"; \ echo "Running test suite: $$suite"; \
$(URCHIN) -f -s $$shell test/$$suite || exit; \ $(URCHIN) -f -s $$shell test/$$suite || exit; \

View File

@@ -358,7 +358,7 @@ nvm_check_global_modules() {
command printf %s\\n "$NPM_GLOBAL_MODULES" command printf %s\\n "$NPM_GLOBAL_MODULES"
nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your' nvm_echo '=> If you wish to uninstall them at a later point (or re-install them under your'
# shellcheck disable=SC2016 # shellcheck disable=SC2016
nvm_echo '=> `nvm` Nodes), you can remove them from the system Node as follows:' nvm_echo '=> `nvm` node installs), you can remove them from the system Node as follows:'
nvm_echo nvm_echo
nvm_echo ' $ nvm use system' nvm_echo ' $ nvm use system'
nvm_echo ' $ npm uninstall -g a_module' nvm_echo ' $ npm uninstall -g a_module'

154
nvm.sh
View File

@@ -81,7 +81,7 @@ nvm_command_info() {
nvm_has_colors() { nvm_has_colors() {
local NVM_NUM_COLORS local NVM_NUM_COLORS
if nvm_has tput; then if nvm_has tput; then
NVM_NUM_COLORS="$(tput -T "${TERM:-vt100}" colors)" NVM_NUM_COLORS="$(command tput -T "${TERM:-vt100}" colors)"
fi fi
[ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ] [ "${NVM_NUM_COLORS:--1}" -ge 8 ] && [ "${NVM_NO_COLORS-}" != '--no-colors' ]
} }
@@ -434,6 +434,7 @@ else
fi fi
unset NVM_SCRIPT_SOURCE 2>/dev/null unset NVM_SCRIPT_SOURCE 2>/dev/null
nvm_tree_contains_path() { nvm_tree_contains_path() {
local tree local tree
tree="${1-}" tree="${1-}"
@@ -449,14 +450,21 @@ nvm_tree_contains_path() {
previous_pathdir="${node_path}" previous_pathdir="${node_path}"
local pathdir local pathdir
pathdir=$(dirname "${previous_pathdir}") pathdir=$(dirname "${previous_pathdir}")
# Convert tree path to canonical form for case-insensitive comparison
local tree_canonical
tree_canonical=$(cd "${tree}" && pwd -P)
while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] && while [ "${pathdir}" != '' ] && [ "${pathdir}" != '.' ] && [ "${pathdir}" != '/' ] &&
[ "${pathdir}" != "${tree}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do [ "${pathdir}" != "${tree_canonical}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
previous_pathdir="${pathdir}" previous_pathdir="${pathdir}"
pathdir=$(dirname "${previous_pathdir}") pathdir=$(dirname "${previous_pathdir}")
done done
[ "${pathdir}" = "${tree}" ]
[ "${pathdir}" = "${tree_canonical}" ]
} }
nvm_find_project_dir() { nvm_find_project_dir() {
local path_ local path_
path_="${PWD}" path_="${PWD}"
@@ -503,9 +511,9 @@ $(nvm_wrap_with_color_code 'y' "${warn_text}")"
} }
nvm_process_nvmrc() { nvm_process_nvmrc() {
local NVMRC_PATH="$1" local NVMRC_PATH
NVMRC_PATH="$1"
local lines local lines
local unpaired_line
lines=$(command sed 's/#.*//' "$NVMRC_PATH" | command sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | nvm_grep -v '^$') lines=$(command sed 's/#.*//' "$NVMRC_PATH" | command sed 's/^[[:space:]]*//;s/[[:space:]]*$//' | nvm_grep -v '^$')
@@ -515,8 +523,12 @@ nvm_process_nvmrc() {
fi fi
# Initialize key-value storage # Initialize key-value storage
local keys='' local keys
local values='' keys=''
local values
values=''
local unpaired_line
unpaired_line=''
while IFS= read -r line; do while IFS= read -r line; do
if [ -z "${line}" ]; then if [ -z "${line}" ]; then
@@ -2437,7 +2449,7 @@ nvm_download_artifact() {
nvm_err "Downloading ${TARBALL_URL}..." nvm_err "Downloading ${TARBALL_URL}..."
nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${TARBALL}" || ( nvm_download -L -C - "${PROGRESS_BAR}" "${TARBALL_URL}" -o "${TARBALL}" || (
command rm -rf "${TARBALL}" "${tmpdir}" command rm -rf "${TARBALL}" "${tmpdir}"
nvm_err "Binary download from ${TARBALL_URL} failed, trying source." nvm_err "download from ${TARBALL_URL} failed"
return 4 return 4
) )
@@ -3356,6 +3368,10 @@ nvm() {
shift shift
;; ;;
--save | -w) --save | -w)
if [ $NVM_WRITE_TO_NVMRC -eq 1 ]; then
nvm_err '--save and -w may only be provided once'
return 6
fi
NVM_WRITE_TO_NVMRC=1 NVM_WRITE_TO_NVMRC=1
shift shift
;; ;;
@@ -3507,6 +3523,11 @@ nvm() {
nvm_ensure_default_set "${provided_version}" nvm_ensure_default_set "${provided_version}"
fi fi
if [ $NVM_WRITE_TO_NVMRC -eq 1 ]; then
nvm_write_nvmrc "${VERSION}"
EXIT_CODE=$?
fi
if [ $EXIT_CODE -ne 0 ] && [ -n "${ALIAS-}" ]; then if [ $EXIT_CODE -ne 0 ] && [ -n "${ALIAS-}" ]; then
nvm alias "${ALIAS}" "${provided_version}" nvm alias "${ALIAS}" "${provided_version}"
EXIT_CODE=$? EXIT_CODE=$?
@@ -3558,9 +3579,13 @@ nvm() {
EXIT_CODE=$? EXIT_CODE=$?
else else
EXIT_CODE=-1 EXIT_CODE=-1
if [ $nosource -eq 1 ]; then
nvm_err "Binary download is not available for ${VERSION}"
EXIT_CODE=3
fi
fi fi
if [ $EXIT_CODE -ne 0 ]; then if [ $EXIT_CODE -ne 0 ] && [ $nosource -ne 1 ]; then
if [ -z "${NVM_MAKE_JOBS-}" ]; then if [ -z "${NVM_MAKE_JOBS-}" ]; then
nvm_get_make_jobs nvm_get_make_jobs
fi fi
@@ -3575,25 +3600,27 @@ nvm() {
fi fi
fi fi
if [ $EXIT_CODE -eq 0 ] && nvm_use_if_needed "${VERSION}" && nvm_install_npm_if_needed "${VERSION}"; then if [ $EXIT_CODE -eq 0 ]; then
if [ -n "${LTS-}" ]; then if nvm_use_if_needed "${VERSION}" && nvm_install_npm_if_needed "${VERSION}"; then
nvm_ensure_default_set "lts/${LTS}" if [ -n "${LTS-}" ]; then
nvm_ensure_default_set "lts/${LTS}"
else
nvm_ensure_default_set "${provided_version}"
fi
if [ "${NVM_UPGRADE_NPM}" = 1 ]; then
nvm install-latest-npm
EXIT_CODE=$?
fi
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
nvm_install_default_packages
fi
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
EXIT_CODE=$?
fi
else else
nvm_ensure_default_set "${provided_version}"
fi
if [ "${NVM_UPGRADE_NPM}" = 1 ]; then
nvm install-latest-npm
EXIT_CODE=$? EXIT_CODE=$?
fi fi
if [ $EXIT_CODE -eq 0 ] && [ -z "${SKIP_DEFAULT_PACKAGES-}" ]; then
nvm_install_default_packages
fi
if [ $EXIT_CODE -eq 0 ] && [ -n "${REINSTALL_PACKAGES_FROM-}" ] && [ "_${REINSTALL_PACKAGES_FROM}" != "_N/A" ]; then
nvm reinstall-packages "${REINSTALL_PACKAGES_FROM}"
EXIT_CODE=$?
fi
else
EXIT_CODE=$?
fi fi
return $EXIT_CODE return $EXIT_CODE
@@ -3736,6 +3763,8 @@ nvm() {
local NVM_LTS local NVM_LTS
local IS_VERSION_FROM_NVMRC local IS_VERSION_FROM_NVMRC
IS_VERSION_FROM_NVMRC=0 IS_VERSION_FROM_NVMRC=0
local NVM_WRITE_TO_NVMRC
NVM_WRITE_TO_NVMRC=0
while [ $# -ne 0 ]; do while [ $# -ne 0 ]; do
case "$1" in case "$1" in
@@ -3747,7 +3776,13 @@ nvm() {
--) ;; --) ;;
--lts) NVM_LTS='*' ;; --lts) NVM_LTS='*' ;;
--lts=*) NVM_LTS="${1##--lts=}" ;; --lts=*) NVM_LTS="${1##--lts=}" ;;
--save | -w) NVM_WRITE_TO_NVMRC=1 ;; --save | -w)
if [ $NVM_WRITE_TO_NVMRC -eq 1 ]; then
nvm_err '--save and -w may only be provided once'
return 6
fi
NVM_WRITE_TO_NVMRC=1
;;
--*) ;; --*) ;;
*) *)
if [ -n "${1-}" ]; then if [ -n "${1-}" ]; then
@@ -3781,8 +3816,8 @@ nvm() {
return 127 return 127
fi fi
if [ "${NVM_WRITE_TO_NVMRC:-0}" -eq 1 ]; then if [ $NVM_WRITE_TO_NVMRC -eq 1 ]; then
nvm_write_nvmrc "$VERSION" nvm_write_nvmrc "${VERSION}"
fi fi
if [ "_${VERSION}" = '_system' ]; then if [ "_${VERSION}" = '_system' ]; then
@@ -3800,7 +3835,7 @@ nvm() {
nvm_err 'System version of node not found.' nvm_err 'System version of node not found.'
fi fi
return 127 return 127
elif [ "_${VERSION}" = "_∞" ]; then elif [ "_${VERSION}" = '_∞' ]; then
if [ "${NVM_SILENT:-0}" -ne 1 ]; then if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "The alias \"${PROVIDED_VERSION}\" leads to an infinite loop. Aborting." nvm_err "The alias \"${PROVIDED_VERSION}\" leads to an infinite loop. Aborting."
fi fi
@@ -4529,31 +4564,44 @@ nvm_supports_xz() {
nvm_auto() { nvm_auto() {
local NVM_MODE local NVM_MODE
NVM_MODE="${1-}" NVM_MODE="${1-}"
local VERSION
local NVM_CURRENT case "${NVM_MODE}" in
if [ "_${NVM_MODE}" = '_install' ]; then none) return 0 ;;
VERSION="$(nvm_alias default 2>/dev/null || nvm_echo)" use)
if [ -n "${VERSION}" ] && ! [ "_${VERSION}" = '_N/A' ] && nvm_is_valid_version "${VERSION}"; then local VERSION
nvm install "${VERSION}" >/dev/null local NVM_CURRENT
elif nvm_rc_version >/dev/null 2>&1; then NVM_CURRENT="$(nvm_ls_current)"
nvm install >/dev/null if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then
fi VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
elif [ "_$NVM_MODE" = '_use' ]; then if [ -n "${VERSION}" ]; then
NVM_CURRENT="$(nvm_ls_current)" if [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
if [ "_${NVM_CURRENT}" = '_none' ] || [ "_${NVM_CURRENT}" = '_system' ]; then nvm use --silent "${VERSION}" >/dev/null
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)" else
if [ -n "${VERSION}" ] && ! [ "_${VERSION}" = '_N/A' ] && nvm_is_valid_version "${VERSION}"; then return 0
nvm use --silent "${VERSION}" >/dev/null fi
elif nvm_rc_version >/dev/null 2>&1; then elif nvm_rc_version >/dev/null 2>&1; then
nvm use --silent >/dev/null nvm use --silent >/dev/null
fi
else
nvm use --silent "${NVM_CURRENT}" >/dev/null
fi fi
else ;;
nvm use --silent "${NVM_CURRENT}" >/dev/null install)
fi local VERSION
elif [ "_${NVM_MODE}" != '_none' ]; then VERSION="$(nvm_alias default 2>/dev/null || nvm_echo)"
nvm_err 'Invalid auto mode supplied.' if [ -n "${VERSION}" ] && [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
return 1 nvm install "${VERSION}" >/dev/null
fi elif nvm_rc_version >/dev/null 2>&1; then
nvm install >/dev/null
else
return 0
fi
;;
*)
nvm_err 'Invalid auto mode supplied.'
return 1
;;
esac
} }
nvm_process_parameters() { nvm_process_parameters() {

View File

@@ -0,0 +1,20 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
nvm_install_source() {
exit 42
}
VERSION="0.7.0"
EXIT_CODE=$(nvm install -b "${VERSION}" ; echo $?)
[ $EXIT_CODE -eq 3 ] || die "Expected exit code 3, got ${EXIT_CODE}"
ACTUAL="$(nvm install -b "${VERSION}" 2>&1)"
EXPECTED="Binary download is not available for v${VERSION}"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"

View File

@@ -6,14 +6,14 @@ die () { echo "$@" ; cleanup ; exit 1; }
cleanup() { cleanup() {
unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs unset -f nvm_download nvm_ls_remote nvm_ls_remote_iojs
if [ -n TEMP_NVM_COLORS ]; then if [ -n "${TEMP_NVM_COLORS-}" ]; then
export NVM_COLORS=TEMP_NVM_COLORS export NVM_COLORS=TEMP_NVM_COLORS
fi fi
unset TEMP_NVM_COLORS unset TEMP_NVM_COLORS
} }
\. ../../../nvm.sh \. ../../../nvm.sh
if [ -n ${NVM_COLORS} ]; then if [ -n "${NVM_COLORS-}" ]; then
export TEMP_NVM_COLORS=NVM_COLORS export TEMP_NVM_COLORS=NVM_COLORS
unset NVM_COLORS unset NVM_COLORS
fi fi

View File

@@ -27,15 +27,15 @@ setup () {
mkdir -p "$npm_config_prefix/lib" mkdir -p "$npm_config_prefix/lib"
} }
setup setup
npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package' npm install -g nop >/dev/null || die 'nvm_check_global_modules cannot be tested because `npm` cannot install the `nop` package'
message=$(nvm_check_global_modules) message=$(nvm_check_global_modules)
[ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}" [ ! -z "$message" ] || die "nvm_check_global_modules should have printed a notice when npm had global modules installed; got:\n${message}"
if [ -n "${ORIGINAL_NVM_DIR}" ]; then if [ -n "${ORIGINAL_NVM_DIR}" ] && [ -z "${GITHUB_ACTIONS}" ]; then
# Admit we're using NVM, just for this one test # Admit we're using NVM, just for this one test
# TODO: fix this for GHA
message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules) message=$(NVM_DIR="${ORIGINAL_NVM_DIR}" nvm_check_global_modules)
[ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}" [ -z "$message" ] || die "nvm_check_global_modules should not have printed a notice when npm is managed by nvm; got:\n${message}"
fi fi

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo "$*" ; echo "|${NVM_DIR}|"; exit 1; }
echo '0.10.1' > ../../alias/default || die "couldn't create default alias" echo '0.10.1' > ../../alias/default || die "couldn't create default alias"
@@ -9,12 +9,12 @@ echo '0.10.1' > ../../alias/default || die "couldn't create default alias"
NVM_TARGET=0.10.3 NVM_TARGET=0.10.3
NVM_DEFAULT="$(nvm_resolve_local_alias default)" NVM_DEFAULT="$(nvm_resolve_local_alias default)"
[ "_$NVM_DEFAULT" != "_$NVM_TARGET" ] || die "default $NVM_DEFAULT is the same as target $NVM_TARGET" [ "_${NVM_DEFAULT}" != "_${NVM_TARGET}" ] || die "default ${NVM_DEFAULT} is the same as target ${NVM_TARGET}"
nvm use $NVM_TARGET || die "nvm use $NVM_TARGET failed" nvm use "${NVM_TARGET}" || die "nvm use ${NVM_TARGET} failed"
\. ../../nvm.sh || die 'sourcing returned nonzero exit code' \. ../../nvm.sh || die 'sourcing returned nonzero exit code'
NVM_CURRENT="$(nvm current)" NVM_CURRENT="$(nvm current)"
[ "_${NVM_CURRENT#v}" = "_$NVM_TARGET" ] || die "node version not retained after sourcing" [ "_${NVM_CURRENT#v}" = "_${NVM_TARGET}" ] || die "node version not retained after sourcing"

View File

@@ -8,21 +8,21 @@ die () { echo "$@" ; exit 1; }
# despite being unloaded in setup, the inherited PATH still contains # despite being unloaded in setup, the inherited PATH still contains
# an nvm-installed node version. We have to reset NVM_DIR after the unload. # an nvm-installed node version. We have to reset NVM_DIR after the unload.
\. ../../nvm.sh || die 'sourcing returned nonzero exit code' \. ../../nvm.sh || die 'sourcing returned nonzero exit code'
NVM_DIR_CACHED="$NVM_DIR" NVM_DIR_CACHED="${NVM_DIR}"
nvm unload || die 'unloading returned nonzero exit code' nvm unload || die 'unloading returned nonzero exit code'
NVM_DIR="$NVM_DIR_CACHED" NVM_DIR="${NVM_DIR_CACHED}"
echo '0.10.1' > ../../alias/default || die 'creation of default alias failed' echo '0.10.1' > "${NVM_DIR}/alias/default" || die 'creation of default alias failed'
# Now to begin the real test # Now to begin the real test
\. ../../nvm.sh || die 'sourcing returned nonzero exit code' \. ../../nvm.sh || die 'sourcing returned nonzero exit code'
NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)" NVM_LS_CURRENT_NOT_GREPPED="$(nvm ls current | strip_colors)"
NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)" NVM_LS_CURRENT="$(nvm ls current | strip_colors | \grep -o v0.10.1)"
[ "_$NVM_LS_CURRENT" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '$NVM_LS_CURRENT_NOT_GREPPED'" [ "_${NVM_LS_CURRENT}" = '_v0.10.1' ] || die "'nvm ls current' did not return '-> v0.10.1', got '${NVM_LS_CURRENT_NOT_GREPPED}'"
# NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)" # NVM_LS_CURRENT_COLORED="$(nvm ls current | sed -n l)"
NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)" NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"
[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.1 (-> v0.10.1)" ] \ [ "_${NVM_ALIAS_DEFAULT}" = "_default -> 0.10.1 (-> v0.10.1)" ] \
|| die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '$NVM_ALIAS_DEFAULT'" || die "'nvm alias default did not return 'default -> 0.10.1 (-> v0.10.1)', got '${NVM_ALIAS_DEFAULT}'"

View File

@@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
die () { echo "$@" ; exit 1; } die () { echo "$*" ; echo "|${NVM_DIR}|"; exit 1; }
supports_source_options () { supports_source_options () {
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ] [ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
} }
@@ -10,18 +11,23 @@ if ! supports_source_options; then
exit 0; exit 0;
fi fi
echo '0.10.2' > ../../.nvmrc || die 'creation of .nvmrc failed' echo '0.10.2' > .nvmrc || die 'creation of .nvmrc failed'
export NVM_DIR="${PWD}/../.."
rm ../../alias/default
\. ../../nvm.sh --install \. ../../nvm.sh --install
EXIT_CODE="$(echo $?)" EXIT_CODE="$?"
echo 'sourcing complete.' echo 'sourcing complete.'
nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)"
[ "_$(nvm_rc_version | \grep -o -e 'with version .*$')" = "_with version <0.10.2>" ] || die "nvm_rc_version $(nvm_rc_version)" [ "_$(nvm_rc_version | \grep -o -e 'with version .*$')" = "_with version <0.10.2>" ] || die "nvm_rc_version $(nvm_rc_version)"
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE" nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: \n$(nvm_ls)"
[ "_${EXIT_CODE}" = '_0' ] || die "sourcing returned nonzero exit code: ${EXIT_CODE}"
NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)" NVM_LS_CURRENT="$(nvm ls current | \grep -o v0.10.2)"
[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT' `nvm ls`" [ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got >${NVM_LS_CURRENT}<\n$(nvm_ls)"
rm .nvmrc

View File

@@ -2,6 +2,7 @@
\. ../common.sh \. ../common.sh
die () { echo "$@" ; exit 1; } die () { echo "$@" ; exit 1; }
supports_source_options () { supports_source_options () {
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ] [ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
} }
@@ -11,22 +12,26 @@ if ! supports_source_options; then
exit 0; exit 0;
fi fi
rm .nvmrc
export NVM_DIR="${PWD}/../.."
echo '0.10.2' > ../../alias/default || die 'creation of default alias failed' echo '0.10.2' > ../../alias/default || die 'creation of default alias failed'
echo 'sourcing nvm with --install...' echo 'sourcing nvm with --install...'
\. ../../nvm.sh --install \. ../../nvm.sh --install
EXIT_CODE="$(echo $?)" EXIT_CODE="$?"
echo 'sourcing complete.' echo 'sourcing complete.'
nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: $(nvm ls)" [ "$(nvm_alias default)" = '0.10.2' ] || die "nvm_alias default did not return '0.10.2', got >$(nvm_alias default)<"
[ "_$EXIT_CODE" = "_0" ] || die "sourcing returned nonzero exit code: $EXIT_CODE" nvm_version 0.10.2 >/dev/null 2>&1 || die "v0.10.2 not installed: \n$(nvm_ls)"
[ "_$EXIT_CODE" = '_0' ] || die "sourcing returned nonzero exit code: ${EXIT_CODE}"
NVM_LS_CURRENT="$(nvm ls current | strip_colors | command grep -o v0.10.2)" NVM_LS_CURRENT="$(nvm ls current | strip_colors | command grep -o v0.10.2)"
[ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', got '$NVM_LS_CURRENT'" [ "_$NVM_LS_CURRENT" = '_v0.10.2' ] || die "'nvm ls current' did not return '-> v0.10.2', >${NVM_LS_CURRENT}<\n$(nvm_ls)"
NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)" NVM_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"
[ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2)" ] \ [ "_$NVM_ALIAS_DEFAULT" = "_default -> 0.10.2 (-> v0.10.2)" ] \
|| die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got '$NVM_ALIAS_DEFAULT'" || die "'nvm alias default did not return 'default -> 0.10.2 (-> v0.10.2)', got >${NVM_ALIAS_DEFAULT}<\n$(nvm_ls)"

View File

@@ -4,4 +4,5 @@ rm -rf ../../alias
rm -rf ../../v0.10.1 rm -rf ../../v0.10.1
rm -rf ../../v0.10.2 rm -rf ../../v0.10.2
rm -rf ../../v0.10.3 rm -rf ../../v0.10.3
rm -rf ../../versions/node/v4.1.0
rm -f ../../.nvmrc rm -f ../../.nvmrc