pub icon indicating copy to clipboard operation
pub copied to clipboard

Add support for cleaning cache for a specific package: `dart pub cache clean <package>`

Open Pingear opened this issue 1 year ago • 1 comments

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:

  1. Selective Cache Management: Developers can target specific packages for cache cleaning without affecting other dependencies.
  2. Improved Developer Experience: Reduces unnecessary re-downloading of unaffected packages, saving time and bandwidth.
  3. 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:

  1. Manually delete the cached package from the filesystem.
  2. 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.

Pingear avatar Dec 08 '24 00:12 Pingear

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.

sigurdm avatar Dec 09 '24 08:12 sigurdm