Compare commits

..

46 Commits

Author SHA1 Message Date
Jordan Harband
31c68adbcf v0.31.6 2016-08-23 14:36:15 -07:00
Aria Stewart
451b67fe78 Revert %s-formatting for SOURCE_STR when writing to shell profile 2016-08-23 17:32:28 -04:00
Jordan Harband
d179810b25 v0.31.5 2016-08-23 11:12:21 -07:00
Jordan Harband
1ac7e236b1 [New] Add lts/foo support to remote commands.
- `nvm ls-remote`
 - `nvm version-remote`
 - `nvm install`
 - `nvm uninstall`

Document existing support:
 - `nvm use`
 - `nvm exec`
 - `nvm run`

Fixes #1208.
2016-08-23 10:58:00 -07:00
Jordan Harband
681c81ad30 [shellcheck] clean up install.sh 2016-08-23 00:45:38 -07:00
Jordan Harband
2228323c0b [shellcheck] disable intentional violations via comments 2016-08-23 00:31:39 -07:00
Jordan Harband
cbeb654692 [shellcheck] properly quote arguments. 2016-08-23 00:31:36 -07:00
Jordan Harband
24a9c089ff [shellcheck] fix incorrect A && B || C usages. 2016-08-23 00:31:25 -07:00
Jordan Harband
bc4639c1c9 [Docs] add a road map. 2016-08-21 12:11:43 -07:00
Jordan Harband
54cc3a383e [Tests] set -ex options on more tests 2016-08-14 09:48:25 -07:00
Jordan Harband
d3d768adcd Add nvm_get_mirror 2016-08-10 23:09:54 -07:00
Jordan Harband
9c65197b22 Add nvm_get_checksum_alg 2016-08-09 22:24:09 -07:00
Jordan Harband
bd3ca47714 [Fix] nvm unload: ensure all functions are unset 2016-08-11 10:58:16 -07:00
Jordan Harband
ec4efa3ec7 [Refactor] nvm install: remove unused REINSTALL_PACKAGES_FROM argument to inner installation helpers. 2016-08-11 10:42:32 -07:00
Jordan Harband
08cbcf2254 [Fix] when not using xz on merged node versions, use z to extract, not x 2016-08-10 23:26:29 -07:00
Jordan Harband
4aa6902dbe [Refactor] nvm_install_merged_node_binary: reduce nesting, fix var curlies. 2016-08-10 16:57:03 -07:00
Jordan Harband
0678652bd3 [New] nvm ls/nvm ls-remote/nvm alias: add --no-colors 2016-08-09 14:46:19 -07:00
Jordan Harband
206878460c [Refactor] always shift first argument to nvm 2016-08-09 13:33:43 -07:00
Jordan Harband
79270a579c [Refactor] create nvm_list_aliases 2016-08-06 22:33:37 -07:00
Jordan Harband
b6eb565ea1 [Refactor] nvm alias: reorganize so alias listing is done last 2016-08-08 15:50:05 -07:00
Jordan Harband
091c64c7c5 [Refactor] nvm alias: add in ---based argument support. 2016-08-08 13:37:14 -07:00
Jordan Harband
21b8f556b2 [Refactor] nvm alias: use named vars instead of positional args. 2016-08-08 13:21:42 -07:00
Jordan Harband
a3bc4d3e62 [Refactor] nvm alias: shift out the “alias” 2016-08-08 13:18:53 -07:00
Jordan Harband
150ed490d0 [Refactor] use curlies with variables 2016-08-07 23:31:16 -07:00
Peter Dave Hello
364096a3c3 Add trailing newline char to $SOURCE_STR
Line 302/301 `printf "$SOURCE_STR"` is missing a trailing newline char,
while line 281/282 and 285/286 have their own new line char, so I  just
remove the manually added newline char, and add it to the end of the
variable "$SOURCE_STR", so no more manually newline char needed there.
2016-08-05 15:52:01 +08:00
Peter Dave Hello
88fc93a71b Fix nvm dir path in install script, fix #1189 2016-08-05 15:23:09 +08:00
Jordan Harband
f9f140ec13 [Performance] make auto-using faster.
Per https://github.com/creationix/nvm/issues/539#issuecomment-236830764
2016-08-02 00:59:51 -07:00
Luke Childs
f653bdc606 Print shell version on Travis 2016-07-31 21:14:30 +01:00
Jordan Harband
31e58d1827 v0.31.4 2016-07-29 16:54:13 -07:00
Julien Gilli
a32b914bab Fix nvm on SmartOS setups using 64 bits pkgsrc repository
On SmartOS setups using 64 bits pkgsrc repositories, `nvm_get_arch`
would not handle pkg_info's output properly.

