Open asportnoy opened 1 year ago
Can you tell me more about why you're using nvm exec
instead of wrapping nvm use
and running your command inside a Fish function? I'm not super familiar with nvm exec
.
I have a global custom command which requires node 18, but I have local projects that require node 16, so I need nvm exec
to make sure I can always run that custom command. I ended up making my own function for it (https://gist.github.com/asportnoy/d3834347aee5e81390b9671305a4536c) but it should just be implemented into this package. Feel free to use my code if it helps.
So, this just switches to the specified version, runs the command, and switches back. Unless the version isn't installed. Have you run into any issues with your function?
If these commands were added, what would be the reason for both? I am all for the minimalistic approach with having as few commands as possible.
@asportnoy is there a reason you have not put that command (.js file) in your PATH
and then added a Shebang?
#!/home/userA/.local/share/nvm/v18.16.0/bin/node
// js content here
Then just execute it like somecommand
since it exists on your path. To me, that would be much simpler than having to cd
to the directory and then run the much longer nvm exec 18 node index.js
. Or if you still want to cd
, then use a .nvmrc
file.
Thank you for clarifying, @thernstig. I actually didn't realize we were discussing two commands! It seems that their similar names had me confused.
So, this just switches to the specified version, runs the command, and switches back. Unless the version isn't installed. Have you run into any issues with your function?
@jorgebucaran kinda. It doesn't actually switch, it just gets the path to the executable with the correct node version and runs it. You can look at the code above to see how I implemented it.
If these commands were added, what would be the reason for both? I am all for the minimalistic approach with having as few commands as possible.
@asportnoy is there a reason you have not put that command (.js file) in your
PATH
and then added a Shebang?#!/home/userA/.local/share/nvm/v18.16.0/bin/node // js content here
Then just execute it like
somecommand
since it exists on your path. To me, that would be much simpler than having tocd
to the directory and then run the much longernvm exec 18 node index.js
. Or if you still want tocd
, then use a.nvmrc
file.
That is an option for this specific scenario not it's not as clean IMO. Plus, you can't use it for npm
or npx
, which you can with nvm exec
Implementing either nvm exec or nvm run would do, correct?
If you were to only add one, it should definitely be nvm exec
. nvm run
is basically just a shortcut to calling nvm exec node $argv
, whereas exec
can also do npm and npx.
Absolutely! Send me PR and we can polish it together?
Like the official
nvm
command, add anvm exec
subcommand which allows you to execute something one-off with a different version. For example,nvm exec 16 node index.js
. There's also anvm run
command which works likeexec
except you don't need to specifynode
(exec
can also be used withnpm
,npx
, etc)