Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for .nvmrc latest release version #295

Closed
emma-k-alexandra opened this issue Apr 18, 2022 · 4 comments
Closed

Support for .nvmrc latest release version #295

emma-k-alexandra opened this issue Apr 18, 2022 · 4 comments

Comments

@emma-k-alexandra
Copy link

When using nvm, a valid .nvmrc file is

14

Which means default to the latest node 14 release. Docs here: https://github.com/nvm-sh/nvm#nvmrc

However, when using asdf-nodejs with this .nvmrc and the legacy_version_file = yes configuration, the correct version of nodes is not selected:

% cat .nvmrc
14
% asdf list nodejs
  14.19.1
  16.14.2
% asdf current
nodejs          14              Not installed. Run "asdf install nodejs 14"
% asdf install nodejs 14
Trying to update node-build... ok
node-build: definition not found: 14

While I have the latest nodejs 14 version installed, 14.19.1, it's not selected. It would be nice for compatibility if it was.

@iFreilicht
Copy link

iFreilicht commented May 23, 2022

Unfortunately, support for this feature is not in the hands of this plugin. The main logic, as you can see, is inside node-build, which is also the cause of the error message definition not found.

Of course, there is a feature request in the node-build repo for this, but it's been open since over a year, so I wouldn't expect too much there.

Another solution would be from the asdf-side. asdf could get a list of all available versions, choose the latest one, and then forward the exact version number to the plugin. There's a feature request for this, too.

Either solution seems fine.

@aquelehugo
Copy link

A workaround for that, based on this article: https://jasonraimondi.com/posts/fix-binary-not-found-error-asdf-nodejs-v14-with-m1-mac/

mv ~/.asdf/installs/nodejs/14.19.1 ~/.asdf/installs/nodejs/14
asdf reshim nodejs

@iFreilicht
Copy link

@aquelehugo Oh my, that's a fix! Even better, create symlinks!

ln -s 14.18.0 14
ln -s 16.13.0 16
ln -s 17.8.0 17

Don't even have to reshim this way, all .tool-version configs work, and all the .nvmrc configs work as well. I don't know if asdf allows to do this, but if asdf-nodejs automatically created these symlinks, then the problem would actually be solved.

danielfalk pushed a commit to danielfalk/asdf-nodejs that referenced this issue Jan 13, 2023
This change will make it such that when installing a version like so:

`asdf install nodejs 16.10`

It would install 16.10.3, assuming 16.10.3 is the latest point release
at the time of installation.  This change allows asdf to work better
with legacy version specifiers such as what would be stored in `.nvmrc`.

For this to work properly, it would also (in the example above), symlink
16.10 to point to 16.10.3 (and likewise to link 16 to 16.10.3).  Such
symlinks are expected to point to the latest version installed that
satisfies the partial version number.

An uninstallation script has to be added so that symlinks aren't left
dangling at any point.

This fix addresses issue asdf-vm#295.
@augustobmoura
Copy link
Member

We changed the way aliases work on #348, now you need to explicitly opt-in with dynamic ranges on legacy version files (.tool-versions and .nvmrc). The .tool-versions file doesn't support non-deterministic versions, and supporting it on .tool-versions is not a feature we are seeking to implement at the moment.

To enable it, you need to provide an ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY environment variable choosing between the latest_available and latest_installed strategies, you can read more about it in the appropriate section on the README of the project. To make this choice permanent you can export said variable from your shell rc file like so:

export ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY=latest_installed
# OR
export ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY=latest_available

Please update the plugin by running asdf plugin-update nodejs. If a new issue arises with the new implementation please open a new issue.

I would also advise removing old symlinks made manually, as they can cause other issues, a quick script for removing them would be to run:

for inst in "${ASDF_DATA_DIR:-$ASDF_DIR}/installs/nodejs"*; do
  if [ -L "$inst" ]; then
    rm "$inst"
  fi
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants