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

Support slash-based aliases for LTS

Open dcalhoun opened this issue 4 years ago • 5 comments

Support for aliases was added in #176, which is great! However, the support appears to use a dash-based naming convention, which diverges from nvm's slash-based naming convention.

If possible, it'd be helpful to align to (or at least support) the slash-based naming convention. Doing so would allow...

  • [ ] Existing .nvmrc files leveraging LTS aliases. E.g. lts/*. (#194)
  • [ ] Installing LTS aliases via the CLI. E.g. asdf install nodejs lts/erbium.

dcalhoun avatar Jan 21 '21 15:01 dcalhoun

The main problem is how the core asdf handles names, it can't use / because it needs to be a valid directory name (lts/erbium actually creates a lts dir with a erbium dir inside). I talked about it in https://github.com/asdf-vm/asdf-nodejs/pull/176#issuecomment-702815634, sorry if was not clear in the original comment is a bit hard to describe the problem. I made the suggestion https://github.com/asdf-vm/asdf/issues/352#issuecomment-703691304 in asdf core that should allow nvm style aliases. We can tinker about other ways though

augustobmoura avatar Jan 21 '21 17:01 augustobmoura

@augustobmoura ah, thank you for providing that context. I overlooked that helpful information. It does seem like supporting aliases containing slashes is a bit more involved and potentially related to asdf core.

dcalhoun avatar Jan 21 '21 17:01 dcalhoun

I wonder if when reading the legacy/.nvmrc file, we could do the conversion there? Then, asdf and asdf-nodejs could treat the value as lts-erbium for its purposes. Basically just a little adapter for their syntax.

Thoughts?

blimmer avatar Jan 21 '21 18:01 blimmer

Actually... There is a way of supporting .nvmrc files using the parse-legacy-file hook, I didn't see that hook before. asdf install nodejs lts/erbium will still not work though

augustobmoura avatar Jan 21 '21 18:01 augustobmoura

I opened the #194 PR to add this translation at legacy file level, tested in my machine and it worked fine. Maybe we can leave the issue open for the asdf install nodejs lts/erbium issue. Running asdf install nodejs(without the version) in the directory with the .nvmrc file installs the correct version for the project

augustobmoura avatar Jan 21 '21 19:01 augustobmoura

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