Repository navigation
[New] add prune command
#3792
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
esguerrag
wants to merge
3
commits into
nvm-sh:master
Choose a base branch
from
esguerrag:prune-outdated-versions
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+739
−0
Open
[New] add prune command
#3792
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Test: Running 'nvm prune' should remove old versions | ||
|
|
||
| die () { echo "$@" ; exit 1; } | ||
|
|
||
| # Mocking nvm_ls output logic relies on nvm_ls calling directory listing. | ||
| # Instead of mocking filesystem which is complex, we will override nvm_ls and nvm_ls_current. | ||
|
|
||
| . ../../nvm.sh | ||
|
|
||
| # Mock nvm_ls to return specific versions as if they were installed | ||
| # The implementation of nvm_prune calls: nvm_ls --no-colors --no-alias | ||
| # We must mock nvm_ls to respond to that or just return the list. | ||
| # Note: nvm_prune strips output except vX.Y.Z. | ||
| nvm_ls() { | ||
| echo " v16.20.2" | ||
| echo " v18.20.5" | ||
| echo " v18.20.7" | ||
| echo " v20.17.0" | ||
| echo "-> v22.22.0" | ||
| echo " v24.13.0" | ||
| } | ||
|
|
||
| # Mock nvm_ls_current | ||
| nvm_ls_current() { | ||
| echo "v22.22.0" | ||
| } | ||
|
|
||
| # Mock nvm_is_version_installed | ||
| nvm_is_version_installed() { | ||
| return 0 | ||
| } | ||
|
|
||
| # Mock nvm function to intercept uninstall calls | ||
| # nvm_prune calls `nvm uninstall`. | ||
| UNINSTALLED_VERSIONS="" | ||
| nvm() { | ||
| if [ "$1" = "uninstall" ]; then | ||
| UNINSTALLED_VERSIONS="${UNINSTALLED_VERSIONS} $2" | ||
| return 0 | ||
| fi | ||
| echo "nvm called with unexpected args: $*" | ||
| } | ||
|
|
||
| # Run prune | ||
| nvm_prune | ||
|
|
||
| # Expected: | ||
| # v16.20.2 (Keep: Only one v16) | ||
| # v18.20.5 (Delete: v18.20.7 is newer) -> WAIT. v18.20.7 is newer. So keep 18.20.7. Delete 18.20.5. | ||
| # v18.20.7 (Keep: Latest v18) | ||
| # v20.17.0 (Keep: Only one v20) | ||
| # v22.22.0 (Keep: Current) | ||
| # v24.13.0 (Keep: Only one v24) | ||
|
|
||
| # Wait, my logic for nvm_prune was to keep latest per major. | ||
|
esguerrag marked this conversation as resolved.
Outdated
|
||
| # v18.20.5 and v18.20.7 are Major 18. | ||
| # Latest is v18.20.7. | ||
| # So v18.20.5 should be pruned. | ||
|
|
||
| # Check UNINSTALLED_VERSIONS | ||
| EXPECTED=" v18.20.5" | ||
| if [ "${UNINSTALLED_VERSIONS}" != "${EXPECTED}" ]; then | ||
| die "Expected uninstalled: '${EXPECTED}', got: '${UNINSTALLED_VERSIONS}'" | ||
| fi | ||
|
|
||
| # New Test Case: Current version is NOT the latest. | ||
| # v18.1.0 (Current) | ||
| # v18.2.0 (Latest) | ||
| # v18.0.0 (Old) | ||
|
|
||
| nvm_ls() { | ||
| echo " v18.0.0" | ||
| echo "-> v18.1.0" | ||
| echo " v18.2.0" | ||
| } | ||
|
|
||
| nvm_ls_current() { | ||
| echo "v18.1.0" | ||
| } | ||
|
|
||
| UNINSTALLED_VERSIONS="" | ||
| nvm_prune | ||
|
|
||
| # Expected: | ||
| # v18.0.0 (Prune) | ||
| # v18.1.0 (Keep: Current) | ||
| # v18.2.0 (Keep: Latest) | ||
|
|
||
| EXPECTED=" v18.0.0" | ||
|
|
||
| if [ "${UNINSTALLED_VERSIONS}" != "${EXPECTED}" ]; then | ||
| die "TestCase 2 Failed. Expected uninstalled: '${EXPECTED}', got: '${UNINSTALLED_VERSIONS}'" | ||
| fi | ||
|
|
||
| echo "All tests passed" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.