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

How to set node versions bin PATH #22

Closed
hyrichie opened this issue Nov 21, 2023 · 14 comments
Closed

How to set node versions bin PATH #22

hyrichie opened this issue Nov 21, 2023 · 14 comments
Labels
enhancement New feature or request

Comments

@hyrichie
Copy link

node version: v16.20.2(currently)
hope: $HOME/.nvmd/versions/16.20.2/bin

switch node version: v18.18.2
hope: $HOME/.nvmd/versions/18.18.2/bin

@hyrichie hyrichie changed the title How to set node versions bin How to set node versions bin PATH Nov 21, 2023
@1111mp
Copy link
Owner

1111mp commented Nov 21, 2023

Sorry, I didn't understand your question a bit. Are you asking about how nvm-desktop works, or do you need a new feature?

nvm-desktop does not switch node versions by setting different environment variables. For more information please see how-does-it-work.

@hyrichie
Copy link
Author

hyrichie commented Nov 21, 2023

yeah~, thanks!

I hope that when I choose a specific version of Node, the env path will be automatically set.
eg: $HOME/.nvmd/versions/16.20.2/bin

@1111mp
Copy link
Owner

1111mp commented Nov 21, 2023

You don't have to do this, nvm-desktop will automatically do this for you. Of course, it is not necessary to write directly to the system environment variables every time, but the principle is similar to this.

@hyrichie
Copy link
Author

hyrichie commented Nov 21, 2023

when i do this:

corepack enable yarn

in my terminal:
image
image

@1111mp
Copy link
Owner

1111mp commented Nov 21, 2023

I finally understand what you mean. 😄

But sorry, nvm-desktop currently does not support the corepack enable command. If you need to use yarn or pnpm, please install it through npm install yarn/pnpm -g.

But later I will learn corepack related behaviors and support it.

@1111mp 1111mp added the enhancement New feature or request label Nov 21, 2023
@hyrichie
Copy link
Author

nice, thanks!

@hyrichie
Copy link
Author

so, you can provide the env setting to solve this problem.

@1111mp
Copy link
Owner

1111mp commented Nov 21, 2023

I need to intercept the corepack enable command and then add the corresponding shim to the $HOME/.nvmd/bin directory.

Example corepack enable yarn:

  • Add shim $HOME/.nvmd/bin/yarn.(This is what nvm-desktop needs to do)
  • Shims: $HOME/.nvmd/versions/16.20.2/bin/yarn & $HOME/.nvmd/versions/16.20.2/bin/yarnpkg. (This is the behavior of corepack)

Later, when you run the yarn -v command, it is initiated by yarn under $HOME/.nvmd/bin/yarn. This will create a new process to run the command you enter: nvmd-command will internally look for $HOME/.nvmd/versions/16.20.2/bin/yarn and then inject it into the environment where this process is running.

By default it will locate the install directory by running the equivalent of
which corepack, but this can be tweaked by explicitly passing the install
directory via the --install-directory flag.

This is troublesome, it means that nvmd-command needs to track these directories. I need some time to think about the implementation.

@hyrichie
Copy link
Author

nice~

@hyrichie
Copy link
Author

I solved it by using "corepack enable --install-directory $NVMD_DIR/bin".
image

@1111mp
Copy link
Owner

1111mp commented Nov 22, 2023

This is indeed a good idea. 👍

But this will also bring some side effects:

  • After switching the node version, yarn or pnpm is still generated through corepack under the previous node version. You need to re-run the corepack enable --install-directory $NVMD_DIR/bin command every time you switch versions (will be overwritten).
  • There will be conflicts with npm install yarn/pnpm -g to install global packages. I'm not sure if this is the default behavior, I need to look into it.

There may be other questions, but these are the things I'm thinking about right now.

@1111mp
Copy link
Owner

1111mp commented Nov 22, 2023

I've decided on the final solution:

  • I will add the yarn&pnpm gaskets by default in the .nvmd/bin directory. After you use corepack enable to generate a shim (default is in the .nvmd/versions/{version}/bin directory), when you run the yarn&pnpm commands, nvmd will start from find the shim in the nvmd/versions/{version}/bin directory.

When you use yarn or pnpm without corepack enable and npm is not installed globally, the terminal will prompt: nvm-desktop: command not find.

Detailed instructions can be found at: nvm-desktop: command not found: {lib}

@1111mp
Copy link
Owner

1111mp commented Nov 23, 2023

Fixed in the latest Release v2.6.0.

I solved it by using "corepack enable --install-directory $NVMD_DIR/bin". image

Support corepack enable command.

If you still have any questions, please feel free to open an issue.

@1111mp 1111mp closed this as completed Nov 23, 2023
@hyrichie
Copy link
Author

oh, yeah~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants