Closed hyrichie closed 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.
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
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.
when i do this:
corepack enable yarn
in my terminal:
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.
nice, thanks!
so, you can provide the env setting to solve this problem.
I need to intercept the corepack enable
command and then add the corresponding shim to the $HOME/.nvmd/bin
directory.
Example corepack enable yarn
:
$HOME/.nvmd/bin/yarn
.(This is what nvm-desktop
needs to do)$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.
nice~
I solved it by using "corepack enable --install-directory $NVMD_DIR/bin".
This is indeed a good idea. 👍
But this will also bring some side effects:
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).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.
I've decided on the final solution:
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}
Fixed in the latest Release v2.6.0.
I solved it by using "corepack enable --install-directory $NVMD_DIR/bin".
Support corepack enable
command.
If you still have any questions, please feel free to open an issue.
oh, yeah~
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