Shim
Version managers typically rely on either a shim or by directly modifying the PATH
environment variable when switching between versions. Both methods have their own advantages and disadvantages, but gruft
chose the shim method for the following reasons:
- Dynamic: We dynamically determine the version to use based on the repository configuration. Modifying the
PATH
environment variable on the fly would be prone to many edge cases. - Isolation: Modifying environment variables can have unintended side effects and can be difficult to debug. Shims keep the
PATH
environment variable relatively clean and untouched.
However, the shim method has its own disadvantages:
- Performance: Traditional shims that use
shell
are notorious for their performance overhead. We use an optimised compiled shim using TinyGo to help mitigate this issue which generally makes this overhead invisible in practice.
There are a few other disadvantages, such as hard to work with environment variables, but these do not affect this project's scope.
How It Works
The gruft
shim includes a few additional features that make it less like a traditional shim and more like a small CLI application. It does the following additonal logic:
- Scans the directory tree for a
gruft.toml
file and parses it to determine the version to use. - Handles version managing and downloading of binaries independently of the main CLI.
- Intercepts additional subcommands and flags such as
gruft use
to select a specific version.
After this additional logic, it then forwards the command to the main CLI which matches the requested version. For a minor performance boost, the main CLI is passed an additional --config-path
flag to skip scanning the directory tree again for the gruft.toml
file.