Compare commits

..

2 Commits

Author SHA1 Message Date
Steven Dee (Jōshin)
b64f947d8c Merge c106455087 into 179d45050b 2024-08-27 13:47:28 -07:00
Jōshin
c106455087 [Fix] install.sh: install looks for .zshenv
A zsh user may have set `ZDOTDIR` to something other than `$HOME`, in which case the profile and rc files will not be located under `$HOME`. But unless the system `zshenv` has done something unusual, it is usually a safe bet that there will be a `$HOME/.zshenv` that, if nothing else, will be setting up `ZDOTDIR`.
2024-05-30 11:58:37 -07:00
9 changed files with 44 additions and 108 deletions

View File

@@ -58,11 +58,12 @@ jobs:
- run: sudo ${{ matrix.shell }} --version 2> /dev/null || dpkg -s ${{ matrix.shell }} 2> /dev/null || which ${{ matrix.shell }}
- run: curl --version
- run: wget --version
- uses: ljharb/actions/node/install@main
- uses: ljharb/actions/node/run@main
name: 'npm install && version checks'
with:
node-version: 'lts/*'
skip-ls-check: true
shell-command: echo installed
- run: npm ls urchin
- run: npx which urchin
- run: env

View File

@@ -40,7 +40,7 @@ nvm_profile_is_bash_or_zsh() {
local TEST_PROFILE
TEST_PROFILE="${1-}"
case "${TEST_PROFILE-}" in
*"/.bashrc" | *"/.bash_profile" | *"/.zshrc" | *"/.zprofile")
*"/.bashrc" | *"/.bash_profile" | *"/.zshenv" | *"/.zshrc" | *"/.zprofile")
return
;;
*)
@@ -300,11 +300,13 @@ nvm_detect_profile() {
DETECTED_PROFILE="$HOME/.zshrc"
elif [ -f "$HOME/.zprofile" ]; then
DETECTED_PROFILE="$HOME/.zprofile"
elif [ -f "$HOME/.zshenv" ]; then
DETECTED_PROFILE="$HOME/.zshenv"
fi
fi
if [ -z "$DETECTED_PROFILE" ]; then
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc"
for EACH_PROFILE in ".profile" ".bashrc" ".bash_profile" ".zprofile" ".zshrc" ".zshenv"
do
if DETECTED_PROFILE="$(nvm_try_profile "${HOME}/${EACH_PROFILE}")"; then
break

21
nvm.sh
View File

@@ -891,10 +891,6 @@ nvm_normalize_lts() {
fi
;;
*)
if [ "${LTS}" != "$(echo "${LTS}" | command tr '[:upper:]' '[:lower:]')" ]; then
nvm_err 'LTS names must be lowercase'
return 3
fi
nvm_echo "${LTS}"
;;
esac
@@ -1253,9 +1249,7 @@ nvm_alias() {
nvm_err 'An alias is required.'
return 1
fi
if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then
return $?
fi
ALIAS="$(nvm_normalize_lts "${ALIAS}")"
if [ -z "${ALIAS}" ]; then
return 2
@@ -1658,9 +1652,7 @@ $VERSION_LIST
EOF
if [ -n "${LTS-}" ]; then
if ! LTS="$(nvm_normalize_lts "lts/${LTS}")"; then
return $?
fi
LTS="$(nvm_normalize_lts "lts/${LTS}")"
LTS="${LTS#lts/}"
fi
@@ -3425,11 +3417,9 @@ nvm() {
;;
esac
local EXIT_CODE
VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")"
EXIT_CODE="$?"
if [ "${VERSION}" = 'N/A' ] || [ $EXIT_CODE -ne 0 ]; then
if [ "${VERSION}" = 'N/A' ]; then
local LTS_MSG
local REMOTE_CMD
if [ "${LTS-}" = '*' ]; then
@@ -3438,10 +3428,6 @@ nvm() {
elif [ -n "${LTS-}" ]; then
LTS_MSG="(with LTS filter '${LTS}') "
REMOTE_CMD="nvm ls-remote --lts=${LTS}"
if [ -z "${provided_version}" ]; then
nvm_err "Version with LTS filter '${LTS}' not found - try \`${REMOTE_CMD}\` to browse available versions."
return 3
fi
else
REMOTE_CMD='nvm ls-remote'
fi
@@ -3506,6 +3492,7 @@ nvm() {
FLAVOR="$(nvm_node_prefix)"
fi
local EXIT_CODE
EXIT_CODE=0
if nvm_is_version_installed "${VERSION}"; then

View File

@@ -1,35 +0,0 @@
#!/bin/sh
die () { echo "$@" ; exit 1; }
\. ../../../nvm.sh
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt"
nvm_download() {
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
cat "${REMOTE}"
elif [ "$*" = "-L -s $(nvm_get_mirror iojs)/index.tab -o -" ]; then
cat "${REMOTE_IOJS}"
else
nvm_err "unknown nvm_download call: $*"
return 42
fi
}
nvm_install_binary() {
return 42
}
nvm_install_source() {
return 42
}
ACTUAL="$(nvm install lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "Expected exit code of 3, got ${EXIT_CODE}"
EXPECTED="LTS names must be lowercase
Version with LTS filter 'ARGON' not found - try \`nvm ls-remote --lts=ARGON\` to browse available versions."
[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"

View File

@@ -1,5 +1,7 @@
#!/bin/sh
set -e
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
@@ -54,14 +56,6 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
INDEX=$(($INDEX + 1))
done
OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "nvm ls-remote lts/ARGON did not exit 3, got '${EXIT_CODE}'"
EXPECTED_OUTPUT="LTS names must be lowercase
N/A"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "${REMOTE}"

View File

@@ -2,11 +2,11 @@
# Save the PATH as it was when the test started to restore it when it
# finishes
ORIG_PATH="${PATH}"
ORIG_PATH=$PATH
cleanup() {
# Restore the PATH as it was when the test started
export PATH="${ORIG_PATH}"
export PATH=ORIG_PATH
}
die () { cleanup; echo "$@" ; exit 1; }
@@ -15,23 +15,20 @@ die () { cleanup; echo "$@" ; exit 1; }
# Directory where mocked binaries used by nvm_get_arch for each OS/arch are
# located
MOCKS_DIR="$(pwd)/../../mocks"
MOCKS_DIR=`pwd`/../../mocks
# Sets the PATH for these tests to include the symlinks to the mocked
# binaries
export PATH=".:${PATH}"
export PATH=.:${PATH}
# Setups mock binaries for a given OS and arch that mimic
# the output of the real binaries used by nvm_get_arch to guess
# the architecture of a given system.
setup_mock_arch() {
local OS
OS=$1
local ARCH
ARCH=$2
local OPT
OPT=$3
local OS=$1
local ARCH=$2
local OPT=$3
if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
if [ "_$OPT" != "_no_pkg_info" ]; then
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
@@ -45,12 +42,10 @@ setup_mock_arch() {
# Cleans up the setup done by setup_mock_arch.
cleanup_mock_arch() {
local OS
OS=$1
local ARCH
ARCH=$2
local OS=$1
local ARCH=$2
if [ "_${OS}" = '_solaris' ] || [ "_${OS}" = '_smartos' ]; then
if [ "_$OS" = "_solaris" ] || [ "_$OS" = "_smartos" ]; then
rm -f ./isainfo
rm -f ./pkg_info
fi
@@ -62,22 +57,17 @@ cleanup_mock_arch() {
# expected output $EXPECTED_OUTPUT with the actual output. Does nothing
# and exits cleanly if they match, dies otherwise.
run_test() {
local ARCH
ARCH=$1
local OS
OS=$2
local EXPECTED_OUTPUT
EXPECTED_OUTPUT=$3
local OPT
OPT=$4
local ARCH=$1
local OS=$2
local EXPECTED_OUTPUT=$3
local OPT=$4
setup_mock_arch "${OS}" "${ARCH}" "${OPT}"
local OUTPUT
OUTPUT="$(nvm_get_arch)"
cleanup_mock_arch "${OS}" "${ARCH}"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] ||
die "nvm_get_arch for OS \"${OS}\" and arch \"${ARCH}\" with OPT \"${OPT}\" did
not return \"${EXPECTED_OUTPUT}\"; got \"${OUTPUT}\""
setup_mock_arch $OS $ARCH $OPT
local OUTPUT="$(nvm_get_arch)"
cleanup_mock_arch $OS $ARCH
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] ||
die "nvm_get_arch for OS \"$OS\" and arch \"$ARCH\" with OPT \"$OPT\" did
not return \"$EXPECTED_OUTPUT\"; got \"$OUTPUT\""
}
run_test x86 smartos x86

View File

@@ -6,7 +6,7 @@ cleanup () {
nvm cache clear
nvm deactivate
rm -rf ${NVM_DIR}/v*
nvm unalias default || true
nvm unalias default
}
die () { >&2 echo "$@" ; cleanup ; exit 1; }

View File

@@ -16,9 +16,6 @@ ACTUAL="$(nvm_normalize_lts "lts/*")"
EXPECTED='lts/*'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<"
if ACTUAL="$(nvm_normalize_lts lts/ARGON)"; then
die "expected failure, got >${ACTUAL}<"
fi
MOCKS_DIR="../Unit tests/mocks"
STAR="$(cat "$MOCKS_DIR/lts-star.txt")"

View File

@@ -9,20 +9,20 @@ die () { echo "$@" ; exit 1; }
nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default'
set +ex # needed for stderr
OUTPUT="$(nvm install --lts 0.12 2>&1)"
EXIT_CODE="$?"
OUTPUT="$(nvm install --lts 3 2>&1)"
set -ex
EXPECTED_OUTPUT="Version '0.12' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 0.12\` did not exit with 3, got >${EXIT_CODE}<"
EXIT_CODE="$(nvm install --lts 3 >/dev/null 2>&1 && echo $? || echo $?)"
EXPECTED_OUTPUT="Version '3' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 3\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
set +ex # needed for stderr
OUTPUT="$(nvm install --lts=argon 0.12 2>&1)"
EXIT_CODE="$?"
set -x
EXPECTED_OUTPUT="Version '0.12' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 0.12\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 0.12\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
OUTPUT="$(nvm install --lts=argon 3 2>&1)"
set -ex
EXIT_CODE="$(nvm install --lts=argon 3 >/dev/null 2>&1 && echo $? || echo $?)"
EXPECTED_OUTPUT="Version '3' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 3\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
nvm install --lts 4.2.2 || die 'nvm install --lts 4.2.2 failed'