This would result in nvm not being to install any node binary when
running on SmartOS setups using a 64 bits pkgsrc repository.

This change fixes this problem, and fixes the tests suite on similar
setups.
2016-07-29 14:08:31 -07:00
Joe Lencioni
f51b1bf8ae Document required git version
git-describe was taught `--abbrev=0` in 1.5.0:

  https://github.com/git/git/blob/master/Documentation/RelNotes/1.5.0.txt

git-describe was taught `--match` in 1.5.5:

  https://github.com/git/git/blob/master/Documentation/RelNotes/1.5.5.txt

I don't see anything else potentially weird in here, so I think it is
safe to proclaim that the minimum git version required to run these
commands is 1.5.5.

Documenting this minimum version required here should help people debug
possible issues and help maintainers of this project understand the
impacts of modifying these commands in the future.
2016-07-28 10:51:00 -07:00
Jordan Harband
c874a17479 Merge pull request #1179 from lencioni/improve-upgrade-instructions
[Docs] Improve installation and upgrade instructions
2016-07-28 10:41:31 -07:00
Joe Lencioni
6eef4ce4d2 Use NVM_DIR in installation instructions
As suggested by @ljharb, this might be a little cleaner. I'm not
entirely sure, but in any case, it is consistent with the upgrade
instructions, so that is nice.
2016-07-28 10:36:51 -07:00
Joe Lencioni
54476476ab Use subshells for installation and upgrade instructions
I recently upgraded my copy of nvm and I was disappointed to be dropped
in the .nvm directory at the end of it. I also didn't like having to
copy and paste two separate blocks of code into my terminal, because I
missed the second one the first time around and was left in a slightly
confusing state. So, I decided to make this easier by utilizing
subshells and moving all of the instructions into one code block in this
document. I think this will improve people's experience maintaining this
tool.
2016-07-28 10:36:51 -07:00
Joe Lencioni
87a3a4425d Ensure git describe only matches version tags
`git describe` will match the latest tags, regardless of what it looks
like. We can make this a little safer by adding a `--match` flag to
match tags that look like version tags. This allows the maintainers of
this repo to more safely add other types of tags if they so wish,
without causing people to install or upgrade to those versions.
2016-07-28 10:36:51 -07:00
Joe Lencioni
17a3272b8a Ensure git describe gives latest tag
I recently ran the upgrade instructions and I ended up with the version
I was already on. This happened because `git describe` describes a
commit using the most recent tag reachable from it. Since I already had
a tag checked out, it was describing the tag I had already checked out.

Thankfully, `git describe` accepts an optional commit-ish, which it will
use instead of what we have currently checked out. Testing this in my
terminal now gives me the latest tag on origin, which is what I am
interested in when updating to the latest version.

  ~/.nvm ❯❯❯ git describe --abbrev=0 --tags
  v0.30.1
  ~/.nvm ❯❯❯ git describe --abbrev=0 --tags origin
  v0.31.3

