The Emergent Field of Interaction Architecture and the Future of Work

My friend proposed a simple game to our group: each person would put their favorite song from the past month into a shared playlist. Then we would go around, listen to each song, and talk about it…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




How to use Volta and why you should consider it over nvm

Node.js is alive and well, they’ve released version 17 into the ecosystem on October 19th, 2021. Along with Node.js 17 brings npm 8 and many cool new features. Now as you go to try it out, it’s also a good time to think about how you’re managing your toolchain.

Working on projects, big or small, it is important that all contributors are using the same versions of tools like node, npm, yarn, tsc, etc. This helps us mitigate both technical risks and potential business risks associated with it.

The best phrase I can think of to explain Volta is magic. Yep, it’s magic. It will magically (well, using a shim that proxies you to the right thing) get the right tool for you.

Now, I’m not just talking about node here, I'm talking about things like npm and tsc as well. Volta is so great that it can ensure everyone in your project uses the right typescript binaries from command line, instead of their potentially whack global version.

Although Volta still supports global versions, and requires you to do that first. But Volta will automagically switch to your project’s configured version if it’s specified.

Let’s start with a basic example. Jumping into a test project, let’s assume in production it was running on node v15 and npm v7. Let’s pin that to the project!

So wait, what just happened? You just configured your project with node 15 and npm 7. Nothing feels dramatic here, it’s an effortless feeling, all that we see is these few lines that have popped into the package.json file, lets grep for volta here:

Neat, I guess! So did it work?

It sure did! So now, whenever your terminal changes to this directory (or any of its subdirectories), Volta will (like magic) know to use that version. But hang on, what happens if we don’t have the version installed? Let me change my node version in the volta object to 15.13.0 and show you what happens.

As you can see, Volta detected that we don’t have that version installed and did it for us (again, magic!).

Lets move into the next example which is related to typescript. Using Volta we can install global tools as well, this way the binaries in that package become apart of our shell.

Take note here that typescript has been installed globally at version 4.5.2 and notes the executables tsc and tsserver. That really isn't interesting, npm can do that for us already - but we did this so tsc would be checked for in our path. I want it to use the version in my package. So lets add the beta version as a dev dependency for the sake of this demo:

Now you know how easy it is to set your version of node, tsc, and everything else in your path, plus ensure everyone else working on the project is on the same version. Let’s go ahead and upgrade node and npm, it’s simple: pin, and then commit your new package.json file!

It even warns you — and suggested to use the bundled version!

Hows this for thought — you could also consider using Volta in your Docker images, so that way even production matches up perfectly.

This is a bit more technical.

Volta does not use anything crazy. It uses a simple but verified method of shims. Whatever tool you install using Volta, it adds a shim to your PATH which acts as a router to the correct version, and don't worry it is fast.

So to elaborate, once you install a global version of say, tsc from the typescript package (you would have usually done this through yarn global add typescript) it will add it to your path.

Volta is keeping record of this in the ~/.volta/tools/user/bins/ directory, but dumps them into your path by create an alias to volta-shim in ~/.volta/bin/

When you run a shim, it will check for a package.json file (working back through your file path if it needs to) and find that volta key value set of versions to ensure it loads the correct version, if it can't find one it'll use the global default.

It creates a cache of these tools in the ~/.volta/tools/image/ directory so if it's not downloaded on your system, it grabs it for you.

Volta controls the version through it’s shim — you don’t have to update your path

Another nice perk is that Volta is created in rust (check it out on GitHub), which compiles down to a really slim and fast binary, whereas nvm is a node project which is why it is not as fast.

Are you in love?

For those that have access to a Unix shell, you can get started like this:

Thats it. Restart your command line tool, and enjoy! You can thank me later.

Add a comment

Related posts:

Easy NSAttributedString usage in Swift

If you are into iOS development you might have come across a UI screen which looks similar to the contents of below image. As there are multiple fonts and sizes involved in this, the better choice is…

Intel c600 series chipset driver windows 10

Download the Intel Chipset Software Installation 10.1.1.8 WHQL driver. This this one actually updates a lot of things. The Intel Chipset Software Installation Utility installs the Windows* INF. …

Human Beings are Social

Human behavior is affected by self-interest, tribalism, and cultural intelligence