asdf-nodejs/README.md

78 lines
4.3 KiB
Markdown
Raw Normal View History

2015-05-24 12:27:40 +08:00
# asdf-nodejs
2018-06-26 09:43:37 +08:00
[![Build Status](https://travis-ci.org/asdf-vm/asdf-nodejs.svg?branch=master)](https://travis-ci.org/asdf-vm/asdf-nodejs)
2016-03-16 12:24:18 +08:00
Node.js plugin for [asdf](https://github.com/asdf-vm/asdf) version manager
2015-05-24 12:27:40 +08:00
## Install
After installing [asdf](https://github.com/asdf-vm/asdf), install the plugin by running:
```bash
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
```
## Use
Check [asdf](https://github.com/asdf-vm/asdf) readme for instructions on how to install & manage versions of Node.js at a system and project level.
Behind the scenes, `asdf-nodejs` utilizes [`node-build`](https://github.com/nodenv/node-build) to install pre-compiled binaries and compile from source if necessary. You can check its [README](https://github.com/nodenv/node-build/blob/master/README.md) for more compile settings and troubleshooting.
When compiling a version from source, you are going to need to install [all requirements for compiling Node.js](https://github.com/nodejs/node/blob/master/BUILDING.md#building-nodejs-on-supported-platforms) (be advised that different versions might require different configurations). That being said, `node-build` does a great job at handling edge cases and compilations rarely need a deep investigation.
### Configuration
Aside from the [common configuration with `node-build`](https://github.com/nodenv/node-build#custom-build-configuration), `asdf-nodejs` has a few extra environment variables for configuration.
- `ASDF_NODEJS_NODEBUILD_HOME`: Home for the node-build installation, defaults to `$ASDF_DIR/plugins/nodejs/.node-build`, you can install it in another place or share it with your system
- `ASDF_NODEJS_NODEBUILD`: Path to the node-build executable, defaults to `$NODE_BUILD_MIRROR_URL/bin/node-build`
- `ASDF_NODEJS_CONCURRENCY`: How many jobs should be used in compilation. Defaults to half the computer cores
- `ASDF_NODEJS_VERBOSE_INSTALL`: Enables verbose output for downloading and building. Any value different from empty is treated as enabled.
- `NODEJS_ORG_MIRROR`: (Legacy) overrides the default mirror used for downloading the distibutions, alternative to the `NODE_BUILD_MIRROR_URL` node-build env var
### Integrity/signature check
In the past `asdf-nodejs` checked for signatures and integrity on our own. `node-build` checks integrity by precomputing checksums ahead of time and versioning them together with the instructions for building them.
### `.nvmrc` and `.node-version` support
2017-03-01 01:20:10 +08:00
2017-03-03 19:17:57 +08:00
asdf uses the `.tool-versions` for auto-switching between software versions. To ease migration, you can have it read an existing `.nvmrc` or `.node-version` file to find out what version of Node.js should be used. To do this, add the following to `$HOME/.asdfrc`:
2017-03-01 01:20:10 +08:00
```
legacy_version_file = yes
```
### Updating node-build defitions
Every new node version needs to have a definition file in the `node-build` repository. Because of that, `asdf-nodejs` tries to update the local `node-build` repository at every install command to download definitions for newly added versions.
We provide a command for manually updating `node-build` at your own time:
```bash
asdf nodejs update-nodebuild
```
### node-build advanced variations
`node-build` has some additional variations aside from the versions listed in `asdf list-all nodejs` (chakracore/graalvm branches and some others). As of now, we weakly support these variations because they are available for install and can be used in a `.tool-versions` file, but we don't list them as installation candidates nor give full support. Some of them will work out of the box, and some others will need a bit of investigation to get them built. We are planning in providing better support for these variations in the future.
To list all the available variations run:
``` bash
asdf nodejs nodebuild --definitions
```
*Note that this command only lists the current `node-build` definitions. You might want to [update the local `node-build` repository](#updating-node-build-definitions) before listing them.*
## Default npm Packages
`asdf-nodejs` can automatically install a set of default set of npm package right after installing a Node.js version. To enable this feature, provide a `$HOME/.default-npm-packages` file that lists one package per line, for example:
```
lodash
request
express
```
You can specify a non-default location of this file by setting a `ASDF_NPM_DEFAULT_PACKAGES_FILE` variable.