Intended change in behaviour
When the commands dart pub get or flutter pub get are executed, pub resolves all dependencies, and downloads those dependencies to the local pub cache. It furthermore creates a mapping from each used package to their location on the local file system. Today this mapping is stored in two files:
.dart_tool/package_config.json
.packages (legacy, as of Dart 2.8.0)
The former of these is the file that the current SDKs rely on. The latter has until now been generated for backwards compatibility with older Dart SDKs. After the present breaking change is made, we'll change pub get to only generate the former (.dart_tool/package_config.json), and the Dart SDK will no longer be able to read the .packages file.
Rationale for making the change
The .packages file is left-over from older Dart SDKs and is not fully compatible with Dart 2.x SDKs (it, for example, doesn’t support language versioning). We're removing the generation of .packages to prevent having extraneous files in the file system, and to prevent corner-case bugs that may occur if both files are around, but in an inconsistent state.
Expected impact of this change.
Regular apps and packages that are written using Dart 2.x will not be impacted, as they rely on .dart_tool/package_config.json.
If you already have a .packages file, you can delete it. After upgrading your Dart SDK it will no longer be generated, and pub will delete it when pub get runs.
Developer tools that need to look up the packages used by a project, and their locations on the file system, will no longer be able to rely on the .packages file. Such tools should be upgraded to rely on the content of the package_config.json file. Rather than reading this file directly, we strongly recommend using the API for consuming it available in package:package_config.
If you are passing a .packages file to the dart command (dart --packages=.packages) you'll need to pass the package config instead (dart --packages=.dart_tool/package_config.json).
Steps for mitigating the change
If you for some reason depend on this legacy file, you will for one stable release be able to generate it by passing the flag --legacy-packages-file to dart pub get / flutter pub get. After one stable release, this flag will be removed, and all support for generating the legacy file be removed. Note however this this is only being offered for external tools that may depend on the .packages file; all tools offered by the Dart team will no longer support this .packages file.
Timeline
The change to no longer generate .packages, and to remove support for reading that file in tools offered by the Dart team / the Dart SDK, will be made in a dev-channel release of Dart 2.18.
The --legacy-packages-file flag -- which offers a temporary solution for retaining the generation of .packages for other legacy tools -- will be removed one release later in a dev-channel release of Dart 2.19.
Related issues
In the Dart 2.18 stable release:
In the following Dart 2.19 stable release:
Intended change in behaviour
When the commands
dart pub getorflutter pub getare executed, pub resolves all dependencies, and downloads those dependencies to the local pub cache. It furthermore creates a mapping from each used package to their location on the local file system. Today this mapping is stored in two files:.dart_tool/package_config.json.packages(legacy, as of Dart 2.8.0)The former of these is the file that the current SDKs rely on. The latter has until now been generated for backwards compatibility with older Dart SDKs. After the present breaking change is made, we'll change
pub getto only generate the former (.dart_tool/package_config.json), and the Dart SDK will no longer be able to read the.packagesfile.Rationale for making the change
The
.packagesfile is left-over from older Dart SDKs and is not fully compatible with Dart 2.x SDKs (it, for example, doesn’t support language versioning). We're removing the generation of.packagesto prevent having extraneous files in the file system, and to prevent corner-case bugs that may occur if both files are around, but in an inconsistent state.Expected impact of this change.
Regular apps and packages that are written using Dart 2.x will not be impacted, as they rely on
.dart_tool/package_config.json.If you already have a
.packagesfile, you can delete it. After upgrading your Dart SDK it will no longer be generated, and pub will delete it when pub get runs.Developer tools that need to look up the packages used by a project, and their locations on the file system, will no longer be able to rely on the
.packagesfile. Such tools should be upgraded to rely on the content of thepackage_config.jsonfile. Rather than reading this file directly, we strongly recommend using the API for consuming it available inpackage:package_config.If you are passing a
.packagesfile to thedartcommand (dart --packages=.packages) you'll need to pass the package config instead (dart --packages=.dart_tool/package_config.json).Steps for mitigating the change
If you for some reason depend on this legacy file, you will for one stable release be able to generate it by passing the flag
--legacy-packages-filetodart pub get/flutter pub get. After one stable release, this flag will be removed, and all support for generating the legacy file be removed. Note however this this is only being offered for external tools that may depend on the.packagesfile; all tools offered by the Dart team will no longer support this.packagesfile.Timeline
The change to no longer generate
.packages, and to remove support for reading that file in tools offered by the Dart team / the Dart SDK, will be made in a dev-channel release of Dart 2.18.The
--legacy-packages-fileflag -- which offers a temporary solution for retaining the generation of.packagesfor other legacy tools -- will be removed one release later in a dev-channel release of Dart 2.19.Related issues
In the Dart 2.18 stable release:
.packages file: Stop producing .packages #47431, Stop generating.packagespub#2756.packages.packages: Remove CFE/analyzer/compiler/VM support for.packagesfile #48939.packagein mainsdkrepo: Remove.packagesfrom the Dart SDK repo #48275.packagesto detect if dependencies needs to be fetched Dart-Code/Dart-Code#3813package_configdart-archive/dart-services#834In the following Dart 2.19 stable release:
--legacy-packages-fileflag entirely: Discontinue--legacy-packages-fileflag pub#3496