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

What is a shim? #1135

Open
bestlem opened this issue Jan 17, 2022 · 8 comments
Open

What is a shim? #1135

bestlem opened this issue Jan 17, 2022 · 8 comments
Labels

Comments

@bestlem
Copy link

bestlem commented Jan 17, 2022

The getting started document says

Volta does not use any fancy OS features or shell-specific hooks. It’s built on the simple, proven approach of shims.

That tells me nothing as I have never heard of shims. (I have been a Unix developer for 30 years so I will be able to understand what it does - as I don't know Rust I can't just read the code to see what it does)

Can you add to the documentation and explanation of what volta does.

@charlespierce
Copy link
Contributor

@bestlem Thanks for the suggestion! We'll definitely look at updating the docs to improve the description. In the short-term, "shim" here refers to an executable that sits between the command you type and the program you run. For Volta, we install a set of binaries (really they're all symlinks to the same binary, volta-shim) with the names of tools that we manage—node, npm, yarn, etc. We also make sure that the directory where those are installed is first in your PATH.

So when you run e.g. node, the normal OS PATH resolution finds the Volta binary and executes that. Volta then runs through its logic to determine the appropriate version of Node and calls out to that directly.

Does that help clarify the comment in the docs? Happy to dig in more if you have follow-up questions!

@bestlem
Copy link
Author

bestlem commented Jan 20, 2022

@charlespierce Yes thanks for that. I now understand and adding the second paragraph to the documentation as the main part and the first as detail would be good. (The second is the explanation the first and the idea of a him is just detail)

Also the bit which I found really confusing is

Whenever you install a tool with Volta, it adds a shim to your PATH that acts as an intelligent (and fast) router to the right version of the tool and runs it with the right Node engine.

I use conda for python which changes the PATH depending on the environment that it uses. Also many command line tools where you choose which version to use by py putting the directory to the specific directory it is in in your PATH. The wording "it adds a shim to your PATH" made me think volta did the same and altered the PATH to change the route to an executable. From your explanation PATH has nothing to do with the router. The shim executable is the thing that changes the route and you have to add the shim executable to the PATH,

@charlespierce
Copy link
Contributor

The wording "it adds a shim to your PATH" made me think volta did the same and altered the PATH to change the route to an executable.

Installing a new tool does add a shim to your PATH resolution, but not by modifying the PATH directly. The Volta installer updates your shell profile script (.zshrc, .bashrc, or similar) to add ~/.volta/bin to PATH. Then all of the shims are added to that directory. When you install a new tool, we create a new shim in that directory so that calls to that executable will be automatically routed through the shim.

@bestlem
Copy link
Author

bestlem commented Jan 21, 2022

The way I read that was it altered the PATH each rime you changed the node (or npm) version. Whilst the PATH only needs to be chnaged on installing volta

@charlespierce
Copy link
Contributor

Ahh, yeah, I can see how that line could read that way. I'll take a look and see if there's a more precise way we could describe how Volta works.

@shamrin
Copy link

shamrin commented Jan 28, 2022

Linking to Wikipedia may help: https://en.wikipedia.org/wiki/Shim_(computing)

@bestlem
Copy link
Author

bestlem commented Jan 28, 2022

@shamrin Yes that might give an overview but I think better to make the documentation describe how this particular project works.

@wll8
Copy link

wll8 commented Apr 21, 2022

How to automatically switch environments after switching directories?
Is this operation done when switching directories? Or is it done when running a specific program like node?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants