Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4054bd70ce | ||
|
|
499d303746 | ||
|
|
31bc0a13c2 | ||
|
|
c72f2c6f21 | ||
|
|
f2c5ce459a | ||
|
|
0f0d5e8270 | ||
|
|
e77ed07ccc | ||
|
|
e01060fa2c | ||
|
|
96069da0d5 | ||
|
|
4436638816 | ||
|
|
344cc32ac3 | ||
|
|
7929190e6e |
@@ -1,6 +1,5 @@
|
||||
language: generic
|
||||
dist: xenial
|
||||
sudo: required
|
||||
addons:
|
||||
apt:
|
||||
packages:
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
# Please note that it'll use about 1.2 GB disk space and about 15 minutes to
|
||||
# build this image, it depends on your hardware.
|
||||
|
||||
# Use Ubuntu Trusty Tahr as base image as we're using on Travis CI
|
||||
# I also tested with Ubuntu 16.04, should be good with it!
|
||||
FROM ubuntu:16.04
|
||||
LABEL maintainer="Peter Dave Hello <hsu@peterdavehello.org>"
|
||||
LABEL name="nvm-dev-env"
|
||||
@@ -66,7 +64,6 @@ RUN apt update && \
|
||||
bash-completion && \
|
||||
apt-get clean
|
||||
|
||||
# ShellCheck with Ubuntu 14.04 container workaround
|
||||
RUN wget https://github.com/koalaman/shellcheck/releases/download/v$SHELLCHECK_VERSION/shellcheck-v$SHELLCHECK_VERSION.linux.x86_64.tar.xz -O- | \
|
||||
tar xJvf - shellcheck-v$SHELLCHECK_VERSION/shellcheck && \
|
||||
mv shellcheck-v$SHELLCHECK_VERSION/shellcheck /bin && \
|
||||
|
||||
21
README.md
21
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)
|
||||
|
||||
<!-- To update this table of contents, ensure you have run `npm install` then `npm run doctoc` -->
|
||||
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
||||
@@ -59,10 +59,10 @@ nvm is a version manager for [node.js](https://nodejs.org/en/), designed to be i
|
||||
|
||||
To **install** or **update** nvm, you should run the [install script][2]. To do that, you may either download and run the script manually, or use the following cURL or Wget command:
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
|
||||
```
|
||||
```sh
|
||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
|
||||
```
|
||||
|
||||
Running either of the above commands downloads a script and runs it. The script clones the nvm repository to `~/.nvm`, and attempts to add the source lines from the snippet below to the correct profile file (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).
|
||||
@@ -115,7 +115,7 @@ You can use a task:
|
||||
```yaml
|
||||
- name: nvm
|
||||
shell: >
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/install.sh | bash
|
||||
args:
|
||||
creates: "{{ ansible_env.HOME }}/.nvm/nvm.sh"
|
||||
```
|
||||
@@ -174,7 +174,7 @@ If you have `git` installed (requires git v1.7.10+):
|
||||
|
||||
1. clone this repo in the root of your user profile
|
||||
- `cd ~/` from anywhere then `git clone https://github.com/nvm-sh/nvm.git .nvm`
|
||||
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.36.0`
|
||||
1. `cd ~/.nvm` and check out the latest version with `git checkout v0.37.0`
|
||||
1. 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:
|
||||
@@ -463,7 +463,7 @@ If you prefer a lighter-weight solution, the recipes below have been contributed
|
||||
Put the following at the end of your `$HOME/.bashrc`:
|
||||
|
||||
```bash
|
||||
find-up () {
|
||||
find-up() {
|
||||
path=$(pwd)
|
||||
while [[ "$path" != "" && ! -e "$path/$1" ]]; do
|
||||
path=${path%/*}
|
||||
@@ -471,7 +471,7 @@ find-up () {
|
||||
echo "$path"
|
||||
}
|
||||
|
||||
cdnvm(){
|
||||
cdnvm() {
|
||||
cd "$@";
|
||||
nvm_path=$(find-up .nvmrc | tr -d '\n')
|
||||
|
||||
@@ -514,6 +514,7 @@ cdnvm(){
|
||||
fi
|
||||
}
|
||||
alias cd='cdnvm'
|
||||
cd $PWD
|
||||
```
|
||||
|
||||
This alias would search 'up' from your current directory in order to detect a `.nvmrc` file. If it finds it, it will switch to that version; if not, it will use the default version.
|
||||
@@ -721,7 +722,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/nvm-sh/nvm/v0.36.0/install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.0/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.
|
||||
@@ -818,8 +819,8 @@ You have to make sure that the user directory name in `$HOME` and the user direc
|
||||
To change the user directory and/or account name follow the instructions [here](https://support.apple.com/en-us/HT201548)
|
||||
|
||||
[1]: https://github.com/nvm-sh/nvm.git
|
||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.36.0/install.sh
|
||||
[2]: https://github.com/nvm-sh/nvm/blob/v0.37.0/install.sh
|
||||
[3]: https://travis-ci.org/nvm-sh/nvm
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.36.0
|
||||
[4]: https://github.com/nvm-sh/nvm/releases/tag/v0.37.0
|
||||
[Urchin]: https://github.com/scraperwiki/urchin
|
||||
[Fish]: http://fishshell.com
|
||||
|
||||
@@ -19,7 +19,7 @@ nvm_install_dir() {
|
||||
}
|
||||
|
||||
nvm_latest_version() {
|
||||
echo "v0.36.0"
|
||||
echo "v0.37.0"
|
||||
}
|
||||
|
||||
nvm_profile_is_bash_or_zsh() {
|
||||
|
||||
116
nvm.sh
116
nvm.sh
@@ -1089,6 +1089,7 @@ nvm_ls() {
|
||||
esac
|
||||
|
||||
nvm_is_zsh && setopt local_options shwordsplit
|
||||
nvm_is_zsh && unsetopt local_options markdirs
|
||||
|
||||
local NVM_DIRS_TO_SEARCH1
|
||||
NVM_DIRS_TO_SEARCH1=''
|
||||
@@ -1239,6 +1240,10 @@ nvm_ls_remote_index_tab() {
|
||||
local PATTERN
|
||||
PATTERN="${3-}"
|
||||
|
||||
if [ "${PATTERN#"${PATTERN%?}"}" = '.' ]; then
|
||||
PATTERN="${PATTERN%.}"
|
||||
fi
|
||||
|
||||
local VERSIONS
|
||||
if [ -n "${PATTERN}" ] && [ "${PATTERN}" != '*' ]; then
|
||||
if [ "${FLAVOR}" = 'iojs' ]; then
|
||||
@@ -2175,6 +2180,15 @@ nvm_npm_global_modules() {
|
||||
nvm_echo "${INSTALLS} //// ${LINKS}"
|
||||
}
|
||||
|
||||
nvm_npmrc_bad_news_bears() {
|
||||
local NVM_NPMRC
|
||||
NVM_NPMRC="${1-}"
|
||||
if [ -n "${NVM_NPMRC}" ] && [ -f "${NVM_NPMRC}" ] && nvm_grep -Ee '^(prefix|globalconfig) *=' <"${NVM_NPMRC}" >/dev/null; then
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
nvm_die_on_prefix() {
|
||||
local NVM_DELETE_PREFIX
|
||||
NVM_DELETE_PREFIX="${1-}"
|
||||
@@ -2222,29 +2236,70 @@ nvm_die_on_prefix() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! nvm_has 'npm'; then
|
||||
return
|
||||
# here, npm config checks npmrc files.
|
||||
# the stack is: cli, env, project, user, global, builtin, defaults
|
||||
# cli does not apply; env is covered above, defaults don't exist for prefix
|
||||
# there are 4 npmrc locations to check: project, global, user, and builtin
|
||||
# project: find the closest node_modules or package.json-containing dir, `.npmrc`
|
||||
# global: default prefix + `/etc/npmrc`
|
||||
# user: $HOME/.npmrc
|
||||
# builtin: npm install location, `npmrc`
|
||||
#
|
||||
# if any of them have a `prefix`, fail.
|
||||
# if any have `globalconfig`, fail also, just in case, to avoid spidering configs.
|
||||
|
||||
local NVM_NPM_BUILTIN_NPMRC
|
||||
NVM_NPM_BUILTIN_NPMRC="${NVM_VERSION_DIR}/lib/node_modules/npm/npmrc"
|
||||
if nvm_npmrc_bad_news_bears "${NVM_NPM_BUILTIN_NPMRC}"; then
|
||||
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
|
||||
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_BUILTIN_NPMRC}"
|
||||
else
|
||||
nvm_err "Your builtin npmrc file ($(nvm_sanitize_path "${NVM_NPM_BUILTIN_NPMRC}"))"
|
||||
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||
return 10
|
||||
fi
|
||||
fi
|
||||
|
||||
local NVM_NPM_PREFIX
|
||||
local NVM_OS
|
||||
NVM_OS="$(nvm_get_os)"
|
||||
NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"
|
||||
if [ "${NVM_VERSION_DIR}" != "${NVM_NPM_PREFIX}" ] && ! (nvm_tree_contains_path "${NVM_VERSION_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then
|
||||
local NVM_NPM_GLOBAL_NPMRC
|
||||
NVM_NPM_GLOBAL_NPMRC="${NVM_VERSION_DIR}/etc/npmrc"
|
||||
if nvm_npmrc_bad_news_bears "${NVM_NPM_GLOBAL_NPMRC}"; then
|
||||
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||
npm config --global --loglevel=warn delete prefix
|
||||
npm config --global --loglevel=warn delete globalconfig
|
||||
else
|
||||
nvm_err "Your global npmrc file ($(nvm_sanitize_path "${NVM_NPM_GLOBAL_NPMRC}"))"
|
||||
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||
return 10
|
||||
fi
|
||||
fi
|
||||
|
||||
local NVM_NPM_USER_NPMRC
|
||||
NVM_NPM_USER_NPMRC="${HOME}/.npmrc"
|
||||
if nvm_npmrc_bad_news_bears "${NVM_NPM_USER_NPMRC}"; then
|
||||
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||
npm config --loglevel=warn delete prefix --userconfig="${NVM_NPM_USER_NPMRC}"
|
||||
npm config --loglevel=warn delete globalconfig --userconfig="${NVM_NPM_USER_NPMRC}"
|
||||
else
|
||||
nvm_err "Your user’s .npmrc file ($(nvm_sanitize_path "${NVM_NPM_USER_NPMRC}"))"
|
||||
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||
return 10
|
||||
fi
|
||||
fi
|
||||
|
||||
local NVM_NPM_PROJECT_NPMRC
|
||||
NVM_NPM_PROJECT_NPMRC="$(nvm_find_project_dir)/.npmrc"
|
||||
if nvm_npmrc_bad_news_bears "${NVM_NPM_PROJECT_NPMRC}"; then
|
||||
if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then
|
||||
npm config --loglevel=warn delete prefix
|
||||
npm config --loglevel=warn delete globalconfig
|
||||
else
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
nvm_err "nvm is not compatible with the npm config \"prefix\" option: currently set to \"${NVM_NPM_PREFIX}\""
|
||||
if nvm_has 'npm'; then
|
||||
nvm_err "Run \`npm config delete prefix\` or \`${NVM_COMMAND}\` to unset it."
|
||||
else
|
||||
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||
fi
|
||||
if [ "${NVM_OS}" = 'darwin' ]; then
|
||||
nvm_err "Make sure your username ($(whoami)) matches the one in your \$HOME path."
|
||||
nvm_err "See the \"macOS Troubleshooting\" section in the docs for more information."
|
||||
fi
|
||||
nvm_err "Your project npmrc file ($(nvm_sanitize_path "${NVM_NPM_PROJECT_NPMRC}"))"
|
||||
nvm_err 'has a `globalconfig` and/or a `prefix` setting, which are incompatible with nvm.'
|
||||
nvm_err "Run \`${NVM_COMMAND}\` to unset it."
|
||||
return 10
|
||||
fi
|
||||
fi
|
||||
@@ -2393,7 +2448,9 @@ nvm() {
|
||||
nvm_echo 'Usage:'
|
||||
nvm_echo ' nvm --help Show this message'
|
||||
nvm_echo ' nvm --version Print out the installed version of nvm'
|
||||
nvm_echo ' nvm install [-s] [<version>] Download and install a <version>, [-s] from source. Uses .nvmrc if available'
|
||||
nvm_echo ' nvm install [<version>] Download and install a <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm install`:'
|
||||
nvm_echo ' -s Skip binary download, install from source only.'
|
||||
nvm_echo ' --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>'
|
||||
nvm_echo ' --lts When installing, only select from LTS (long-term support) versions'
|
||||
nvm_echo ' --lts=<LTS name> When installing, only select from versions for a specific LTS line'
|
||||
@@ -2405,13 +2462,19 @@ nvm() {
|
||||
nvm_echo ' nvm uninstall <version> Uninstall a version'
|
||||
nvm_echo ' nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm use [--silent] [<version>] Modify PATH to use <version>. Uses .nvmrc if available'
|
||||
nvm_echo ' nvm use [<version>] Modify PATH to use <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm use`:'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm exec [--silent] [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available'
|
||||
nvm_echo ' nvm exec [<version>] [<command>] Run <command> on <version>. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm exec`:'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm run [--silent] [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available'
|
||||
nvm_echo ' nvm run [<version>] [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' The following optional arguments, if provided, must appear directly after `nvm run`:'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.'
|
||||
nvm_echo ' --lts=<LTS name> Uses automatic alias for provided LTS line, if available.'
|
||||
nvm_echo ' nvm current Display currently activated version of Node'
|
||||
@@ -2426,7 +2489,8 @@ nvm() {
|
||||
nvm_echo ' nvm version-remote <version> Resolve the given description to a single remote version'
|
||||
nvm_echo ' --lts When listing, only select from LTS (long-term support) versions'
|
||||
nvm_echo ' --lts=<LTS name> When listing, only select from versions for a specific LTS line'
|
||||
nvm_echo ' nvm deactivate [--silent] Undo effects of `nvm` on current shell'
|
||||
nvm_echo ' nvm deactivate Undo effects of `nvm` on current shell'
|
||||
nvm_echo ' --silent Silences stdout/stderr output'
|
||||
nvm_echo ' nvm alias [<pattern>] Show all aliases beginning with <pattern>'
|
||||
nvm_echo ' --no-colors Suppress colored output'
|
||||
nvm_echo ' nvm alias <name> <version> Set an alias named <name> pointing to <version>'
|
||||
@@ -2434,7 +2498,8 @@ nvm() {
|
||||
nvm_echo ' nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version'
|
||||
nvm_echo ' nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version'
|
||||
nvm_echo ' nvm unload Unload `nvm` from shell'
|
||||
nvm_echo ' nvm which [--silent] [current | <version>] Display path to installed node version. Uses .nvmrc if available'
|
||||
nvm_echo ' nvm which [current | <version>] Display path to installed node version. Uses .nvmrc if available and version is omitted.'
|
||||
nvm_echo ' --silent Silences stdout/stderr output when a version is omitted'
|
||||
nvm_echo ' nvm cache dir Display path to the cache directory for nvm'
|
||||
nvm_echo ' nvm cache clear Empty cache directory for nvm'
|
||||
nvm_echo
|
||||
@@ -3647,7 +3712,7 @@ nvm() {
|
||||
NVM_VERSION_ONLY=true NVM_LTS="${NVM_LTS-}" nvm_remote_version "${PATTERN:-node}"
|
||||
;;
|
||||
"--version" | "-v")
|
||||
nvm_echo '0.36.0'
|
||||
nvm_echo '0.37.0'
|
||||
;;
|
||||
"unload")
|
||||
nvm deactivate >/dev/null 2>&1
|
||||
@@ -3688,6 +3753,7 @@ nvm() {
|
||||
nvm_sanitize_path nvm_has_colors nvm_process_parameters \
|
||||
nvm_node_version_has_solaris_binary nvm_iojs_version_has_solaris_binary \
|
||||
nvm_curl_libz_support nvm_command_info nvm_is_zsh nvm_stdout_is_terminal \
|
||||
nvm_npmrc_bad_news_bears \
|
||||
>/dev/null 2>&1
|
||||
unset NVM_RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_IOJS_ORG_MIRROR NVM_DIR \
|
||||
NVM_CD_FLAGS NVM_BIN NVM_INC NVM_MAKE_JOBS \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "nvm",
|
||||
"version": "0.36.0",
|
||||
"version": "0.37.0",
|
||||
"description": "Node Version Manager - Simple bash script to manage multiple active node.js versions",
|
||||
"directories": {
|
||||
"test": "test"
|
||||
@@ -37,10 +37,10 @@
|
||||
"homepage": "https://github.com/nvm-sh/nvm",
|
||||
"devDependencies": {
|
||||
"dockerfile_lint": "^0.3.2",
|
||||
"doctoc": "^1.2.0",
|
||||
"eclint": "^2.6.0",
|
||||
"replace": "^0.3.0",
|
||||
"semver": "^5.0.1",
|
||||
"urchin": "^0.0.5",
|
||||
"doctoc": "^1.2.0"
|
||||
"urchin": "^0.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
40
test/fast/Listing versions/Running "nvm ls" should not show a trailing slash
Executable file
40
test/fast/Listing versions/Running "nvm ls" should not show a trailing slash
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/bin/zsh
|
||||
|
||||
\. ../../../nvm.sh
|
||||
\. ../../common.sh
|
||||
|
||||
if type setopt >/dev/null 2>&1; then setopt local_options markdirs; fi
|
||||
|
||||
die () {
|
||||
if type unsetopt >/dev/null 2>&1; then unsetopt local_options markdirs; fi
|
||||
echo "$@";
|
||||
exit 1;
|
||||
}
|
||||
|
||||
make_fake_node v0.0.1
|
||||
make_fake_node v0.0.3
|
||||
make_fake_node v0.0.9
|
||||
make_fake_node v0.3.1
|
||||
make_fake_node v0.3.3
|
||||
make_fake_node v0.3.9
|
||||
make_fake_node v0.12.87
|
||||
make_fake_node v0.12.9
|
||||
make_fake_iojs v0.1.2
|
||||
make_fake_iojs v0.10.2
|
||||
|
||||
OUTPUT="$(nvm_ls)"
|
||||
EXPECTED_OUTPUT="v0.0.1
|
||||
v0.0.3
|
||||
v0.0.9
|
||||
iojs-v0.1.2
|
||||
v0.3.1
|
||||
v0.3.3
|
||||
v0.3.9
|
||||
iojs-v0.10.2
|
||||
v0.12.9
|
||||
v0.12.87"
|
||||
if nvm_has_system_node || nvm_has_system_iojs; then
|
||||
EXPECTED_OUTPUT="${EXPECTED_OUTPUT}
|
||||
system"
|
||||
fi
|
||||
[ "${OUTPUT-}" = "${EXPECTED_OUTPUT-}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
||||
@@ -5,7 +5,7 @@ set -ex
|
||||
BEFORE="./before.tmp"
|
||||
AFTER="./after.tmp"
|
||||
|
||||
cleanup () { echo rm -f "${BEFORE}" "${AFTER}"; }
|
||||
cleanup () { rm -f "${BEFORE}" "${AFTER}"; }
|
||||
die () { echo "$@" ; cleanup ; exit 1; }
|
||||
|
||||
typeset -f | awk '/ \(\) $/ && !/^main / {print $1}' > "${BEFORE}"
|
||||
|
||||
@@ -1,13 +1,26 @@
|
||||
#!/bin/sh
|
||||
|
||||
TEST_PWD=$(pwd)
|
||||
TEST_DIR="$TEST_PWD/nvm_die_on_prefix_tmp"
|
||||
|
||||
\. ../../../nvm.sh
|
||||
|
||||
TEST_VERSION_DIR="${TEST_DIR}/version"
|
||||
|
||||
cleanup () {
|
||||
rm -rf "$TEST_DIR"
|
||||
alias nvm_has='\nvm_has'
|
||||
alias npm='\npm'
|
||||
unset -f nvm_has npm
|
||||
}
|
||||
die () { echo "$@" ; exit 1; }
|
||||
|
||||
\. ../../../nvm.sh
|
||||
die () {
|
||||
echo "$@";
|
||||
cleanup;
|
||||
exit 1;
|
||||
}
|
||||
|
||||
[ ! -e "$TEST_DIR" ] && mkdir "$TEST_DIR"
|
||||
|
||||
OUTPUT="$(nvm_die_on_prefix 2>&1)"
|
||||
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
|
||||
@@ -33,15 +46,22 @@ OUTPUT="$(nvm_die_on_prefix 0 version_dir foo 2>&1)"
|
||||
|
||||
nvm_has() { return 0; }
|
||||
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
||||
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
|
||||
|
||||
mkdir -p "$(nvm_version_dir new)"
|
||||
ln -s "$(nvm_version_dir new)" "$TEST_DIR/node"
|
||||
|
||||
npm() {
|
||||
local args
|
||||
args="$@"
|
||||
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
|
||||
echo "$(nvm_version_dir new)/good prefix"
|
||||
echo "$TEST_DIR/node"
|
||||
fi
|
||||
}
|
||||
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
||||
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
|
||||
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when directory is equivalent; got '$OUTPUT'"
|
||||
|
||||
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
||||
EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
|
||||
@@ -64,18 +84,106 @@ EXIT_CODE="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_versi
|
||||
[ "_$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="$@"
|
||||
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
|
||||
echo "./bad prefix"
|
||||
fi
|
||||
}
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
||||
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\"
|
||||
Run \`npm config delete prefix\` or \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'"
|
||||
# npmrc tests
|
||||
(
|
||||
cd "${TEST_DIR}"
|
||||
touch package.json
|
||||
|
||||
# project: prefix
|
||||
echo 'prefix=garbage' > .npmrc
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your project npmrc file ($(nvm_sanitize_path "${TEST_DIR}")/.npmrc)
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
# project: globalconfig
|
||||
echo 'globalconfig=garbage' > .npmrc
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your project npmrc file ($(nvm_sanitize_path "${TEST_DIR}")/.npmrc)
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with project .npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
rm "${TEST_DIR}/.npmrc" || die '.npmrc could not be removed'
|
||||
|
||||
mkdir -p "${TEST_VERSION_DIR}"
|
||||
GLOBAL_NPMRC="${TEST_VERSION_DIR}/etc/npmrc"
|
||||
mkdir -p "${TEST_VERSION_DIR}/etc"
|
||||
|
||||
BUILTIN_NPMRC="${TEST_VERSION_DIR}/lib/node_modules/npm/npmrc"
|
||||
mkdir -p "${TEST_VERSION_DIR}/lib/node_modules/npm/"
|
||||
|
||||
export HOME="${TEST_VERSION_DIR}"
|
||||
USER_NPMRC="${TEST_VERSION_DIR}/.npmrc"
|
||||
|
||||
# global: prefix
|
||||
echo 'prefix=garbage' > "${GLOBAL_NPMRC}"
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your global npmrc file ($(nvm_sanitize_path "${GLOBAL_NPMRC}"))
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
# global: globalconfig
|
||||
echo 'globalconfig=garbage' > "${GLOBAL_NPMRC}"
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your global npmrc file ($(nvm_sanitize_path "${GLOBAL_NPMRC}"))
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with global npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
rm "${GLOBAL_NPMRC}" || die "${GLOBAL_NPMRC} could not be removed"
|
||||
|
||||
# builtin: prefix
|
||||
echo 'prefix=garbage' > "${BUILTIN_NPMRC}"
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your builtin npmrc file ($(nvm_sanitize_path "${BUILTIN_NPMRC}"))
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
# builtin: globalconfig
|
||||
echo 'globalconfig=garbage' > "${BUILTIN_NPMRC}"
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your builtin npmrc file ($(nvm_sanitize_path "${BUILTIN_NPMRC}"))
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with builtin npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
rm "${BUILTIN_NPMRC}" || die "${BUILTIN_NPMRC} could not be removed"
|
||||
|
||||
# user: prefix
|
||||
echo 'prefix=garbage' > "${USER_NPMRC}"
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your user’s .npmrc file ($(nvm_sanitize_path "${USER_NPMRC}"))
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has prefix did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has prefix did not exit with 10; got '$EXIT_CODE'"
|
||||
|
||||
# user: globalconfig
|
||||
echo 'globalconfig=garbage' > "${USER_NPMRC}"
|
||||
OUTPUT="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" 2>&1)"
|
||||
EXPECTED_OUTPUT="Your user’s .npmrc file ($(nvm_sanitize_path "${USER_NPMRC}"))
|
||||
has a \`globalconfig\` and/or a \`prefix\` setting, which are incompatible with nvm.
|
||||
Run \`foo\` to unset it."
|
||||
EXIT_CODE="$(nvm_die_on_prefix 0 foo "${TEST_VERSION_DIR}" >/dev/null 2>&1; echo $?)"
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has globalconfig did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
||||
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' with user .npmrc that has globalconfig did not exit with 10; got '$EXIT_CODE'"
|
||||
)
|
||||
|
||||
cleanup
|
||||
|
||||
@@ -19,7 +19,8 @@ fi
|
||||
|
||||
rm -rf "$TEST_DIR"
|
||||
mkdir "$TEST_DIR"
|
||||
ln -s "$(command which which)" "$TEST_DIR/which"
|
||||
# Ensure that the system version of which is used, not node_modules/.bin/which
|
||||
ln -s "$(PATH=$(echo $PATH | tr ":" "\n" | grep -v "node_modules/.bin" | tr "\n" ":") command which which)" "$TEST_DIR/which"
|
||||
ln -s "$(command which dirname)" "$TEST_DIR/dirname"
|
||||
ln -s "$(command which printf)" "$TEST_DIR/printf"
|
||||
|
||||
@@ -27,12 +28,12 @@ ln -s "$(command which printf)" "$TEST_DIR/printf"
|
||||
[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'
|
||||
|
||||
echo "#!/bin/bash" > "$TEST_DIR/node"
|
||||
echo "echo 'VERSION FOO!'" > "$TEST_DIR/node"
|
||||
echo "echo 'VERSION FOO!'" >> "$TEST_DIR/node"
|
||||
chmod a+x "$TEST_DIR/node"
|
||||
|
||||
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
|
||||
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
|
||||
|
||||
alias node='node --harmony'
|
||||
[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
|
||||
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
|
||||
|
||||
cleanup
|
||||
|
||||
@@ -40,6 +40,19 @@ v0.3.8"
|
||||
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $OUTPUT"
|
||||
|
||||
OUTPUT="$(nvm_ls_remote 0.3.)"
|
||||
EXPECTED_OUTPUT="v0.3.0
|
||||
v0.3.1
|
||||
v0.3.2
|
||||
v0.3.3
|
||||
v0.3.4
|
||||
v0.3.5
|
||||
v0.3.6
|
||||
v0.3.7
|
||||
v0.3.8"
|
||||
|
||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3. did not output 0.3.x versions; got $OUTPUT"
|
||||
|
||||
# Sanity checks
|
||||
OUTPUT="$(nvm_print_implicit_alias remote stable)"
|
||||
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm_print_implicit_alias remote stable.txt"
|
||||
|
||||
Reference in New Issue
Block a user