I also added it to the manual install instructions for consistency and
extra safety.
2016-07-28 10:36:51 -07:00
Luke Childs
c08010f610 Fix typo in readme 2016-07-28 17:48:23 +01:00
Jordan Harband
2ee8ec886f Merge pull request #1178 from lukechilds/installation-improvements
Installation improvements
2016-07-28 08:49:28 -07:00
Luke Childs
978f7b4435 Only source nvm, not entire profile 2016-07-27 22:44:51 +01:00
Luke Childs
3417e9d9a3 Add message explaining how to use nvm 2016-07-27 22:39:50 +01:00
Luke Childs
eb4de62bc1 Remove incorrect message 2016-07-27 21:43:13 +01:00
Jordan Harband
8a199e00a2 Merge pull request #1173 from wiserweb/master
[Docs] Specify the lines that will be added by the installation script
2016-07-26 08:30:56 -07:00
wiserweb
6ac7ecf7dc Update README.markdown
Specifies the lines that will be added by the installation script.
2016-07-26 02:31:07 -04:00
Luke Childs
a09f225ec7 Update zsh-nvm upgrade command in readme 2016-07-24 21:13:51 +01:00
Jordan Harband
e0e1c0379a Merge pull request #1163 from sebthom/patch-1
[Fix] fix "find: warning: Unix filenames usually don't contain slashes" warning

Fixes #871.
2016-07-20 10:30:47 -07:00
Sebastian Thomschke
f4d57cc17d Fix for #871 find: warning: Unix filenames usually don't contain slashes 2016-07-20 13:31:47 +02:00
15 changed files with 702 additions and 454 deletions

View File

@@ -4,6 +4,7 @@ addons:
- zsh - zsh
- ksh - ksh
before_install: before_install:
- $SHELL --version 2> /dev/null || dpkg -s $SHELL 2> /dev/null || which $SHELL
- curl --version - curl --version
- wget --version - wget --version
install: install:

View File

