Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7ad6d98ced | ||
|
|
fa9c50520d | ||
|
|
4846d57c69 | ||
|
|
65f0572bdc | ||
|
|
b6a7a54d04 | ||
|
|
8a8dcbb393 | ||
|
|
bacdd95591 | ||
|
|
4b0563093c | ||
|
|
c7ac69bfbb | ||
|
|
a57fe846e8 | ||
|
|
7bfd1e0644 | ||
|
|
9352f6913a | ||
|
|
16d3e6d2dc | ||
|
|
91a29c0da2 | ||
|
|
4b48556e92 | ||
|
|
be171bba33 | ||
|
|
049a86022f | ||
|
|
a7b7eec0c5 | ||
|
|
9953a52afb | ||
|
|
fc30e0ade4 |
16
README.md
16
README.md
@@ -1,4 +1,4 @@
|
||||
# Node Version Manager [][3] [][4] [](https://bestpractices.coreinfrastructure.org/projects/684)
|
||||
# Node Version Manager [][3] [][4] [](https://bestpractices.coreinfrastructure.org/projects/684)
|
||||
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
||||
@@ -41,13 +41,13 @@
|
||||
To install or update nvm, you can use the [install script][2] using cURL:
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||
```
|
||||
|
||||
or Wget:
|
||||
|
||||
```sh
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||
```
|
||||
|
||||
<sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).</sub>
|
||||
@@ -127,7 +127,7 @@ If you have `git` installed (requires git v1.7+):
|
||||
|
||||
1. clone this repo in the root of your user profile
|
||||
- `cd ~/` from anywhere then `git clone https://github.com/creationix/nvm.git .nvm`
|
||||
2. `cd ~/.nvm` and check out the latest version with `git checkout v0.33.6`
|
||||
2. `cd ~/.nvm` and check out the latest version with `git checkout v0.33.8`
|
||||
3. activate nvm by sourcing it from your shell: `. nvm.sh`
|
||||
|
||||
Now add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
|
||||
@@ -325,7 +325,7 @@ NVM_IOJS_ORG_MIRROR=https://iojs.org/dist nvm install iojs-v1.0.3
|
||||
### .nvmrc
|
||||
|
||||
You can create a `.nvmrc` file containing version number in the project root directory (or any parent directory).
|
||||
`nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied.
|
||||
`nvm use`, `nvm install`, `nvm exec`, `nvm run`, and `nvm which` will all respect an `.nvmrc` file when a version is not supplied on the command line.
|
||||
|
||||
For example, to make nvm default to the latest 5.9 release for the current directory:
|
||||
|
||||
@@ -487,7 +487,7 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
|
||||
|
||||
```sh
|
||||
apk add -U curl bash ca-certificates openssl ncurses coreutils python2 make gcc g++ libgcc linux-headers grep util-linux binutils findutils
|
||||
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.6/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.8/install.sh | bash
|
||||
```
|
||||
|
||||
The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
|
||||
@@ -554,8 +554,8 @@ sudo chmod ugo-x /usr/libexec/path_helper
|
||||
More on this issue in [dotphiles/dotzsh](https://github.com/dotphiles/dotzsh#mac-os-x).
|
||||
|
||||
[1]: https://github.com/creationix/nvm.git
|
||||
[2]: https://github.com/creationix/nvm/blob/v0.33.6/install.sh
|
||||
[2]: https://github.com/creationix/nvm/blob/v0.33.8/install.sh
|
||||
[3]: https://travis-ci.org/creationix/nvm
|
||||
[4]: https://github.com/creationix/nvm/releases/tag/v0.33.6
|
||||
[4]: https://github.com/creationix/nvm/releases/tag/v0.33.8
|
||||
[Urchin]: https://github.com/scraperwiki/urchin
|
||||
[Fish]: http://fishshell.com
|
||||
|
||||
18
install.sh
18
install.sh
@@ -11,7 +11,7 @@ nvm_install_dir() {
|
||||
}
|
||||
|
||||
nvm_latest_version() {
|
||||
echo "v0.33.6"
|
||||
echo "v0.33.8"
|
||||
}
|
||||
|
||||
nvm_profile_is_bash_or_zsh() {
|
||||
@@ -140,22 +140,22 @@ install_nvm_from_git() {
|
||||
# Automatically install Node.js
|
||||
#
|
||||
nvm_install_node() {
|
||||
local NODE_VERSION
|
||||
NODE_VERSION="$(nvm_node_version)"
|
||||
local NODE_VERSION_LOCAL
|
||||
NODE_VERSION_LOCAL="$(nvm_node_version)"
|
||||
|
||||
if [ -z "$NODE_VERSION" ]; then
|
||||
if [ -z "$NODE_VERSION_LOCAL" ]; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "=> Installing Node.js version $NODE_VERSION"
|
||||
nvm install "$NODE_VERSION"
|
||||
echo "=> Installing Node.js version $NODE_VERSION_LOCAL"
|
||||
nvm install "$NODE_VERSION_LOCAL"
|
||||
local CURRENT_NVM_NODE
|
||||
|
||||
CURRENT_NVM_NODE="$(nvm_version current)"
|
||||
if [ "$(nvm_version "$NODE_VERSION")" == "$CURRENT_NVM_NODE" ]; then
|
||||
echo "=> Node.js version $NODE_VERSION has been successfully installed"
|
||||
if [ "$(nvm_version "$NODE_VERSION_LOCAL")" == "$CURRENT_NVM_NODE" ]; then
|
||||
echo "=> Node.js version $NODE_VERSION_LOCAL has been successfully installed"
|
||||
else
|
||||
echo >&2 "Failed to install Node.js $NODE_VERSION"
|
||||
echo >&2 "Failed to install Node.js $NODE_VERSION_LOCAL"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
64
nvm.sh
64
nvm.sh
@@ -13,13 +13,7 @@
|
||||
NVM_SCRIPT_SOURCE="$_"
|
||||
|
||||
nvm_echo() {
|
||||
command printf %s\\n "$*" 2>/dev/null || {
|
||||
nvm_echo() {
|
||||
# shellcheck disable=SC1001
|
||||
\printf %s\\n "$*" # on zsh, `command printf` sometimes fails
|
||||
}
|
||||
nvm_echo "$@"
|
||||
}
|
||||
command printf %s\\n "$*" 2>/dev/null
|
||||
}
|
||||
|
||||
nvm_cd() {
|
||||
@@ -212,13 +206,13 @@ nvm_install_latest_npm() {
|
||||
NVM_IS_4_4_OR_BELOW=1
|
||||
fi
|
||||
|
||||
if $NVM_IS_4_4_OR_BELOW -eq 1 || (\
|
||||
if [ $NVM_IS_4_4_OR_BELOW -eq 1 ] || (\
|
||||
nvm_version_greater_than_or_equal_to "${NODE_VERSION}" 5.0.0 \
|
||||
&& nvm_version_greater 5.10.0 "${NODE_VERSION}"\
|
||||
); then
|
||||
nvm_echo '* `npm` `v5.3.x` is the last version that works on `node` 4.x versions below v4.4, or 5.x versions below v5.10, due to `Buffer.alloc`'
|
||||
$NVM_NPM_CMD install -g npm@5.3
|
||||
elif $NVM_IS_4_4_OR_BELOW -eq 0 && nvm_version_greater 4.7.0 "${NODE_VERSION}"; then
|
||||
elif [ $NVM_IS_4_4_OR_BELOW -eq 0 ] && nvm_version_greater 4.7.0 "${NODE_VERSION}"; then
|
||||
nvm_echo '* `npm` `v5.4.x` is the last version that works on `node` `v4.5` and `v4.6`'
|
||||
$NVM_NPM_CMD install -g npm@5.4
|
||||
else
|
||||
@@ -273,12 +267,12 @@ nvm_tree_contains_path() {
|
||||
|
||||
# Traverse up in directory tree to find containing folder
|
||||
nvm_find_up() {
|
||||
local path
|
||||
path="${PWD}"
|
||||
while [ "${path}" != "" ] && [ ! -f "${path}/${1-}" ]; do
|
||||
path=${path%/*}
|
||||
local path_
|
||||
path_="${PWD}"
|
||||
while [ "${path_}" != "" ] && [ ! -f "${path_}/${1-}" ]; do
|
||||
path_=${path_%/*}
|
||||
done
|
||||
nvm_echo "${path}"
|
||||
nvm_echo "${path_}"
|
||||
}
|
||||
|
||||
|
||||
@@ -514,6 +508,7 @@ nvm_remote_versions() {
|
||||
local NVM_LS_REMOTE_IOJS_EXIT_CODE
|
||||
NVM_LS_REMOTE_IOJS_EXIT_CODE=0
|
||||
local NVM_LS_REMOTE_IOJS_OUTPUT
|
||||
NVM_LS_REMOTE_IOJS_OUTPUT=''
|
||||
if [ -z "${NVM_LTS-}" ] && ( \
|
||||
[ -z "${NVM_FLAVOR-}" ] || [ "${NVM_FLAVOR-}" = "${NVM_IOJS_PREFIX}" ] \
|
||||
); then
|
||||
@@ -2116,19 +2111,35 @@ nvm_die_on_prefix() {
|
||||
return 2
|
||||
fi
|
||||
|
||||
if [ -n "${PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$PREFIX" >/dev/null 2>&1); then
|
||||
# npm first looks at $PREFIX (case-sensitive)
|
||||
# we do not bother to test the value here; if this env var is set, unset it to continue.
|
||||
if [ -n "${PREFIX-}" ]; then
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
nvm_err "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"$PREFIX\""
|
||||
nvm_err "nvm is not compatible with the \"PREFIX\" environment variable: currently set to \"${PREFIX}\""
|
||||
nvm_err 'Run `unset PREFIX` to unset it.'
|
||||
return 3
|
||||
fi
|
||||
|
||||
if [ -n "${NPM_CONFIG_PREFIX-}" ] && ! (nvm_tree_contains_path "$NVM_DIR" "$NPM_CONFIG_PREFIX" >/dev/null 2>&1); then
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
nvm_err "nvm is not compatible with the \"NPM_CONFIG_PREFIX\" environment variable: currently set to \"$NPM_CONFIG_PREFIX\""
|
||||
nvm_err 'Run `unset NPM_CONFIG_PREFIX` to unset it.'
|
||||
return 4
|
||||
elif ! nvm_has 'npm'; then
|
||||
# npm normalizes NPM_CONFIG_-prefixed env vars
|
||||
# https://github.com/npm/npmconf/blob/22827e4038d6eebaafeb5c13ed2b92cf97b8fb82/npmconf.js#L331-L348
|
||||
# https://github.com/npm/npm/blob/5e426a78ca02d0044f8dd26e0c5f881217081cbd/lib/config/core.js#L343-L359
|
||||
#
|
||||
# here, we avoid trying to replicate "which one wins" or testing the value; if any are defined, it errors
|
||||
# until none are left.
|
||||
local NVM_NPM_CONFIG_PREFIX_ENV
|
||||
NVM_NPM_CONFIG_PREFIX_ENV="$(command env | nvm_grep -i NPM_CONFIG_PREFIX | command tail -1 | command awk -F '=' '{print $1}')"
|
||||
if [ -n "${NVM_NPM_CONFIG_PREFIX_ENV-}" ]; then
|
||||
local NVM_CONFIG_VALUE
|
||||
eval "NVM_CONFIG_VALUE=\"\$${NVM_NPM_CONFIG_PREFIX_ENV}\""
|
||||
if [ -n "${NVM_CONFIG_VALUE-}" ]; then
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
nvm_err "nvm is not compatible with the \"${NVM_NPM_CONFIG_PREFIX_ENV}\" environment variable: currently set to \"${NVM_CONFIG_VALUE}\""
|
||||
nvm_err "Run \`unset ${NVM_NPM_CONFIG_PREFIX_ENV}\` to unset it."
|
||||
return 4
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! nvm_has 'npm'; then
|
||||
return
|
||||
fi
|
||||
|
||||
@@ -2363,9 +2374,9 @@ nvm() {
|
||||
local DIR
|
||||
DIR="$(nvm_cache_dir)"
|
||||
if command rm -rf "${DIR}" && command mkdir -p "${DIR}"; then
|
||||
nvm_echo 'Cache cleared.'
|
||||
nvm_echo 'nvm cache cleared.'
|
||||
else
|
||||
nvm_err "Unable to clear cache: ${DIR}"
|
||||
nvm_err "Unable to clear nvm cache: ${DIR}"
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
@@ -2907,6 +2918,7 @@ nvm() {
|
||||
command rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current"
|
||||
fi
|
||||
local NVM_USE_OUTPUT
|
||||
NVM_USE_OUTPUT=''
|
||||
if [ $NVM_USE_SILENT -ne 1 ]; then
|
||||
if nvm_is_iojs_version "$VERSION"; then
|
||||
NVM_USE_OUTPUT="Now using io.js $(nvm_strip_iojs_prefix "$VERSION")$(nvm_print_npm_version)"
|
||||
@@ -3346,7 +3358,7 @@ nvm() {
|
||||
;;
|
||||
"clear-cache" )
|
||||
command rm -f "$NVM_DIR/v*" "$(nvm_version_dir)" 2>/dev/null
|
||||
nvm_echo 'Cache cleared.'
|
||||
nvm_echo 'nvm cache cleared.'
|
||||
;;
|
||||
"version" )
|
||||
nvm_version "${1}"
|
||||
@@ -3387,7 +3399,7 @@ nvm() {
|
||||
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
||||
;;
|
||||
"--version" )
|
||||
nvm_echo '0.33.6'
|
||||
nvm_echo '0.33.8'
|
||||
;;
|
||||
"unload" )
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.33.6",
|
||||
"version": "0.33.8",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
set -eux
|
||||
|
||||
cleanup() {
|
||||
unset -f nvm_has_system_node nvm_print_npm_version
|
||||
|
||||
@@ -46,17 +46,24 @@ OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
|
||||
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
|
||||
EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
|
||||
Run `unset PREFIX` to unset it.'
|
||||
EXIT_CODE="$(PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
|
||||
EXIT_CODE="$(export PREFIX=bar ; nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_3" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 3; got '$EXIT_CODE'"
|
||||
|
||||
OUTPUT="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo 2>&1)"
|
||||
OUTPUT="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo 2>&1)"
|
||||
EXPECTED_OUTPUT='nvm is not compatible with the "NPM_CONFIG_PREFIX" environment variable: currently set to "bar"
|
||||
Run `unset NPM_CONFIG_PREFIX` to unset it.'
|
||||
EXIT_CODE="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
|
||||
EXIT_CODE="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_4" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
|
||||
|
||||
OUTPUT="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo 2>&1)"
|
||||
EXPECTED_OUTPUT='nvm is not compatible with the "npm_CONFIG_PREFIX" environment variable: currently set to "bar"
|
||||
Run `unset npm_CONFIG_PREFIX` to unset it.'
|
||||
EXIT_CODE="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_4" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
|
||||
|
||||
npm() {
|
||||
local args
|
||||
args="$@"
|
||||
|
||||
@@ -21,6 +21,7 @@ rm -rf "$TEST_DIR"
|
||||
mkdir "$TEST_DIR"
|
||||
ln -s "$(command which which)" "$TEST_DIR/which"
|
||||
ln -s "$(command which dirname)" "$TEST_DIR/dirname"
|
||||
ln -s "$(command which printf)" "$TEST_DIR/printf"
|
||||
|
||||
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"'
|
||||
[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'
|
||||
|
||||
8
test/install_script/nvm_install_with_node_version
Executable file
8
test/install_script/nvm_install_with_node_version
Executable file
@@ -0,0 +1,8 @@
|
||||
#!/bin/sh
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
NODE_VERSION=8 \. ../../install.sh
|
||||
|
||||
# nvm installed node 8
|
||||
nvm ls 8 > /dev/null 2>&1 || die "nvm didn't install node 8"
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -ex
|
||||
set -eux
|
||||
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user