Add nvm prune command to clean up old versions#3792
Add nvm prune command to clean up old versions#3792esguerrag wants to merge 9 commits intonvm-sh:masterfrom
nvm prune command to clean up old versions#3792Conversation
|
To be clear, #1195 doesn't have a "PR wanted" label, so I'm still not convinced we should add this. The linked comment also says
That said, why would iojs versions be excluded? Also, it should probably indicate which versions it's about to remove that have global npm modules installed, since that's the only info that'll really be "lost". Personally, I want to have the latest version of every minor installed, not just every major. It would be nice to add a flag here to have that behavior. |
|
Can you also clarify if you used any LLMs to write the code (which might make it uncopyrightable and potentially not viable to contribute to open source) or the OP? |
|
Got it, now I understand the hesitation and since it wasn't discussed for a long time now I see why it wasn't added.
Thank you for your input and looking forward to solve any doubts. |
|
There's helpers to add or remove the prefixes, so you can compare the versions as one single list. How about That level of LLM usage is perfectly fine; thanks for confirming. |
|
I've just pushed the updates. I added the |
Description
This PR introduces a new command,
nvm prune, which allows users to easily clean up old, unused Node.js versions from their local installation while ensuring important versions are kept safe.Motivation
Over time, users accumulate many patch versions of Node.js (e.g.,
v14.17.0,v14.17.1,v14.17.2). Manually finding and uninstalling these old versions is tedious.nvm pruneautomates this maintenance task by keeping only the latest version of each major release installed. This also was requested back in 2016Behavior & Rules
When running
nvm prune, it iterates through all installed versions and applies the following retention policy for each version group:v16.1.0andv16.2.0,v16.2.0is kept).--minorflag is used, the command preserves the latest version of each minor group (e.g., keeps both the latestv18.19.xandv18.20.x).Features
--dry-runsupport: Preview which versions would be removed without actually deleting anything.Implementation Details
grep -o(GNU extension) with standardawk.sort -V(GNU extension) to use standardsortwith field keys (-k 1.2,1n ...) to ensure correct version ordering on all systems.nvmcommand switch.Usage Examples
Test Plan
nvm prune --dry-runlists candidates without uninstalling.nvm prunecorrectly identifies the "latest" version per major version group.nvm prunedoes not remove the currently active version.bashandzsh.