@@ -9,7 +9,7 @@ Note: `nvm` does not support Windows (see [#284](https://github.com/creationix/n
- [nodist](https://github.com/marcelklehr/nodist) - [nodist](https://github.com/marcelklehr/nodist)
Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creationix/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us: Note: `nvm` does not support [Fish] either (see [#303](https://github.com/creationix/nvm/issues/303)). Alternatives exist, which are neither supported nor developed by us:
- [bass](https://github.com/edc/bass) allows to use utilities written for Bash in fish shell - [bass](https://github.com/edc/bass) allows you to use utilities written for Bash in fish shell
- [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup - [fast-nvm-fish](https://github.com/brigand/fast-nvm-fish) only works with version numbers (not aliases) but doesn't significantly slow your shell startup
- [fin](https://github.com/fisherman/fin) is a pure fish node version manager for fish shell - [fin](https://github.com/fisherman/fin) is a pure fish node version manager for fish shell
- [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell - [plugin-nvm](https://github.com/derekstavis/plugin-nvm) plugin for [Oh My Fish](https://github.com/oh-my-fish/oh-my-fish), which makes nvm and its completions available in fish shell
@@ -30,24 +30,29 @@ Note: On OS X, if you have/had a "system" node installed and want to install mod
Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue. Homebrew installation is not supported. If you have issues with homebrew-installed `nvm`, please `brew uninstall` it, and install it using the instructions below, before filing an issue.
Note: If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm_update` to update. Note: If you're using `zsh` you can easily install `nvm` as a zsh plugin. Install [`zsh-nvm`](https://github.com/lukechilds/zsh-nvm) and run `nvm upgrade` to upgrade.
### Install script ### Install script
To install or update nvm, you can use the [install script][2] using cURL: To install or update nvm, you can use the [install script][2] using cURL:
```sh ```sh
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.31.6/install.sh | bash
``` ```
or Wget: or Wget:
```sh ```sh
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | bash wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.6/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> <sub>The script clones the nvm repository to `~/.nvm` and adds the source line to your profile (`~/.bash_profile`, `~/.zshrc`, `~/.profile`, or `~/.bashrc`).</sub>
```sh
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
```
You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables. You can customize the install source, directory, profile, and version using the `NVM_SOURCE`, `NVM_DIR`, `PROFILE`, and `NODE_VERSION` variables.
Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install. Eg: `curl ... | NVM_DIR=/usr/local/nvm bash` for a global install.
@@ -76,16 +81,18 @@ which should output 'nvm' if the installation was successful. Please note that `
For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in `~/.nvm`. For manual install create a folder somewhere in your filesystem with the `nvm.sh` file inside it. I put mine in `~/.nvm`.
Or if you have `git` installed, then just clone it, and check out the latest version: Or if you have `git` installed (requires git v1.5.5+):
1. clone this repo
1. check out the latest version
1. activate nvm by sourcing it from your shell
```sh ```sh
git clone https://github.com/creationix/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags` export NVM_DIR="$HOME/.nvm" && (
``` git clone https://github.com/creationix/nvm.git "$NVM_DIR"
cd "$NVM_DIR"
To activate nvm, you need to source it from your shell: git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" origin`
) && . "$NVM_DIR/nvm.sh"
```sh
. ~/.nvm/nvm.sh
``` ```
Add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login: Add these lines to your `~/.bashrc`, `~/.profile`, or `~/.zshrc` file to have it automatically sourced upon login:
@@ -98,16 +105,19 @@ export NVM_DIR="$HOME/.nvm"
### Manual upgrade ### Manual upgrade
For manual upgrade with `git`, change to the `$NVM_DIR`, pull down the latest changes, and check out the latest version: For manual upgrade with `git` (requires git v1.5.5+):
1. change to the `$NVM_DIR`
1. pull down the latest changes
1. check out the latest version
1. activate the new version
```sh ```sh
cd "$NVM_DIR" && git fetch origin && git checkout `git describe --abbrev=0 --tags` (
``` cd "$NVM_DIR"
git fetch origin
After upgrading, don't forget to activate the new version: git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" origin`
) && . "$NVM_DIR/nvm.sh"
```sh
. "$NVM_DIR/nvm.sh"
``` ```
## Usage ## Usage
@@ -150,13 +160,13 @@ In place of a version pointer like "0.10" or "5.0" or "4.2.1", you can use the f
### Long-term support ### Long-term support
Node has a [schedule](https://github.com/nodejs/LTS#lts_schedule) for long-term support (LTS) You can reference LTS versions in aliases and `.nvmrc` files with the notation `lts/*` for the latest LTS, and `lts/argon` for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments: Node has a [schedule](https://github.com/nodejs/LTS#lts_schedule) for long-term support (LTS) You can reference LTS versions in aliases and `.nvmrc` files with the notation `lts/*` for the latest LTS, and `lts/argon` for LTS releases from the "argon" line, for example. In addition, the following commands support LTS arguments:
- `nvm install --lts` / `nvm install --lts=argon` - `nvm install --lts` / `nvm install --lts=argon` / `nvm install 'lts/*'` / `nvm install lts/argon`
- `nvm uninstall --lts` / `nvm uninstall --lts=argon` - `nvm uninstall --lts` / `nvm uninstall --lts=argon` / `nvm uninstall 'lts/*'` / `nvm uninstall lts/argon`
- `nvm use --lts` / `nvm use --lts=argon` - `nvm use --lts` / `nvm use --lts=argon` / `nvm use 'lts/*'` / `nvm use lts/argon`
- `nvm exec --lts` / `nvm exec --lts=argon` - `nvm exec --lts` / `nvm exec --lts=argon` / `nvm exec 'lts/*'` / `nvm exec lts/argon`
- `nvm run --lts` / `nvm run --lts=argon` - `nvm run --lts` / `nvm run --lts=argon` / `nvm run 'lts/*'` / `nvm run lts/argon`
- `nvm ls-remote --lts` / `nvm ls-remote --lts=argon` - `nvm ls-remote --lts` / `nvm ls-remote --lts=argon` `nvm ls-remote 'lts/*'` / `nvm ls-remote lts/argon`
- `nvm version-remote --lts` / `nvm version-remote --lts=argon` - `nvm version-remote --lts` / `nvm version-remote --lts=argon` / `nvm version-remote 'lts/*'` / `nvm version-remote lts/argon`
Any time your local copy of `nvm` connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under `$NVM_DIR/alias/lts`), are managed by `nvm`, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported. Any time your local copy of `nvm` connects to https://nodejs.org, it will re-create the appropriate local aliases for all available LTS lines. These aliases (stored under `$NVM_DIR/alias/lts`), are managed by `nvm`, and you should not modify, remove, or create these files - expect your changes to be undone, and expect meddling with these files to cause bugs that will likely not be supported.
@@ -394,7 +404,7 @@ If installing nvm on Alpine Linux *is* still what you want or need to do, you sh
```sh ```sh
apk add bash apk add bash
wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.3/install.sh | /bin/bash wget -qO- https://raw.githubusercontent.com/creationix/nvm/v0.31.6/install.sh | /bin/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. The Node project has some desire but no concrete plans (due to the overheads of building, testing and support) to offer Alpine-compatible binaries.
@@ -425,7 +435,7 @@ After the v0.8.6 release of node, nvm tries to install from binary packages. But
If setting the `default` alias does not establish the node version in new shells (i.e. `nvm current` yields `system`), ensure that the system's node PATH is set before the `nvm.sh` source line in your shell profile (see [#658](https://github.com/creationix/nvm/issues/658)) If setting the `default` alias does not establish the node version in new shells (i.e. `nvm current` yields `system`), ensure that the system's node PATH is set before the `nvm.sh` source line in your shell profile (see [#658](https://github.com/creationix/nvm/issues/658))
[1]: https://github.com/creationix/nvm.git [1]: https://github.com/creationix/nvm.git
[2]: https://github.com/creationix/nvm/blob/v0.31.3/install.sh [2]: https://github.com/creationix/nvm/blob/v0.31.6/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
[Fish]: http://fishshell.com [Fish]: http://fishshell.com

9
ROADMAP.md Normal file
View File

@@ -0,0 +1,9 @@
# nvm Road Map
This is a list of the primary features planned for `nvm`:
1. Rewriting installation code paths to support installing `io.js` and `node` `v4+` [from source](https://github.com/creationix/nvm/issues/1188).
- This will include [reusing previously downloaded tarballs](https://github.com/creationix/nvm/issues/1193) that match checksums, which is a nice performance and bandwith bonus.
1. Adding opt-in environment variable support to list, download, and install `node` [release candidates](https://github.com/creationix/nvm/issues/779), and [nightly builds](https://github.com/creationix/nvm/issues/1053).
1. [`nvm update`](https://github.com/creationix/nvm/issues/400): the ability to autoupdate `nvm` itself
1. [v1.0.0](https://github.com/creationix/nvm/milestone/1), including updating the [nvm on npm](https://github.com/creationix/nvm/issues/304) to auto-install nvm properly

View File

@@ -7,11 +7,11 @@ nvm_has() {
} }
nvm_install_dir() { nvm_install_dir() {
echo ${NVM_DIR:-"$HOME/.nvm"} echo "${NVM_DIR:-"$HOME/.nvm"}"
} }
nvm_latest_version() { nvm_latest_version() {
echo "v0.31.3" echo "v0.31.6"
} }
# #
@@ -40,7 +40,7 @@ nvm_source() {
echo "$NVM_SOURCE_URL" echo "$NVM_SOURCE_URL"
} }
# #
# Node.js version to install # Node.js version to install
# #
nvm_node_version() { nvm_node_version() {
@@ -49,7 +49,7 @@ nvm_node_version() {
nvm_download() { nvm_download() {
if nvm_has "curl"; then if nvm_has "curl"; then
curl -q $* curl -q "$@"
elif nvm_has "wget"; then elif nvm_has "wget"; then
# Emulate curl with wget # Emulate curl with wget
ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \ ARGS=$(echo "$*" | command sed -e 's/--progress-bar /--progress=bar /' \
@@ -58,7 +58,8 @@ nvm_download() {
-e 's/-s /-q /' \ -e 's/-s /-q /' \
-e 's/-o /-O /' \ -e 's/-o /-O /' \
-e 's/-C - /-c /') -e 's/-C - /-c /')
wget $ARGS # shellcheck disable=SC2086
eval wget $ARGS
fi fi
} }
@@ -68,15 +69,15 @@ install_nvm_from_git() {
if [ -d "$INSTALL_DIR/.git" ]; then if [ -d "$INSTALL_DIR/.git" ]; then
echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git" echo "=> nvm is already installed in $INSTALL_DIR, trying to update using git"
printf "\r=> " command printf "\r=> "
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch 2> /dev/null || { command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" fetch 2> /dev/null || {
echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself." echo >&2 "Failed to update nvm, run 'git fetch' in $INSTALL_DIR yourself."
exit 1 exit 1
} }
else else
# Cloning to $NVM_DIR # Cloning to $INSTALL_DIR
echo "=> Downloading nvm from git to '$INSTALL_DIR'" echo "=> Downloading nvm from git to '$INSTALL_DIR'"
printf "\r=> " command printf "\r=> "
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
command git clone "$(nvm_source)" "$INSTALL_DIR" || { command git clone "$(nvm_source)" "$INSTALL_DIR" || {
echo >&2 "Failed to clone nvm repo. Please report this!" echo >&2 "Failed to clone nvm repo. Please report this!"
@@ -103,7 +104,6 @@ nvm_install_node() {
NODE_VERSION="$(nvm_node_version)" NODE_VERSION="$(nvm_node_version)"
if [ -z "$NODE_VERSION" ]; then if [ -z "$NODE_VERSION" ]; then
echo "=> You can now install Node.js by running \`nvm install\`"
return 0 return 0
fi fi
@@ -138,12 +138,12 @@ install_nvm_as_script() {
echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'" echo >&2 "Failed to download '$NVM_SOURCE_LOCAL'"
return 1 return 1
} }
nvm_download -s "$NVM_EXEC_SOURCE" -o "$NVM_DIR/nvm-exec" || { nvm_download -s "$NVM_EXEC_SOURCE" -o "$INSTALL_DIR/nvm-exec" || {
echo >&2 "Failed to download '$NVM_EXEC_SOURCE'" echo >&2 "Failed to download '$NVM_EXEC_SOURCE'"
return 2 return 2
} }
chmod a+x "$NVM_DIR/nvm-exec" || { chmod a+x "$INSTALL_DIR/nvm-exec" || {
echo >&2 "Failed to mark '$NVM_DIR/nvm-exec' as executable" echo >&2 "Failed to mark '$INSTALL_DIR/nvm-exec' as executable"
return 3 return 3
} }
} }
@@ -155,8 +155,8 @@ install_nvm_as_script() {
# Otherwise, an empty string is returned # Otherwise, an empty string is returned
# #
nvm_detect_profile() { nvm_detect_profile() {
if [ -n "$PROFILE" -a -f "$PROFILE" ]; then if [ -n "${PROFILE}" ] && [ -f "${PROFILE}" ]; then
echo "$PROFILE" echo "${PROFILE}"
return return
fi fi
@@ -207,18 +207,18 @@ nvm_check_global_modules() {
local NPM_GLOBAL_MODULES local NPM_GLOBAL_MODULES
NPM_GLOBAL_MODULES="$( NPM_GLOBAL_MODULES="$(
npm list -g --depth=0 | npm list -g --depth=0 |
sed '/ npm@/d' | command sed '/ npm@/d' |
sed '/ (empty)$/d' command sed '/ (empty)$/d'
)" )"
local MODULE_COUNT local MODULE_COUNT
MODULE_COUNT="$( MODULE_COUNT="$(
printf %s\\n "$NPM_GLOBAL_MODULES" | command printf %s\\n "$NPM_GLOBAL_MODULES" |
sed -ne '1!p' | # Remove the first line command sed -ne '1!p' | # Remove the first line
wc -l | tr -d ' ' # Count entries wc -l | tr -d ' ' # Count entries
)" )"
if [ $MODULE_COUNT -ne 0 ]; then if [ "${MODULE_COUNT}" != '0' ]; then
cat <<-'END_MESSAGE' cat <<-'END_MESSAGE'
=> You currently have modules installed globally with `npm`. These will no => You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node => longer be linked to the active version of Node when you install a new node
@@ -226,7 +226,7 @@ nvm_check_global_modules() {
=> override the binaries of modules installed with `nvm`: => override the binaries of modules installed with `nvm`:
END_MESSAGE END_MESSAGE
printf %s\\n "$NPM_GLOBAL_MODULES" command printf %s\\n "$NPM_GLOBAL_MODULES"
cat <<-'END_MESSAGE' cat <<-'END_MESSAGE'
=> If you wish to uninstall them at a later point (or re-install them under your => If you wish to uninstall them at a later point (or re-install them under your
@@ -267,37 +267,40 @@ nvm_do_install() {
echo echo
local NVM_PROFILE local NVM_PROFILE
NVM_PROFILE=$(nvm_detect_profile) NVM_PROFILE="$(nvm_detect_profile)"
local INSTALL_DIR local INSTALL_DIR
INSTALL_DIR="$(nvm_install_dir)" INSTALL_DIR="$(nvm_install_dir)"
SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm" SOURCE_STR="\nexport NVM_DIR=\"$INSTALL_DIR\"\n[ -s \"\$NVM_DIR/nvm.sh\" ] && . \"\$NVM_DIR/nvm.sh\" # This loads nvm\n"
if [ -z "$NVM_PROFILE" ] ; then if [ -z "${NVM_PROFILE-}" ] ; then
echo "=> Profile not found. Tried $NVM_PROFILE (as defined in \$PROFILE), ~/.bashrc, ~/.bash_profile, ~/.zshrc, and ~/.profile." echo "=> Profile not found. Tried ${NVM_PROFILE} (as defined in \$PROFILE), ~/.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"
echo "=> Create it (touch $NVM_PROFILE) and run this script again" echo "=> Create it (touch ${NVM_PROFILE}) and run this script again"
echo " OR" echo " OR"
echo "=> Append the following lines to the correct file yourself:" echo "=> Append the following lines to the correct file yourself:"
printf "$SOURCE_STR" command printf "${SOURCE_STR}"
echo
else else
if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then if ! command grep -qc '/nvm.sh' "$NVM_PROFILE"; then
echo "=> Appending source string to $NVM_PROFILE" echo "=> Appending source string to $NVM_PROFILE"
printf "$SOURCE_STR\n" >> "$NVM_PROFILE" command printf "$SOURCE_STR" >> "$NVM_PROFILE"
else else
echo "=> Source string already in $NVM_PROFILE" echo "=> Source string already in ${NVM_PROFILE}"
fi fi
fi fi
# Sourcing $PROFILE to take into account the new environment # Source nvm
. "$NVM_PROFILE" # shellcheck source=/dev/null
. "${INSTALL_DIR}/nvm.sh"
nvm_check_global_modules nvm_check_global_modules
nvm_install_node nvm_install_node
nvm_reset nvm_reset
echo "=> Close and reopen your terminal to start using nvm or run the following to use it now:"
command printf "$SOURCE_STR"
} }
# #

937
nvm.sh

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{ {
"name": "nvm", "name": "nvm",
"version": "0.31.3", "version": "0.31.6",
"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"

View File

@@ -32,6 +32,14 @@ OUTPUT="$(nvm version-remote --lts=argon foo)"
EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:argon,PATTERN:foo' EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:argon,PATTERN:foo'
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote --lts=argon foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote --lts=argon foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
OUTPUT="$(nvm version-remote lts/foo)"
EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:foo,PATTERN:'
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote lts/foo\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
OUTPUT="$(nvm version-remote 'lts/*')"
EXPECTED_OUTPUT='NVM_VERSION_ONLY:true,NVM_LTS:*,PATTERN:'
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm version-remote lts/*\` called nvm_remote_version with >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
set +ex # needed for stderr set +ex # needed for stderr
OUTPUT="$(nvm version-remote --foo bar 2>&1)" OUTPUT="$(nvm version-remote --foo bar 2>&1)"
set -ex set -ex

View File

@@ -32,6 +32,8 @@ setup_mock_arch() {
ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo ln -sf "${MOCKS_DIR}/isainfo_${ARCH}" ./isainfo
if [ "_$OPT" != "_no_pkg_info" ]; then if [ "_$OPT" != "_no_pkg_info" ]; then
ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info ln -sf "${MOCKS_DIR}/pkg_info_${ARCH}" ./pkg_info
else
ln -sf "${MOCKS_DIR}/pkg_info_fail" ./pkg_info
fi fi
fi fi

View File

@@ -0,0 +1,18 @@
#!/bin/sh
set -ex
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
ALG="$(nvm_get_checksum_alg)"
case "$ALG" in
'sha-256' | 'sha-1')
echo 'sha-256 or sha-1 found'
;;
*)
die "sha-256 or sha-1 not found: found ${ALG}"
;;
esac

View File

@@ -0,0 +1,16 @@
#!/bin/sh
set -ex
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
! nvm_get_mirror || die 'unknown release type did not error'
! nvm_get_mirror node || die 'unknown release type did not error'
! nvm_get_mirror iojs || die 'unknown release type did not error'
! nvm_get_mirror node foo || die 'unknown release type did not error'
! nvm_get_mirror iojs foo || die 'unknown release type did not error'
[ "$(nvm_get_mirror node std)" = "${NVM_NODEJS_ORG_MIRROR}" ] || die 'node std did not yield NVM_NODEJS_ORG_MIRROR'
[ "$(nvm_get_mirror iojs std)" = "${NVM_IOJS_ORG_MIRROR}" ] || die 'node std did not yield NVM_NODEJS_ORG_MIRROR'

View File

@@ -1,23 +1,29 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
set +e # TODO: fix
. ../../nvm.sh . ../../nvm.sh
set -e
nvm deactivate || die 'deactivate failed'
nvm unalias default || die 'unable to unalias default' nvm unalias default || die 'unable to unalias default'
NVM_TEST_VERSION=v0.10.7 NVM_TEST_VERSION=v0.10.7
# Remove the stuff we're clobbering. # Remove the stuff we're clobbering.
[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION nvm uninstall "${NVM_TEST_VERSION}" || die 'nvm uninstall failed'
# Install from source # Install from source
nvm install -s $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed" nvm install -s "${NVM_TEST_VERSION}" || die "'nvm install -s ${NVM_TEST_VERSION}' failed"
# Check # Check
[ -d ../../$NVM_TEST_VERSION ] [ -d ../../$NVM_TEST_VERSION ] || die "../../${NVM_TEST_VERSION} is not a directory"
nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed" nvm run $NVM_TEST_VERSION --version | grep $NVM_TEST_VERSION || "'nvm run ${NVM_TEST_VERSION} --version | grep ${NVM_TEST_VERSION}' failed"
# ensure default is set # ensure default is set
NVM_CURRENT_DEFAULT="$(nvm_alias default)" NVM_CURRENT_DEFAULT="$(nvm_alias default)"
[ "$NVM_CURRENT_DEFAULT" = "$NVM_TEST_VERSION" ] || die "wrong default alias: $(nvm alias)" [ "${NVM_CURRENT_DEFAULT}" = "${NVM_TEST_VERSION}" ] || die "wrong default alias: $(nvm alias)"

View File

@@ -1,13 +1,19 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
set +e # TODO: fix
. ../../nvm.sh . ../../nvm.sh
set -e
nvm deactivate || die 'deactivate failed'
NVM_TEST_VERSION=v0.8.5 NVM_TEST_VERSION=v0.8.5
# Remove the stuff we're clobbering. # Remove the stuff we're clobbering.
[ -e ../../$NVM_TEST_VERSION ] && rm -R ../../$NVM_TEST_VERSION nvm uninstall "${NVM_TEST_VERSION}" || die 'uninstall failed'
# Install from source implicitly (v0.8.6 is when binaries started) # Install from source implicitly (v0.8.6 is when binaries started)
nvm install $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed" nvm install $NVM_TEST_VERSION || die "'nvm install -s $NVM_TEST_VERSION' failed"

View File

@@ -1 +1,4 @@
# On SmartOS 64bits setups, pkg_info outputs _both_ i386 and x86_64
# architectures as architectures supported by pkg_install.
echo "i386"
echo "x86_64" echo "x86_64"

1
test/mocks/pkg_info_fail Executable file
View File

@@ -0,0 +1 @@
exit 1

View File

@@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh