mirror of
https://github.com/nvm-sh/nvm.git
synced 2025-12-13 08:34:19 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1b6332bbe | ||
|
|
159d4c645e | ||
|
|
687df82107 | ||
|
|
ff1781b95d | ||
|
|
110e571c34 | ||
|
|
a7108e98f2 | ||
|
|
30b044a368 | ||
|
|
825cb46969 | ||
|
|
ab56ec6675 |
@@ -8,11 +8,11 @@ First you'll need to make sure your system has a c++ compiler. For OSX, XCode w
|
|||||||
|
|
||||||
To install you could use the [install script][2] using cURL:
|
To install you could use the [install script][2] using cURL:
|
||||||
|
|
||||||
curl https://raw.githubusercontent.com/creationix/nvm/v0.15.0/install.sh | bash
|
curl https://raw.githubusercontent.com/creationix/nvm/v0.16.0/install.sh | bash
|
||||||
|
|
||||||
or Wget:
|
or Wget:
|
||||||
|
|
||||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.15.0/install.sh | bash
|
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.16.0/install.sh | bash
|
||||||
|
|
||||||
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
|
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc` or `~/.profile`).</sub>
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
|
|||||||
nvm install -s 0.8.6
|
nvm install -s 0.8.6
|
||||||
|
|
||||||
[1]: https://github.com/creationix/nvm.git
|
[1]: https://github.com/creationix/nvm.git
|
||||||
[2]: https://github.com/creationix/nvm/blob/v0.15.0/install.sh
|
[2]: https://github.com/creationix/nvm/blob/v0.16.0/install.sh
|
||||||
[3]: https://travis-ci.org/creationix/nvm
|
[3]: https://travis-ci.org/creationix/nvm
|
||||||
[Urchin]: https://github.com/scraperwiki/urchin
|
[Urchin]: https://github.com/scraperwiki/urchin
|
||||||
|
|
||||||
|
|||||||
10
install.sh
10
install.sh
@@ -44,12 +44,12 @@ install_nvm_from_git() {
|
|||||||
mkdir -p "$NVM_DIR"
|
mkdir -p "$NVM_DIR"
|
||||||
git clone "$NVM_SOURCE" "$NVM_DIR"
|
git clone "$NVM_SOURCE" "$NVM_DIR"
|
||||||
fi
|
fi
|
||||||
cd $NVM_DIR && git checkout v0.15.0 && git branch -D master || true
|
cd $NVM_DIR && git checkout v0.16.0 && git branch -D master || true
|
||||||
}
|
}
|
||||||
|
|
||||||
install_nvm_as_script() {
|
install_nvm_as_script() {
|
||||||
if [ -z "$NVM_SOURCE" ]; then
|
if [ -z "$NVM_SOURCE" ]; then
|
||||||
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.15.0/nvm.sh"
|
NVM_SOURCE="https://raw.githubusercontent.com/creationix/nvm/v0.16.0/nvm.sh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Downloading to $NVM_DIR
|
# Downloading to $NVM_DIR
|
||||||
@@ -96,7 +96,9 @@ echo
|
|||||||
|
|
||||||
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
|
# Detect profile file if not specified as environment variable (eg: PROFILE=~/.myprofile).
|
||||||
if [ -z "$PROFILE" ]; then
|
if [ -z "$PROFILE" ]; then
|
||||||
if [ -f "$HOME/.bash_profile" ]; then
|
if [ -f "$HOME/.bashrc" ]; then
|
||||||
|
PROFILE="$HOME/.bashrc"
|
||||||
|
elif [ -f "$HOME/.bash_profile" ]; then
|
||||||
PROFILE="$HOME/.bash_profile"
|
PROFILE="$HOME/.bash_profile"
|
||||||
elif [ -f "$HOME/.zshrc" ]; then
|
elif [ -f "$HOME/.zshrc" ]; then
|
||||||
PROFILE="$HOME/.zshrc"
|
PROFILE="$HOME/.zshrc"
|
||||||
@@ -109,7 +111,7 @@ SOURCE_STR="\nexport NVM_DIR=\"$NVM_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$
|
|||||||
|
|
||||||
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
if [ -z "$PROFILE" ] || [ ! -f "$PROFILE" ] ; then
|
||||||
if [ -z "$PROFILE" ]; then
|
if [ -z "$PROFILE" ]; then
|
||||||
echo "=> Profile not found. Tried ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
echo "=> Profile not found. Tried ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile."
|
||||||
echo "=> Create one of them and run this script again"
|
echo "=> Create one of them and run this script again"
|
||||||
else
|
else
|
||||||
echo "=> Profile $PROFILE not found"
|
echo "=> Profile $PROFILE not found"
|
||||||
|
|||||||
37
nvm.sh
37
nvm.sh
@@ -249,13 +249,20 @@ nvm_ls() {
|
|||||||
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'`
|
| sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n | \grep -v '^ *\.' | \grep -e '^v'`
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if nvm_has_system_node; then
|
||||||
|
if [ -z "$PATTERN" ]; then
|
||||||
|
VERSIONS="$VERSIONS$(printf '\n%s' 'system')"
|
||||||
|
elif [ "$PATTERN" = 'system' ]; then
|
||||||
|
VERSIONS="$(printf '%s' 'system')"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$VERSIONS" ]; then
|
if [ -z "$VERSIONS" ]; then
|
||||||
echo "N/A"
|
echo "N/A"
|
||||||
return 3
|
return 3
|
||||||
fi
|
fi
|
||||||
if [ -z "$PATTERN" ] && nvm_has_system_node; then
|
|
||||||
VERSIONS="$VERSIONS$(printf '\n%s' 'system')"
|
|
||||||
fi
|
|
||||||
echo "$VERSIONS"
|
echo "$VERSIONS"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -785,11 +792,27 @@ nvm() {
|
|||||||
nvm help
|
nvm help
|
||||||
return 127
|
return 127
|
||||||
fi
|
fi
|
||||||
VERSION="$(nvm_version "$2")"
|
|
||||||
|
|
||||||
# declare local INSTALLS first, otherwise it doesn't work in zsh
|
local PROVIDED_VERSION
|
||||||
|
PROVIDED_VERSION="$2"
|
||||||
|
|
||||||
|
if [ "$PROVIDED_VERSION" = "$(nvm_ls_current)" ]; then
|
||||||
|
echo 'Can not copy packages from the current version of node.' >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
|
||||||
local INSTALLS
|
local INSTALLS
|
||||||
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
if [ "$PROVIDED_VERSION" = "system" ]; then
|
||||||
|
if ! nvm_has_system_node; then
|
||||||
|
echo 'No system version of node detected.' >&2
|
||||||
|
return 3
|
||||||
|
fi
|
||||||
|
INSTALLS=$(nvm deactivate > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
||||||
|
else
|
||||||
|
local VERSION
|
||||||
|
VERSION="$(nvm_version "$PROVIDED_VERSION")"
|
||||||
|
INSTALLS=$(nvm use "$VERSION" > /dev/null && npm list -g --depth=0 | tail -n +2 | \grep -o -e ' [^@]*' | cut -c 2- | \grep -v npm | xargs)
|
||||||
|
fi
|
||||||
|
|
||||||
echo "$INSTALLS" | xargs npm install -g --quiet
|
echo "$INSTALLS" | xargs npm install -g --quiet
|
||||||
;;
|
;;
|
||||||
@@ -801,7 +824,7 @@ nvm() {
|
|||||||
nvm_version $2
|
nvm_version $2
|
||||||
;;
|
;;
|
||||||
"--version" )
|
"--version" )
|
||||||
echo "0.15.0"
|
echo "0.16.0"
|
||||||
;;
|
;;
|
||||||
"unload" )
|
"unload" )
|
||||||
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater > /dev/null 2>&1
|
unset -f nvm nvm_print_versions nvm_checksum nvm_ls_remote nvm_ls nvm_remote_version nvm_version nvm_rc_version nvm_version_greater > /dev/null 2>&1
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "nvm",
|
"name": "nvm",
|
||||||
"version": "0.15.0",
|
"version": "0.16.0",
|
||||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||||
"directories": {
|
"directories": {
|
||||||
"test": "test"
|
"test": "test"
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
cleanup () { unset -f nvm_has_system_node; }
|
||||||
|
die () { cleanup ; echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
mkdir -p ../../../v0.0.1
|
||||||
|
mkdir -p ../../../v0.0.3
|
||||||
|
mkdir -p ../../../v0.0.9
|
||||||
|
mkdir -p ../../../v0.3.1
|
||||||
|
mkdir -p ../../../v0.3.3
|
||||||
|
mkdir -p ../../../v0.3.9
|
||||||
|
|
||||||
|
nvm_has_system_node() { return 0; }
|
||||||
|
nvm ls system | grep system 2>&1 > /dev/null
|
||||||
|
[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present'
|
||||||
|
|
||||||
|
nvm_has_system_node() { return 1; }
|
||||||
|
nvm ls system | grep system 2>&1 > /dev/null
|
||||||
|
[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present'
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../nvm.sh
|
||||||
|
|
||||||
|
local EXPECTED_MSG="Can not copy packages from the current version of node."
|
||||||
|
[ "$(nvm use 0.10.28 && nvm copy-packages 0.10.28 2&>1)" = "$EXPECTED_MSG" ] || die '"nvm use 0.10.28 && nvm copy-packages 0.10.28" did not fail with the right message'
|
||||||
|
|
||||||
|
$(nvm use 0.10.28 && nvm copy-packages 0.10.28)
|
||||||
|
[ $? = 2 ] || die '"nvm use 0.10.28 && nvm copy-packages 0.10.28" did not fail with the right error code'
|
||||||
|
|
||||||
Reference in New Issue
Block a user