1111mp / nvm-desktop

Node Version Manager Desktop - A desktop application to manage multiple active node.js versions.
https://github.com/1111mp/nvm-desktop
MIT License
675 stars 34 forks source link

How to set node versions bin PATH #22

Closed hyrichie closed 9 months ago

hyrichie commented 9 months ago

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

1111mp commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

when i do this:

corepack enable yarn

in my terminal: image image

1111mp commented 9 months ago

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.

hyrichie commented 9 months ago

nice, thanks!

hyrichie commented 9 months ago

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

1111mp commented 9 months ago

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

Example corepack enable yarn:

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 commented 9 months ago

nice~

hyrichie commented 9 months ago

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

1111mp commented 9 months ago

This is indeed a good idea. 👍

But this will also bring some side effects:

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

1111mp commented 9 months ago

I've decided on the final solution:

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 commented 9 months ago

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.

hyrichie commented 9 months ago

oh, yeah~