Repository navigation
Conversation
|
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 |
b0f5986 to
cc9ff83
Compare
|
The dry-run output could use some polish - i don't mind the debug output if |
|
The output was fixed to make sense and adding the flag for |
57eda06 to
22f15d0
Compare
22f15d0 to
2e51789
Compare
This comment was marked as spam.
This comment was marked as spam.
|
@esguerrag are you no longer interested in adding this feature? |
This comment was marked as spam.
This comment was marked as spam.
|
@ljharb Yes, I'm still interested in landing this feature. Since this branch got a bit stale, I'll go ahead and open a fresh PR with an updated implementation shortly. |
|
I would vastly prefer you restore the branch and reopen the PR, and then force push whatever changes you want to that branch. |
2c0b952 to
ebd9b6f
Compare
|
@ljharb Understood. The PR is open again and rebased with one change. Thanks! |
nvm prune command to clean up old versionsprune command
ebd9b6f to
1122a76
Compare
ljharb
left a comment
There was a problem hiding this comment.
Thanks for working on this - pruning old versions is a nice feature to have. There are some problems that need fixing before it can land, though (inline below); the most important is that it currently deletes aliased versions, including default, and the aliases themselves.
A couple of broader things:
- Since this is a bulk, irreversible delete, I'd like it to show what it's going to remove and ask for confirmation (with a flag to skip the prompt for scripts), rather than requiring
--dry-runto see that ahead of time. Note that it also can't know which versions projects'.nvmrcfiles pin. - The help text should say what's kept: the newest per group, the current version, and (once fixed) anything an alias points to.
- Progress messages are only shown under
NVM_DEBUG=1; the "Pruning…"/"Dry run" lines seem worth showing normally.
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.