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

Add nvm exec and nvm run commands #207

Open
asportnoy opened this issue Apr 11, 2023 · 10 comments
Open

Add nvm exec and nvm run commands #207

asportnoy opened this issue Apr 11, 2023 · 10 comments
Labels
enhancement New feature or request

Comments

@asportnoy
Copy link

Like the official nvm command, add a nvm 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 a nvm run command which works like exec except you don't need to specify node (exec can also be used with npm, npx, etc)

@asportnoy asportnoy changed the title Add nvm exec and nvm run command Add nvm exec and nvm run commands Apr 11, 2023
@jorgebucaran jorgebucaran added the enhancement New feature or request label Apr 12, 2023
@jorgebucaran
Copy link
Owner

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.

@asportnoy
Copy link
Author

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.

@jorgebucaran
Copy link
Owner

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?

@thernstig
Copy link

thernstig commented Apr 30, 2023

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.

@jorgebucaran
Copy link
Owner

Thank you for clarifying, @thernstig. I actually didn't realize we were discussing two commands! It seems that their similar names had me confused.

@asportnoy
Copy link
Author

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.

@asportnoy
Copy link
Author

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.

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

@jorgebucaran
Copy link
Owner

Implementing either nvm exec or nvm run would do, correct?

@asportnoy
Copy link
Author

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.

@jorgebucaran
Copy link
Owner

Absolutely! Send me PR and we can polish it together?

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

3 participants