dart-lang/sdk

Issue with Dart pub cache since 3.0 launch on windows

slightfoot opened this issue · 4 comments

TLDR; Pub changed its cache directory location on Windows and did not move the data or update the PATH and warn the user.

Example:

# melos exec -- flutter pub get
Can't load Kernel binary: Invalid kernel binary format version.

This is usual behaviour with pub global binaries after upgrade of Dart as the snapshot kernel format for the compiled Dart code has changed. It then recompiles the snapshot and all is well.

However, even after the normal recompilation. The error message persists.
This is because melos re-executes itself and it's executing a previous version. This is not a melos specific issue as it also occurs with other previously installed globally activated binaries.

This is because the pub global cache directory has moved. So new binaries/scripts are being created in the new directory and not the old one. Without any warning to remove the old one from the PATH, or to have those binaries/scripts removed.

Flutter 3.7 / Dart 2.19

C:\Users\<user>\AppData\Roaming\Pub\Cache\bin

Flutter 3.10 / Dart 3.0

C:\Users\<user>\AppData\Local\Pub\Cache\bin

With the directory change without the movement of files from one to the other. I have also "lost" the pub publish credentials for packages as that remains in the old directory.

I also lost 15 GB of disk space to the old directory not being deleted, since there was no deletion policy from the upgrade. Not to mention the re-download of all of the pub packages to the new directory using up bandwith. For me this is not an issue, but for some developers in other situations where they pay for the data they download.

I have now updated my PATH and moved my credentials over and removed the old directory and all is well.

There are two changes here:

  • (A) dart-lang/pub#3831
    • Stop looking for PUB_CACHE in %APPDATA%.
    • We haven't created PUB_CACHE folders in %APPDATA% since Dart 2.8
  • (B) dart-lang/pub#3824
    • Stop looking for the old credentials.json file.
    • We haven't created PUB_CACHE/credentials.json since Dart 2.15

The impact of (B) is merely that the user have to sign-in again. An annoyance, but keeping credentials out of the PUB_CACHE is probably a good idea. One could imagine someone caching the PUB_CACHE between builds on a CI system.

I don't think we've considered all the impacts of (A). Especially, not around PATH and globally activated packages.

I think (A) should affect users who have been using Dart since before 2.8, but that's also a sizable number of people.

I also lost 15 GB of disk space to the old directory not being deleted,

Hmm, I suppose a warning message that encouraged users to delete the old folder would be fairly harmless.
Even if a user is using both new and old Dart SDKs, they are probably not using something older than Dart 2.8, which would recreated the PUB_CACHE in the old location.

I'm not sure (A) is something we should revert. I could be convinced, but I think that moving the PUB_CACHE to %LOCALAPPDATA% is a good thing. So doing it as part of Dart 3 seems reasonable.

It probably won't affect most users, but if you are using school or corporate system where %APPDATA% is sync'ed between machines, it's probably bad to have your entire pub-cache transferred as part of your user profile.

We could do a notice message encourage users to delete the old pub-cache. That would help users reclaim some disk space :D

Rather than reverting -- which would out is back mid-stream with two different cache locations -- I suggest we implement the suggested warning message that encourages users to delete the old folder, and update path + then cherry pick that.