Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d0239a

Browse filesBrowse files
committed
docs: add documentation on custom version resolvers
1 parent 766e3c0 commit 3d0239a
Copy full SHA for 3d0239a

File tree

Expand file treeCollapse file tree

1 file changed

+43
-14
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+43
-14
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+43-14Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,15 @@ When compiling a version from source, you are going to need to install [all requ
2222

2323
`node-build` already has a [handful of settings](https://github.com/nodenv/node-build#custom-build-configuration), in additional to that `asdf-nodejs` has a few extra configuration variables:
2424

25+
- `ASDF_NODEJS_RESOLVE_VERSION_CMD`: Custom script to resolve versions on legacy version files. This is evaluated as a bash script `$1` is the version to be resolved. If you want a quick way to support partial/codename versions check [Partial and codename versions](#partial-and-codename-versions)
2526
- `ASDF_NODEJS_VERBOSE_INSTALL`: Enables verbose output for downloading and building. Any value different from empty is treated as enabled.
2627
- `ASDF_NODEJS_FORCE_COMPILE`: Forces compilation from source instead of preferring pre-compiled binaries
2728
- `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
2829
- `ASDF_NODEJS_NODEBUILD`: Path to the node-build executable, defaults to `$ASDF_NODEJS_NODEBUILD_HOME/bin/node-build`
30+
- `ASDF_NODEJS_SKIP_NODEBUILD_UPDATE`: Skip trying to update nodebuild prior to list-all and install. If enabling this var, you might need to [update nodebuild manually](#manually-updating-node-build-definitions) to get newly released versions
2931
- `ASDF_NODEJS_CONCURRENCY`: How many jobs should be used in compilation. Defaults to half the computer cores
3032
- `NODEJS_ORG_MIRROR`: (Legacy) overrides the default mirror used for downloading the distibutions, alternative to the `NODE_BUILD_MIRROR_URL` node-build env var
3133

32-
### Integrity/signature check
33-
34-
In the past `asdf-nodejs` checked for signatures and integrity by querying live keyservers. `node-build`, on the other hand, checks integrity by precomputing checksums ahead of time and versioning them together with the instructions for building them, making the process a lot more streamlined.
35-
3634
### `.nvmrc` and `.node-version` support
3735

3836
asdf uses a `.tool-versions` file 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`:
@@ -41,6 +39,45 @@ asdf uses a `.tool-versions` file for auto-switching between software versions.
4139
legacy_version_file = yes
4240
```
4341

42+
## Partial and codename versions
43+
44+
Many version managers allow you to use partial versions (e.g. `v10`) or NodeJS codenames (e.g. `lts/hydrogen`) in version files, which are resolved at runtime. However, this can be risky as it is not guaranteed that all developers will use the same version, leading to non-reproducibility. In `asdf`, we prioritize reproducibility, so you cannot use partial versions or codenames in a `.tool-versions` file.
45+
46+
To address this, we offer an escape hatch for legacy version files. If you are comfortable with non-reproducibility issues, you can provide your own resolution script as an environment variable `ASDF_NODEJS_RESOLVE_VERSION_CMD`. You can export this variable from your shell rc file and it will become the default behavior.
47+
48+
It is important to be aware of the risks of non-reproducibility. Debugging can become more challenging and bugs may leak into production if the deployed node version differs from the one used in development. Ideally, maintainers should be encouraged to pin the version to a specific release to avoid these issues.
49+
50+
If non-reproducibility is not a concern for you, you can use one of the following resolve scripts in your shell rc file:
51+
52+
```bash
53+
# This script will always resolve to the latest version of said partial, even if not installed.
54+
# If a new version is released for that partial/codename, asdf will prompt you to install it.
55+
export ASDF_NODEJS_RESOLVE_VERSION_CMD='asdf nodejs latest "$1"'
56+
57+
# This script will resolve to the latest *installed* version that satisfies the partial/codename.
58+
# If new versions that match said partial are released, you need to install them with `asdf install nodejs <version>`.
59+
# The newly installed version will be picked up automatically.
60+
export ASDF_NODEJS_RESOLVE_VERSION_CMD='asdf nodejs latest "$1" --installed'
61+
```
62+
63+
These are just examples, and you can provide your own script that resolves to your preferred version.
64+
65+
> **NOTE**: Partial versions and codenames only work for legacy version files: `.node-version` and `.nvmrc`.
66+
> The `.tool-versions` file will never support non-deterministic versions, if they were supported in the past
67+
> that was a mistake
68+
69+
### Default npm Packages
70+
71+
`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:
72+
73+
```
74+
lodash
75+
request
76+
express
77+
```
78+
79+
You can specify a non-default location of this file by setting a `ASDF_NPM_DEFAULT_PACKAGES_FILE` variable.
80+
4481
### Running the wrapped node-build command
4582

4683
We provide a command for running the installed `node-build` command:
@@ -71,14 +108,6 @@ Every new node version needs to have a definition file in the `node-build` repos
71108
asdf nodejs update-nodebuild
72109
```
73110

74-
## Default npm Packages
75-
76-
`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:
77-
78-
```
79-
lodash
80-
request
81-
express
82-
```
111+
### Integrity/signature check
83112

84-
You can specify a non-default location of this file by setting a `ASDF_NPM_DEFAULT_PACKAGES_FILE` variable.
113+
In the past `asdf-nodejs` checked for signatures and integrity by querying live keyservers. `node-build`, on the other hand, checks integrity by precomputing checksums ahead of time and versioning them together with the instructions for building them, making the process a lot more streamlined.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.