volta icon indicating copy to clipboard operation
volta copied to clipboard

How to install the pinned version of tools?

Open existe-deja opened this issue 2 years ago • 11 comments

It's more a question than an issue, sorry for polluting the repo. I didn't find a way to install the right pinned version of node and yarn in command line. Does this option exists?

Thanks

existe-deja avatar Nov 24 '22 13:11 existe-deja

If you have already pinned a tool (i.e. there is a corresponding entry in the package.json file), these tools are automatically installed if necessary when they are used. There is no need to install them beforehand - you would loose flexibility.

michaelfoidl avatar Nov 29 '22 06:11 michaelfoidl

So if I have node@18 as default and my project pinned node@16 it will automatically use it and download it if needed?

existe-deja avatar Nov 29 '22 10:11 existe-deja

Exactly.

When a command like "node -v" is executed, Volta gets the appropriate version of node from the nearest package.json file in the directory hierarchy upwards and falls back to the default version. If the specified version is not yet present, it is downloaded and installed.

Just try it.

For me, this has always been clear, but when looking at the docs, I have not found a place where this functionality has been described explicitly. Maybe something like that should be added?

michaelfoidl avatar Nov 29 '22 10:11 michaelfoidl

Thank you. It wasn't super clear until you explained me. Also because I see no downloads when I switch version. A more explicit documentation could do the job yes!

existe-deja avatar Nov 30 '22 14:11 existe-deja

Oh interesting, thanks for pointing that out @michaelfoidl & @existe-deja! I would have sworn there was an explicit reference to that behavior early in the docs, but looking now and I don't see anything either! We'll definitely want to get that updated.

charlespierce avatar Dec 03 '22 20:12 charlespierce

I really like this behaviour in a development environment, but I had the same question when looking for somthing a little more explicit to allow installing with volta as part of Docker build. Waiting for the first call feels like the wrong approach in this instance.

pughpugh avatar Feb 13 '23 17:02 pughpugh

+1 to the docker use case. having deterministic behavior for CI/CD purposes seems like a very important feature to me.

PhilippMolitor avatar Jun 06 '23 14:06 PhilippMolitor

I just got lost on this point for a little bit as well, I had a system node version installed and assumed that volta would fallback to the system node version when running commands. I discovered that was not the case and figured out after a little while that separately from volta setup you also need to run volta install node at least once before the automatic download behaviour kicks in.

As for the deterministic behaviour, I also agree that running volta install inside of a project with a "volta": {} section in its package.json would ideally install the pinned tools but for the CI/CD usage it seems that the volta team already provide: https://github.com/volta-cli/action

Should I open a separate issue for volta install behaviour?

Where in the documentation would the auto-install behaviour best be kept, likely as early on as the UNIX installation process as that is exactly where I would want to run volta install node to get everything primed?

vallode avatar Feb 01 '24 14:02 vallode

@vallode I'm not sure I totally follow—You shouldn't need to execute volta install node if you have a version pinned in your package.json. Is there case you have where that wasn't happening? Because that feels like a separate issue / bug that we should investigate!

If you don't have a version pinned, then you will need to use volta install node to select a default version—otherwise Volta wouldn't know which version to use 😄 In fact, the primary behavior of volta install node@{version} is to select that default version, we chose install as the verb for that command because it lined up with similar tools, but really the "install" part is secondary. There's long been a RFC in the back of my mind about changing those verbs to be more accurate and help make the mental model more clear. Naming things is hard 😅

charlespierce avatar Feb 01 '24 18:02 charlespierce

@charlespierce thank you for the prompt response. It looks like I must have been confused myself, I can't reproduce what I thought I was facing earlier (not being able to run node even in a project that has a pinned version). I attempted to wipe my volta install but the automatic download now kicks in as expected on the first attempt of running node or yarn. Beats me what it could have been, human error on my part probably (running the commands in a directory with no package.json?).

I agree that install is probably not the ideal verb in this scenario, where automatic installations are the standard. I think nvm likely uses use for this reason, separate from its install verb.

I think the issue would have been mitigated either way if the documentation more prominently tool the user to select a default node version, so hopefully all is well after the PR is merged into the docs :) Thanks!

vallode avatar Feb 01 '24 19:02 vallode

Yeah, the part that's been holding up changing the verb is figuring out what the right one is—I like use, but in Volta's case it has an overloaded meaning since it's ambiguous whether you mean "pin" (i.e. use in this project) or "default" (i.e. use as a backup). I think that volta pin actually does a nice job for the project-local verb, it's mostly a question of what is the most clear way to say "choose default"

Definitely open to suggestions, maybe I'll write up that RFC just to start a conversation 😄

charlespierce avatar Feb 01 '24 19:02 charlespierce