mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-12-12 16:14:18 +00:00
Compare commits
2 Commits
0da3501a3b
...
travis3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f32e7bad4 | ||
|
|
9bd27d3897 |
27
nvm.sh
27
nvm.sh
@@ -196,9 +196,6 @@ nvm_install_latest_npm() {
|
|||||||
nvm_echo 'Attempting to upgrade to the latest working version of npm...'
|
nvm_echo 'Attempting to upgrade to the latest working version of npm...'
|
||||||
local NODE_VERSION
|
local NODE_VERSION
|
||||||
NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")"
|
NODE_VERSION="$(nvm_strip_iojs_prefix "$(nvm_ls_current)")"
|
||||||
local NPM_VERSION
|
|
||||||
NPM_VERSION="$(npm --version 2>/dev/null)"
|
|
||||||
|
|
||||||
if [ "${NODE_VERSION}" = 'system' ]; then
|
if [ "${NODE_VERSION}" = 'system' ]; then
|
||||||
NODE_VERSION="$(node --version)"
|
NODE_VERSION="$(node --version)"
|
||||||
elif [ "${NODE_VERSION}" = 'none' ]; then
|
elif [ "${NODE_VERSION}" = 'none' ]; then
|
||||||
@@ -209,6 +206,8 @@ nvm_install_latest_npm() {
|
|||||||
nvm_err 'Unable to obtain node version.'
|
nvm_err 'Unable to obtain node version.'
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
local NPM_VERSION
|
||||||
|
NPM_VERSION="$(npm --version 2>/dev/null)"
|
||||||
if [ -z "${NPM_VERSION}" ]; then
|
if [ -z "${NPM_VERSION}" ]; then
|
||||||
nvm_err 'Unable to obtain npm version.'
|
nvm_err 'Unable to obtain npm version.'
|
||||||
return 2
|
return 2
|
||||||
@@ -440,7 +439,6 @@ 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-}"
|
||||||
@@ -456,21 +454,14 @@ 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_canonical}" ] && [ "${pathdir}" != "${previous_pathdir}" ]; do
|
[ "${pathdir}" != "${tree}" ] && [ "${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}"
|
||||||
@@ -709,12 +700,10 @@ nvm_ensure_version_installed() {
|
|||||||
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
nvm_err "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed."
|
||||||
fi
|
fi
|
||||||
nvm_err ""
|
nvm_err ""
|
||||||
if [ "${PROVIDED_VERSION}" = 'lts' ]; then
|
if [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
||||||
nvm_err '`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
|
||||||
elif [ "${IS_VERSION_FROM_NVMRC}" != '1' ]; then
|
else
|
||||||
nvm_err "You need to run \`nvm install ${PROVIDED_VERSION}\` to install and use it."
|
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
|
||||||
else
|
|
||||||
nvm_err 'You need to run `nvm install` to install and use the node version specified in `.nvmrc`.'
|
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
set -ex
|
|
||||||
|
|
||||||
die () { echo "$@" ; exit 1; }
|
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
|
||||||
|
|
||||||
# Deactivate any active node version
|
|
||||||
nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
|
|
||||||
|
|
||||||
# Attempt to use 'lts' without '--' and capture the error message
|
|
||||||
ERROR_OUTPUT=$(nvm use lts 2>&1) || true
|
|
||||||
|
|
||||||
EXPECTED_ERROR='`lts` is not an alias - you may need to run `nvm install --lts` to install and `nvm use --lts` to use it.'
|
|
||||||
|
|
||||||
# Check if the error message matches the expected output
|
|
||||||
echo "$ERROR_OUTPUT" | grep -q "$EXPECTED_ERROR" \
|
|
||||||
|| die "Expected error message not found. Got: $ERROR_OUTPUT"
|
|
||||||
Reference in New Issue
Block a user