asdf-nodejs icon indicating copy to clipboard operation
asdf-nodejs copied to clipboard

Support for `.nvmrc` latest release version

Open emma-k-alexandra opened this issue 3 years ago • 3 comments

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.

emma-k-alexandra avatar Apr 18 '22 18:04 emma-k-alexandra

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.

iFreilicht avatar May 23 '22 14:05 iFreilicht

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

aquelehugo avatar Jun 16 '22 13:06 aquelehugo

@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.

iFreilicht avatar Jun 27 '22 15:06 iFreilicht

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

augustobmoura avatar May 20 '23 16:05 augustobmoura