https://github.com/mearns/nvmw
A wrapper around nvm, in the style of gradle-wrapper (sort of)
https://github.com/mearns/nvmw
Last synced: about 1 month ago
JSON representation
A wrapper around nvm, in the style of gradle-wrapper (sort of)
- Host: GitHub
- URL: https://github.com/mearns/nvmw
- Owner: mearns
- License: agpl-3.0
- Created: 2016-02-19T15:44:54.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-26T17:46:31.000Z (about 9 years ago)
- Last Synced: 2025-02-05T11:45:04.409Z (3 months ago)
- Language: Shell
- Size: 34.2 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nvmw
**`nvmw` - the nvm wrapper.**
Ensure that a specified version of [`nvm`](https://github.com/creationix/nvm)
is installed, and then use it to
ensure a specific version of [`nodejs`](https://nodejs.org/) is installed.
Then execute the given
arguments with the desired node version selected (i.e., following an `nvm
use`).Specify the node version to install in a `.nvmrc` file, as usual with `nvm`, or
alternatively with the `NODE_VERSION` environment variable (which supercedes
any `.nvmrc` file).You can also specify which version of `nvm` to use, with the `NVM_VERSION` env
var. Otherwise, a default value is used (hard-coded below). This should be a specific
version tagged version, excluding the leading 'v'.For status messages, set the `NVMW_DEBUG` variable to "1".
Everything is stored in the `.nvmw` directory in the same directory as this
script is located (NOT necessarily the working directory). Versions of the
`nvm.sh` script are stored under there, and, when invoked through the nvm-wrapper,
is configured to use `.nvmw/nvm` as the NVM directory; all versions of
`node` and related tools (e.g., `npm`), plus all "globally" installed npm modules
are stored there (assuming you use the nvm-wrapper to install them, like
`./nvmw npm install MODULE_NAME -g`). If you want, you can change the location
where nvmw stores things by setting the `NVMW_DIR` env var. For instance, you
could set it to a system wide location so that nvmw and nvm cache everything
in one location.## Installation
Just drop `nvmw` into your project's root directory. That's it. Oh, and you need either
curl or wget installed. Other than that, it should work in pretty much any bash shell
(possibly others).E.g.:
```bash
wget https://raw.githubusercontent.com/mearns/nvmw/v1.0.0/nvmw
```## Demo
```console
$ pwd
/tmp
$
$ # Make sure no previous nvmw things are in the way,
$ # to get consistent output.
$ rm -rf .nvmw
$ rm -f .nvmrc
$
$ # Specify which version of node we want to use, in the .nvmrc
$ echo "4.3.1" > .nvmrc
$
$ # Invoke node, using the wrapper.
$ # Neither nvm nor node is installed here yet, so they will both be installed first.
$ ./nvmw node --version
######################################################################## 100.0%
Found '/tmp/.nvmrc' with version <4.3.1>
Downloading https://nodejs.org/dist/v4.3.1/node-v4.3.1-linux-x64.tar.xz...
######################################################################## 100.0%
Now using node v4.3.1 (npm v2.14.12)
Creating default alias: default -> 4.3.1 (-> v4.3.1)
v4.3.1
$
$ # The version is installed now, it'll be quicker this time.
$ ./nvmw node --version
v4.3.1
$
$ # Override the version with the NODE_VERSION env var.
$ # The new version of node will be installed, but nvm is already installed.
$ NODE_VERSION=5.6.0 ./nvmw node --version
######################################################################## 100.0%
Now using node v5.6.0 (npm v3.6.0)
v5.6.0
$
$ # Back to using nvmrc
$ ./nvmw node --version
v4.3.1
$
$ # And back to overridden version
$ NODE_VERSION=5.6.0 ./nvmw node --version
v5.6.0
$
$ # Install npm modules.
$ sudo ./nvmw npm install pm2 -g
npm WARN optional dep failed, continuing [email protected]
/tmp/.nvmw/nvm/versions/node/v4.3.1/bin/pm2 -> /tmp/.nvmw/nvm/versions/node/v4.3.1/lib/node_modules/pm2/bin/pm2
/tmp/.nvmw/nvm/versions/node/v4.3.1/bin/pm2-dev -> /tmp/.nvmw/nvm/versions/node/v4.3.1/lib/node_modules/pm2/bin/pm2-dev
[email protected] /tmp/.nvmw/nvm/versions/node/v4.3.1/lib/node_modules/pm2
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected] ([email protected])
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected])
├── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected])
├── [email protected]
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected], [email protected])
├── [email protected] ([email protected])
├── [email protected] ([email protected])
├── [email protected]
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
$
$ # Now pm2 is installed, but only for the local version 4.3.0 of node.
$ ./nvmw pm2 --version
1.0.1
$
$ # It isn't installed for other versions of node.
$ NODE_VERSION=5.6.0 ./nvmw pm2 --version
./nvmw: line 198: pm2: command not found
$
$ ./nvmw which pm2
/tmp/.nvmw/nvm/versions/node/v4.3.1/bin/pm2
```## Limits
You shouldn't generally use the nvm wrapper to execute nvm. It may work in
particular cases, but, in particular, if you're overriding the node version
with the `NODE_VERSION` env var, nvm itself does not consider this.