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

asdf local lts should write version, not alias

Open jhogendorn opened this issue 3 years ago • 4 comments

When you run asdf local nodejs lts it writes nodejs lts to .tool-versions.

It should probably write what it resolves to instead, ie nodejs 16.15.1 or better yet, probably nodejs ^16.15.1 (not sure if this tool supports that notation for versions)

This means if we click over what lts means, we're actually sticking to the old lts until the project is explicitly upgraded.

I know we have the lts-codename versions, but I never remember what the current one is and have to go look it up. annoying.

jhogendorn avatar Jul 08 '22 03:07 jhogendorn

Aliases can only work during installation as the plugin executes the installation and linking to support this. asdf local <plugin> <version> and asdf global <plugin> <version> which update .tool-versions do not interact with the provided plugins, the asdf core handles that on it's lonesome.

So what you request is not possible.

My personal opinion is that you should stick with full versions as the simplicity of the LTS aliases will only breed further issues like this. For example, 4/20 issues open in this repo are solely about LTS.

EDIT: I commented on this in the core repo over a year ago https://github.com/asdf-vm/asdf/issues/1024#issuecomment-899203820

I do not like the idea of aliases as they are simply a shortcut, and only a shortcut for that single time they are used. asdf install nodejs lts changes over time and so the lts on your machine is no longer an LTS. Also, your lts may be different to my lts. And reporting you are using lts when trying to resolve a bug only causes more problems. I personally would advise against using aliases. Unless I am misunderstanding their utility.

jthegedus avatar Jul 17 '22 11:07 jthegedus

can the plugin on install just take lts, resolve it at that time, and then install the actual version? ie user types asdf install nodejs lts and the plugin resolves lts to 16.15.1 and installs that version then, so asdf only ever sees 16.15.1?

It wouldnt solve the asdf local nodejs lts thing but at least it would be a 'real version', without having to go look up what the current lts is.

jhogendorn avatar Jul 18 '22 05:07 jhogendorn

can the plugin on install just take lts, resolve it at that time, and then install the actual version? ie user types asdf install nodejs lts and the plugin resolves lts to 16.15.1 and installs that version then, so asdf only ever sees 16.15.1?

I believe this is what asdf-nodejs already does.

jthegedus avatar Jul 18 '22 07:07 jthegedus

I believe this is what asdf-nodejs already does.

It does :+1:

$ asdf list nodejs

  16.17.0
  lts

can the plugin on install just take lts, resolve it at that time, and then install the actual version?

While not exactly what you want, if you insist on using the lts version, you could choose to be a bit more explicit about which LTS series you want, that would at least pin to the major version associated to that LTS release?

$ asdf list all nodejs lts

lts-argon
lts-boron
lts-carbon
lts-dubnium
lts-erbium
lts-fermium
lts-gallium
lts

# Add the `-` suffix to filter out the generic `lts` result, this will report the latest LTS:
$ asdf latest nodejs lts-

lts-gallium

# Install the latest LTS at the time (by LTS release name):
$ asdf install nodejs "$(asdf latest nodejs lts-)"

It should roughly be equivalent to what you wanted?


If you need something more specific then perhaps be more explicit in specifying the version?

# Find where the lts version is located:
$ asdf where nodejs lts
/home/polarathene/.asdf/installs/nodejs/lts


# Result is a symlink, so resolve it to absolute path with `readlink -f`:
$ readlink -f $(asdf where nodejs lts)
/home/polarathene/.asdf/installs/nodejs/16.17.0


# Pipe into `awk` to split the line at each `/` and output the last column (`NF`):
$ readlink -f $(asdf where nodejs lts) | awk -F '/' '{print $(NF)}' 

16.17.0


# Set the local version to the current lts version installed, perhaps easier to make an alias for this command:
asdf local nodejs "$(readlink -f $(asdf where nodejs lts) | awk -F '/' '{print $(NF)}')"


# Tada!
$ cat .tool-versions

nodejs 16.17.0

With an alias configured for that, you can easily set the local version to the explicit nodejs version the lts alias is using (or even the current alias with asdf where nodejs instead of querying the lts alias).

polarathene avatar Sep 02 '22 22:09 polarathene

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.

augustobmoura avatar May 20 '23 16:05 augustobmoura