Skip to content

Conversation

AdrieanKhisbe
Copy link
Contributor

Support nvm aliases (including lts/aliases, stable, personal ones, indirections and cycle protection)

Hey @ehmicky 🙂, here is the rework of https://github.com/AdrieanKhisbe/normalize-node-version/commits/support-nvm-aliases--original prototype when #1 was still in building 🏗️. I adapted it to the refactors you made to the project after #1 merge.

Proposed changes:

  • Problem addressed: use nvm aliases along with nve
  • Related Prs: None
  • Solution proposed
    • if NVM_DIR is configured, try to resolve theses aliases.
    • Note: this relies on nvm directory structured, and version files, rather than relying on nvm bash scripts
  • Checklist
    • I have read the contribution guidelines.
    • I have added tests (we are enforcing 100% test coverage).
    • I have added documentation in the README.md, the docs directory (if
      any) and the examples directory (if any).
    • The status checks are successful (continuous integration).

includies lts/aliases, stable, personal ones, indirections and cycle protection

:hammer_and_wrench: This is a rework of https://github.com/AdrieanKhisbe/normalize-node-version/commits/support-nvm-aliases--original prototype when ehmicky#1 was still in building 🏗️
@ehmicky
Copy link
Owner

ehmicky commented Apr 21, 2020

Thanks a lot for this PR @AdrieanKhisbe!

To keep normalize-node-version focused on Node.js version resolution (and not alias), I created two new projects:

The dependency chain is now get-node -> preferred-node-version -> node-version-alias -> normalize-node-version -> all-node-versions.

I have integrated all the changes from this PR into those respective projects and credited your changes: nvm custom aliases, LTS named aliases, stable, node, latest.

I have renamed . to now and added the following new features:

  • also look into home directory for version files
  • supports .n-node-version (used by n version manager)
  • supports .nodeenvrc (used by nodeenv version manager)
  • supports NODE_VERSION environment variable (used by Netlify)
  • supports NODIST_NODE_VERSION environment variable (used by Netlify)
  • supports lts and lts/* to target the latest LTS version
  • supports lts/-2, lts/-3, etc. to target the n-th latest LTS version (this is a new alias from nvm)
  • supports current alias, used by some version managers instead of latest
  • supports system, iojs and unstable alias which are some builtin aliases with nvm

The now alias should be able to handle any Node.js version manager file and aliases. However, in order to keep nve simple, only a limited amount of aliases are now allowed in the nve {version} CLI call itself: latest, lts and now. I think this should take care of 99% of use cases and will keep the interface uncomplicated.

Note that the LTS versions are retrieved using nodejs.org/dist/index.json and checking for the lts field instead of looking up the nvm alias directory. This is because:

  • the user might not have nvm
  • we already retrieve that file for other reasons, so this is cached and faster
  • nvm actually does the same under the hood
  • this avoids having to specify a NVM_DIR option

Thanks for getting all this progress kicked in!

@ehmicky ehmicky closed this Apr 21, 2020
@AdrieanKhisbe
Copy link
Contributor Author

Awesome @ehmicky ! =)
and I see nve@11 is out! 🚀

About LTS you're right, it's far better not to rely on nvm for them.

Just one suggestion though,
I would have rather replaced . with here, as "here in the current project".
I feel now does more sound like _, the process current node version.

@AdrieanKhisbe AdrieanKhisbe deleted the support-nvm-aliases branch April 22, 2020 07:20
@AdrieanKhisbe AdrieanKhisbe restored the support-nvm-aliases branch April 22, 2020 07:20
@ehmicky
Copy link
Owner

ehmicky commented Apr 22, 2020

You're absolutely right, here makes more sense than now. I have renamed it in nve@12.

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

Successfully merging this pull request may close these issues.

2 participants