Add support for cleaning cache for a specific package: `dart pub cache clean <package>`
Currently, the dart pub cache clean command removes all cached packages, which can be inconvenient when a developer only needs to refresh the cache for a single package. This is particularly relevant when working with Git dependencies, as changes to a Git-based package do not trigger automatic updates unless the version or commit reference changes.
Feature Request:
Introduce a feature in the dart pub cache command to allow developers to clean the cache for a specific package without affecting the entire cache. The proposed syntax could be:
dart pub cache clean <package-name>
Benefits:
- Selective Cache Management: Developers can target specific packages for cache cleaning without affecting other dependencies.
- Improved Developer Experience: Reduces unnecessary re-downloading of unaffected packages, saving time and bandwidth.
- Consistency with Modern Tools: Many package managers (e.g., npm, pip) support selective cache cleaning for specific packages.
Use Case:
For example, when a Git dependency (my_package) is updated in the remote repository but retains the same version in pubspec.yaml, developers currently need to either:
- Manually delete the cached package from the filesystem.
- Clear the entire cache, which forces unnecessary downloads.
With this feature, developers could simply run:
dart pub cache clean my_package
dart pub get
This enhancement would streamline workflows for projects using Git dependencies or frequently updated packages.
Yeah - I this is a good idea.
We could have two variants, something like:
dart pub cache clean --current-project
Which removes all packages depended on by the current project (the current package_config.json).
and
dart pub cache remove <package>
Which removes a single package from the cache.
For the second one we probably need a way to also remove git packages, and a way to remove from specific hosts.