asdf-vm / asdf-nodejs

Node.js plugin for asdf version manager
https://github.com/asdf-vm/asdf
MIT License
908 stars 144 forks source link

Resolving LTS version only outputs major number #369

Open jabkoo opened 1 year ago

jabkoo commented 1 year ago

Describe the Bug

When trying to resolve latest lts node version, I'm getting the result I was not expecting. When I run asdf nodejs resolve lts it only outputs a current major number 18 instead of a full version specified: 18.18.0. I get the same result when running asdf nodejs resolve lts --latest-available. Weirdly enough, running asdf nodejs resolve lts --latest-installed returns full version, so 18.18.0, even though I have no node versions installed yet (I am assuming it is using latest available version as a fallback?).

That is also causing asdf install nodejs lts not working, because it cannot resolve version 18.

Steps to Reproduce

Run:

Expected Behaviour

Command asdf nodejs resolve lts should output full semantic version of latest available LTS Node version and asdf install nodejs lts should be able to install it. As of 2023-10-02 it should output 18.18.0

Actual Behaviour

Only major version number is printed

> asdf nodejs resolve lts
18

This causes asdf install nodejs lts to fail. It needs full version specified with MAJOR.MINOR.PATCH

> asdf install nodejs lts 
Trying to update node-build... ok
node-build: definition not found: 18

Environment

OS:
Darwin jabko-macbook 22.6.0 Darwin Kernel Version 22.6.0: Wed Jul  5 22:22:52 PDT 2023; root:xnu-8796.141.3~6/RELEASE_ARM64_T8103 arm64

SHELL:
zsh 5.9 (x86_64-apple-darwin22.0)

BASH VERSION:
3.2.57(1)-release

ASDF VERSION:
v0.13.0

ASDF INTERNAL VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=.tool-versions
ASDF_DATA_DIR=/Users/jabko/.asdf
ASDF_DIR=/opt/homebrew/opt/asdf/libexec
ASDF_CONFIG_FILE=/Users/jabko/.asdfrc

ASDF INSTALLED PLUGINS:
golang                       https://github.com/asdf-community/asdf-golang.git master e7e8171
hugo                         https://github.com/NeoHsu/asdf-hugo.git master 125ce37
nodejs                       https://github.com/asdf-vm/asdf-nodejs.git master 9275f49

asdf plugins affected (if relevant)

nodejs

jabkoo commented 1 year ago

Ok, I fixed that with adding ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY="latest_available" variable to my .zshrc, I guess that is how it is supposed to work?

However, it is really confusing, because I'm not using any legacy files like .node-version or .nvmrc. I just wanted to be able to resolve latest lts version from the command line with asdf nodejs resolve lts, so I wouldn't have guessed I need to set ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY variable just for that.

@augustobmoura Is this behaviour intended?

Edditoria commented 11 months ago

The README states "This option is only available for legacy version files". So, it does not work with .tools-version. IMHO it is a good decision.

  1. If your team uses ASDF (the ".tools-version"), just use the exact version stated in the .tools-version file.
  2. This is consistent with other plugins. Plus, unclear version sometimes create problems.
  3. If you team is more comfortable with partial version like "20" (not recommend) or "20.10" (better), use .nvmrc instead of .tools-version.

Most of my projects are using .nvmrc, and need to switch a lot. I use "latest_installed" to gain more control in my local env. It is smooth, so far.

logicalup commented 10 months ago

this is now happening with v20. It's a broken behavior imo. When trying to install latest lts version using the command that asdf says to use: "asdf install nodejs lts" it errors out node-build: definition not found: 20

I tried adding ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY="latest_available" and that didn't help

brendanmatkin commented 8 months ago

this is now happening with v20. It's a broken behavior imo. When trying to install latest lts version using the command that asdf says to use: "asdf install nodejs lts" it errors out node-build: definition not found: 20

I tried adding ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY="latest_available" and that didn't help

I agree, this is definitely broken behaviour, or incorrect docs (i.e. following the documentation leads to an error).

image
augustobmoura commented 4 months ago

Ok, I fixed that with adding ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY="latest_available" variable to my .zshrc, I guess that is how it is supposed to work?

However, it is really confusing, because I'm not using any legacy files like .node-version or .nvmrc. I just wanted to be able to resolve latest lts version from the command line with asdf nodejs resolve lts, so I wouldn't have guessed I need to set ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY variable just for that.

@augustobmoura Is this behaviour intended?

We could've the command fail if you don't provide either ASDF_NODEJS_LEGACY_FILE_DYNAMIC_STRATEGY or a flag forcing a strategy. The idea is that by default it should follow your strategy of preference, from the variable.

I will work on making failing when no variable is passed the default behavior