Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use node should support nvm aliases as well as node versions #1270

Open
DrHyde opened this issue Apr 10, 2024 · 0 comments
Open

use node should support nvm aliases as well as node versions #1270

DrHyde opened this issue Apr 10, 2024 · 0 comments
Labels

Comments

@DrHyde
Copy link

DrHyde commented Apr 10, 2024

Is your feature request related to a problem? Please describe.

As a work-around for #1269 I tried using use node default in a .envrc, and got an error direnv: Unable to find NodeJS version (default) in (/Users/dcantrell/.nvm/versions/node)! (the directory is what's in NODE_VERSIONS).

Aliases are stored as files in $NODE_VERSIONS/../../alias and can either be a specific version, such as 18.14.2, or can be another named alias, or as a special case can be node which means the highest installed version of node.

Describe the solution you'd like

use node should take any argument that nvm use can take

Describe alternatives you've considered

I tried just putting nvm use default in .envrc, but because it's a function and not an executable command it didn't work: ./.envrc:9: nvm: command not found

Additional context

You can get the prefix path for any nvm-installed version of node, and also any alias, thus: dirname $(dirname $(nvm which $VERSION)). For example:

~ $ dirname $(dirname $(nvm which node))
/Users/dcantrell/.nvm/versions/node/v20.11.1        <-- most recent installed
~ $ dirname $(dirname $(nvm which current))
/Users/dcantrell/.nvm/versions/node/v16.20.2        <-- the one currently in use
~ $ dirname $(dirname $(nvm which v18.16.0))
/Users/dcantrell/.nvm/versions/node/v18.16.0        <-- specific version asked for
~ $ dirname $(dirname $(nvm which 18.16.0))
/Users/dcantrell/.nvm/versions/node/v18.16.0        <-- specific version asked for without a NODE_VERSION_PREFIX
~ $ dirname $(dirname $(nvm which default))
/Users/dcantrell/.nvm/versions/node/v20.11.1        <-- resolved via alias

Doing that is a bit slow because it has to run node, so I suggest keeping the existing code and only doing the nvm which dance and trying again if the directory $node_prefix calculated here doesn't exist.

@DrHyde DrHyde added the Feature label Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant