mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-08-19 12:03:43 +00:00
Compare commits
6 Commits
2d4283c38a
...
4e2ed4624d
Author | SHA1 | Date | |
---|---|---|---|
![]() |
4e2ed4624d | ||
![]() |
0ce8f5a52f | ||
![]() |
863bd63cfa | ||
![]() |
0d53381666 | ||
![]() |
df70535248 | ||
![]() |
cae2eb71a2 |
30
.github/workflows/tests.yml
vendored
30
.github/workflows/tests.yml
vendored
@ -19,13 +19,24 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
include:
|
||||
- shell: bash
|
||||
exclude:
|
||||
- shell: sh
|
||||
suite: install_script
|
||||
# shell:
|
||||
# - bash
|
||||
# suite:
|
||||
# - install_script
|
||||
- shell: dash
|
||||
suite: install_script
|
||||
- shell: zsh
|
||||
suite: install_script
|
||||
- shell: ksh
|
||||
suite: install_script
|
||||
suite:
|
||||
- install_script
|
||||
- sourcing
|
||||
shell:
|
||||
- sh
|
||||
- bash
|
||||
- dash
|
||||
- zsh
|
||||
# - ksh
|
||||
|
||||
steps:
|
||||
- name: Harden Runner
|
||||
@ -37,7 +48,13 @@ jobs:
|
||||
raw.githubusercontent.com:443
|
||||
nodejs.org:443
|
||||
iojs.org:443
|
||||
azure.archive.ubuntu.com:80
|
||||
packages.microsoft.com:443
|
||||
- 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: curl --version
|
||||
- run: wget --version
|
||||
@ -48,6 +65,7 @@ jobs:
|
||||
skip-ls-check: true
|
||||
shell-command: echo installed
|
||||
- run: npm ls urchin
|
||||
- run: npx which urchin
|
||||
- run: env
|
||||
- run: make TERM=xterm-256color TEST_SUITE="${{ matrix.suite }}" SHELL="${{ matrix.shell }}" URCHIN="$(npx which urchin)" test-${{ matrix.shell }}
|
||||
|
||||
|
@ -87,11 +87,6 @@ env:
|
||||
- SHELL=bash TEST_SUITE=fast
|
||||
- SHELL=zsh 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=dash TEST_SUITE=slow
|
||||
- SHELL=bash TEST_SUITE=slow
|
||||
|
2
Makefile
2
Makefile
@ -43,7 +43,7 @@ $(SHELL_TARGETS):
|
||||
@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; } && \
|
||||
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 \
|
||||
echo "Running test suite: $$suite"; \
|
||||
$(URCHIN) -f -s $$shell test/$$suite || exit; \
|
||||
|
@ -163,7 +163,8 @@ install_nvm_from_git() {
|
||||
}
|
||||
else
|
||||
# Cloning repo
|
||||
command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
|
||||
command git clone "$(nvm_source)" --depth=1 -o origin "${INSTALL_DIR}" 2> /dev/null \
|
||||
|| command git clone "$(nvm_source)" --depth=1 "${INSTALL_DIR}" || {
|
||||
nvm_echo >&2 'Failed to clone nvm repo. Please report this!'
|
||||
exit 2
|
||||
}
|
||||
|
32
nvm.sh
32
nvm.sh
@ -128,7 +128,12 @@ nvm_download() {
|
||||
if nvm_curl_use_compression; then
|
||||
CURL_COMPRESSED_FLAG="--compressed"
|
||||
fi
|
||||
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} $*"
|
||||
local NVM_DOWNLOAD_ARGS
|
||||
NVM_DOWNLOAD_ARGS=''
|
||||
for arg in "$@"; do
|
||||
NVM_DOWNLOAD_ARGS="${NVM_DOWNLOAD_ARGS} \"$arg\""
|
||||
done
|
||||
eval "curl -q --fail ${CURL_COMPRESSED_FLAG:-} ${CURL_HEADER_FLAG:-} ${NVM_DOWNLOAD_ARGS}"
|
||||
elif nvm_has "wget"; then
|
||||
# Emulate curl with wget
|
||||
ARGS=$(nvm_echo "$@" | command sed -e 's/--progress-bar /--progress=bar /' \
|
||||
@ -4559,7 +4564,7 @@ nvm_auto() {
|
||||
|
||||
case "${NVM_MODE}" in
|
||||
none) return 0 ;;
|
||||
use | install)
|
||||
use)
|
||||
local VERSION
|
||||
local NVM_CURRENT
|
||||
NVM_CURRENT="$(nvm_ls_current)"
|
||||
@ -4567,25 +4572,28 @@ nvm_auto() {
|
||||
VERSION="$(nvm_resolve_local_alias default 2>/dev/null || nvm_echo)"
|
||||
if [ -n "${VERSION}" ]; then
|
||||
if [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
|
||||
if [ "_${NVM_MODE}" = '_install' ]; then
|
||||
nvm install "${VERSION}" >/dev/null
|
||||
else
|
||||
nvm use --silent "${VERSION}" >/dev/null
|
||||
fi
|
||||
nvm use --silent "${VERSION}" >/dev/null
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
elif nvm_rc_version >/dev/null 2>&1; then
|
||||
if [ "_${NVM_MODE}" = '_install' ]; then
|
||||
nvm install >/dev/null
|
||||
else
|
||||
nvm use --silent >/dev/null
|
||||
fi
|
||||
nvm use --silent >/dev/null
|
||||
fi
|
||||
else
|
||||
nvm use --silent "${NVM_CURRENT}" >/dev/null
|
||||
fi
|
||||
;;
|
||||
install)
|
||||
local VERSION
|
||||
VERSION="$(nvm_alias default 2>/dev/null || nvm_echo)"
|
||||
if [ -n "${VERSION}" ] && [ "_${VERSION}" != '_N/A' ] && nvm_is_valid_version "${VERSION}"; then
|
||||
nvm install "${VERSION}" >/dev/null
|
||||
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
|
||||
|
0
test/fast/Unit tests/Running 'nvm install --save' works as expected'
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm install --save' works as expected'
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm use --save' works with a .nvmrc in the parent dir
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm use --silent --save' doesn't output anything
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm use -w' works as expected'
Normal file → Executable file
0
test/fast/Unit tests/Running 'nvm use -w' works as expected'
Normal file → Executable file
3
test/fast/Unit tests/nvm_download
Normal file → Executable file
3
test/fast/Unit tests/nvm_download
Normal file → Executable file
@ -25,4 +25,7 @@ NVM_AUTH_HEADER="Bearer test-token" nvm_download "http://127.0.0.1/bearer" > /de
|
||||
nvm_download "http://127.0.0.1/bearer" > /dev/null && die 'nvm_download with no auth header should not send the header and should fail'
|
||||
docker stop httpbin && docker rm httpbin
|
||||
|
||||
# ensure quoted extra args remain quoted
|
||||
nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" -o "; die quoted-command-not-quoted" || die 'command failed'
|
||||
|
||||
cleanup
|
||||
|
0
test/fast/Unit tests/nvm_install_binary_extract
Normal file → Executable file
0
test/fast/Unit tests/nvm_install_binary_extract
Normal file → Executable file
0
test/fast/Unit tests/nvm_install_no_progress_bar
Normal file → Executable file
0
test/fast/Unit tests/nvm_install_no_progress_bar
Normal file → Executable file
0
test/fast/Unit tests/nvm_is_version_installed
Normal file → Executable file
0
test/fast/Unit tests/nvm_is_version_installed
Normal file → Executable file
0
test/fast/Unit tests/nvm_write_nvmrc
Normal file → Executable file
0
test/fast/Unit tests/nvm_write_nvmrc
Normal file → Executable file
0
test/fast/nvm should remove the last trailing slash in $NVM_DIR
Normal file → Executable file
0
test/fast/nvm should remove the last trailing slash in $NVM_DIR
Normal file → Executable file
@ -27,15 +27,15 @@ setup () {
|
||||
mkdir -p "$npm_config_prefix/lib"
|
||||
}
|
||||
|
||||
|
||||
setup
|
||||
|
||||
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)
|
||||
[ ! -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
|
||||
# TODO: fix this for GHA
|
||||
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}"
|
||||
fi
|
||||
|
2
test/install_script/nvm_download
Normal file → Executable file
2
test/install_script/nvm_download
Normal file → Executable file
@ -12,7 +12,7 @@ nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/install.sh" >/de
|
||||
|
||||
# nvm_download should fail to download wrong_install.sh
|
||||
if nvm_download "https://raw.githubusercontent.com/nvm-sh/nvm/HEAD/wrong_install.sh" &>/dev/null; then
|
||||
die "nvm_download should fail to download no existing file"
|
||||
die "nvm_download should fail to download nonexistent file"
|
||||
fi
|
||||
|
||||
cleanup
|
||||
|
0
test/installation_iojs/install from source
Normal file → Executable file
0
test/installation_iojs/install from source
Normal file → Executable file
0
test/installation_iojs/install version specified in .nvmrc from source
Normal file → Executable file
0
test/installation_iojs/install version specified in .nvmrc from source
Normal file → Executable file
0
test/installation_node/install from binary with binary flag set
Normal file → Executable file
0
test/installation_node/install from binary with binary flag set
Normal file → Executable file
0
test/slow/nvm exec/Running 'nvm exec' with help should not parse
Normal file → Executable file
0
test/slow/nvm exec/Running 'nvm exec' with help should not parse
Normal file → Executable file
0
test/slow/nvm reinstall-packages/test-npmlink/package.json
Normal file → Executable file
0
test/slow/nvm reinstall-packages/test-npmlink/package.json
Normal file → Executable file
0
test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
Normal file → Executable file
0
test/slow/nvm use/Running 'nvm use' with nvmrc containing not installed version
Normal file → Executable file
@ -1,6 +1,6 @@
|
||||
#!/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"
|
||||
|
||||
@ -9,12 +9,12 @@ echo '0.10.1' > ../../alias/default || die "couldn't create default alias"
|
||||
NVM_TARGET=0.10.3
|
||||
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_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"
|
||||
|
@ -8,21 +8,21 @@ die () { echo "$@" ; exit 1; }
|
||||
# despite being unloaded in setup, the inherited PATH still contains
|
||||
# an nvm-installed node version. We have to reset NVM_DIR after the unload.
|
||||
\. ../../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_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
|
||||
\. ../../nvm.sh || die 'sourcing returned nonzero exit code'
|
||||
|
||||
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" = '_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_ALIAS_DEFAULT="$(nvm alias default | strip_colors)"
|
||||
[ "_$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'"
|
||||
[ "_${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}'"
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
die () { echo "$*" ; echo "|${NVM_DIR}|"; exit 1; }
|
||||
|
||||
supports_source_options () {
|
||||
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
|
||||
}
|
||||
@ -10,18 +11,23 @@ if ! supports_source_options; then
|
||||
exit 0;
|
||||
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
|
||||
EXIT_CODE="$(echo $?)"
|
||||
EXIT_CODE="$?"
|
||||
|
||||
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)"
|
||||
|
||||
[ "_$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" = '_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
|
||||
|
@ -2,6 +2,7 @@
|
||||
\. ../common.sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
supports_source_options () {
|
||||
[ "_$(echo 'echo $1' | . /dev/stdin yes)" = "_yes" ]
|
||||
}
|
||||
@ -11,22 +12,26 @@ if ! supports_source_options; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
rm .nvmrc
|
||||
export NVM_DIR="${PWD}/../.."
|
||||
echo '0.10.2' > ../../alias/default || die 'creation of default alias failed'
|
||||
|
||||
echo 'sourcing nvm with --install...'
|
||||
|
||||
\. ../../nvm.sh --install
|
||||
EXIT_CODE="$(echo $?)"
|
||||
EXIT_CODE="$?"
|
||||
|
||||
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" = '_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" = "_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)"
|
||||
|
@ -4,4 +4,5 @@ rm -rf ../../alias
|
||||
rm -rf ../../v0.10.1
|
||||
rm -rf ../../v0.10.2
|
||||
rm -rf ../../v0.10.3
|
||||
rm -rf ../../versions/node/v4.1.0
|
||||
rm -f ../../.nvmrc
|
Loading…
x
Reference in New Issue
Block a user