JavaScript developers live in a world of rapidly changing tool versions. It can be quite a chore to maintain the correct set of libraries and plugins for a solo developer. It’s much harder to do so across a team. It’s even harder for geographically distributed teams. Many hours are lost troubleshooting differences in library versions between environments.
Volta is an open-source project to simplify the management of environments. Volta claims to be the “Hassle-free JavaScript Tool Manager”. The Volta team released their 1.0 version in December 2020. Since we like hassle-free, and we like code, we needed a closer look at the tool.
Chuck Pierce, the lead maintainer of Volta, agreed to come on our React Wednesday show and demonstrate how Volta simplified JavaScript toolchain configuration and administration. During the broadcast, we took a look at Volta, discussed how Volta works, learned its origin story, and found out why the team chose Rust as the platform language. Chuck did a great job showing off the tool and taking questions from the audience. I encourage you to watch the broadcast. Below are some highlights from the show that are worth mentioning.
What is Volta?
Volta is a hassle-free way to manage your JavaScript command-line tools. Volta takes declarative configuration about which tools your project requires and then ensures the correct tools are installed and in scope for your project. Volta checks to see if it has a copy of the specified tool and version and if it does, Volta will make that available to your project, else Volta will download and install the correct version.
The creators of Volta designed the library to stay out of your way. We joked during the broadcast that a new tagline for Volta is “Works so good you’ll forget it’s installed”. You specify your tool configuration using declarative syntax, and Volta handles the tactical details to properly stand-up the environment to your liking.
Who needs Volta?
YOU do if you are the sort of person who wants to avoid diagnostic and troubleshooting work caused by version mismatches. It seems we all have many projects on our file system. You can tell the last time a project was run by the version of the libraries, sort of like the rings of a tree. Environments can get messy when versions compete with each other or are even just slightly different. Volta lets you configure the exact environment needed and then automatically orchestrates the setup and configuration.
A Practical Example of Volta Helping You Out
Imagine you had a project that used TypeScript. You have TypeScript v3.9 installed globally, but your project dependency is TypeScript 3.8. If TypeScript 3.8 was not installed in the project, likely your environment will be “helpful” by finding and using the globally installed TypeScript binary. This version mismatch could potentially cause problems with your project.
Volta will avoid calling the globally registered TypeScript binary and throw an error. This error will prevent the opportunity for your application to run on the wrong binary version.
How to Configure Environments with Volta
The configuration is available at the global or project level. You specify the recipe needed for your project using the familiar package.json file. You’ll need to insert a Volta key into the package.json file for node, and any package managers you use. Volta also provides CLI commands for convenience to set the version and write the appropriate configurations.
The rest of your project toolchain configuration is found in the regular ‘dependencies’ key in your package.json. Any package installable through a supported package manager is administrable by Volta.
Supported Package Managers:
- npm
- yarn
- npx
Coming Soon Package Managers:
- pnpm
- pnpx
How does Volta Work?
Volta creates shims for commands. A call process looks like this:
- A command is executed for a toolchain binary.
- Usually, the system will call the toolchain binary and execute the command, but Volta intercepts the command
- Volta validates the correct version of the binary is installed and available in the project directory.
- If the binary is not in place, Volta looks to see if it has a copy of the binary/version. If it does, Volta makes that binary available to the project. If not, it downloads and installs the binary/version and makes the binary available to the project directory.
- Volta executes the original command to the binary.
Because of this shim nature, the Volta team wanted to ensure there wouldn’t be undue performance issues arising from Volta serving as an intermediary. To squeeze maximum performance, the Volta team chose the Rust programming environment. Rust is a systems-level language with functional language capability. Rust is also cross-platform, allowing Volta to work on Windows, Mac, and Linux. Chuck said the impact of Volta is about 20ms, which is exceptionally lightweight, as I’m sure you’ll agree.
Who Sponsors the Development of Volta?
Chuck is an employee of LinkedIn. LinkedIn uses Volta internally and chose to make Volta available as an open-source project. Chuck primarily works on the Volta project. It is reassuring to know a dedicated resource is in charge of the project.
How is Volta Licensed?
Volta is licensed under the BSD 2-clause license. The BSD 2-clause license is highly permissive and free of weird requirements, so you’ll be able to use Volta in your projects, even if your organization requires a legal review of the license.
Where to Go for More Info on Volta