Skip to content

Commit 604be14

Browse files
committed
Remove uspport for .packages files.
Simplify (braking) API which no longer needs to support two files. Since this is breaking anyway, add `final` to classes, and make comparison operators on `LanguageVersion` instance methods. Add tool to query package configuration for a file or directory: `bin/package_config_of.dart`.
1 parent 9765c2a commit 604be14

14 files changed

+749
-1267
lines changed

pkgs/package_config/CHANGELOG.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
## 2.2.0-wip
1+
## 3.0.0
22

3-
- Add relational operators to `LanguageVersion` with extension methods
4-
exported under `LanguageVersionRelationalOperators`.
3+
- Removes support for the `.packages` file.
4+
The Dart SDK no longer supports that file, and no new `.packages` files
5+
will be generated.
56

6-
- Include correct parameter names in errors when validating
7-
the `major` and `minor` versions in the `LanguageVersion.new` constructor.
7+
- **Breaking change**
8+
Simplifies API that no longer needs to support two separate files.
9+
- Renamed `readAnyConfigFile` to `readConfigFile`, and removed
10+
the `preferNewest` parameter.
11+
- Same for `readAnyConfigFileUri` which becomes `readConfigFileUri`.
12+
13+
Also makes `PackageConfig`, `Package` and `LanguageVersion` final classes.
14+
15+
- Adds `PackageConfig.minVersion` to complement `.maxVersion`.
16+
Currently both are `2`.
17+
18+
- Adds relational operators to `LanguageVersion`.
19+
20+
- Includes correct parameter names in errors when validating
21+
the `major` and `minor` versions in the `LanguageVersion()` constructor.
822

923
## 2.1.1
1024

pkgs/package_config/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,5 @@ The primary libraries of this package are
2121
Just the `PackageConfig` class and other types needed to use
2222
package configurations. This library does not depend on `dart:io`.
2323

24-
The package includes deprecated backwards compatible functionality to
25-
work with the `.packages` file. This functionality will not be maintained,
26-
and will be removed in a future version of this package.
24+
The package no longer contains backwards compatible functionality to
25+
work with `.packages` files.

pkgs/package_config/lib/package_config.dart

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,27 @@ export 'package_config_types.dart';
2121

2222
/// Reads a specific package configuration file.
2323
///
24-
/// The file must exist and be readable.
25-
/// It must be either a valid `package_config.json` file
26-
/// or a valid `.packages` file.
27-
/// It is considered a `package_config.json` file if its first character
28-
/// is a `{`.
29-
///
30-
/// If the file is a `.packages` file (the file name is `.packages`)
31-
/// and [preferNewest] is true, the default, also checks if there is
32-
/// a `.dart_tool/package_config.json` file next
33-
/// to the original file, and if so, loads that instead.
34-
/// If [preferNewest] is set to false, a directly specified `.packages` file
35-
/// is loaded even if there is an available `package_config.json` file.
36-
/// The caller can determine this from the [PackageConfig.version]
37-
/// being 1 and look for a `package_config.json` file themselves.
24+
/// The file must exist, be readable and be a valid `package_config.json` file.
3825
///
3926
/// If [onError] is provided, the configuration file parsing will report errors
4027
/// by calling that function, and then try to recover.
4128
/// The returned package configuration is a *best effort* attempt to create
4229
/// a valid configuration from the invalid configuration file.
4330
/// If no [onError] is provided, errors are thrown immediately.
4431
Future<PackageConfig> loadPackageConfig(File file,
32+
{void Function(Object error)? onError}) =>
33+
readConfigFile(file, onError ?? throwError);
34+
35+
/// @nodoc
36+
@Deprecated('use loadPackageConfig instead')
37+
Future<PackageConfig> loadAnyPackageConfig(File file,
4538
{bool preferNewest = true, void Function(Object error)? onError}) =>
46-
readAnyConfigFile(file, preferNewest, onError ?? throwError);
39+
loadPackageConfig(file, onError: onError);
4740

4841
/// Reads a specific package configuration URI.
4942
///
50-
/// The file of the URI must exist and be readable.
51-
/// It must be either a valid `package_config.json` file
52-
/// or a valid `.packages` file.
53-
/// It is considered a `package_config.json` file if its first
54-
/// non-whitespace character is a `{`.
55-
///
56-
/// If [preferNewest] is true, the default, and the file is a `.packages` file,
57-
/// as determined by its file name being `.packages`,
58-
/// first checks if there is a `.dart_tool/package_config.json` file
59-
/// next to the original file, and if so, loads that instead.
60-
/// The [file] *must not* be a `package:` URI.
61-
/// If [preferNewest] is set to false, a directly specified `.packages` file
62-
/// is loaded even if there is an available `package_config.json` file.
63-
/// The caller can determine this from the [PackageConfig.version]
64-
/// being 1 and look for a `package_config.json` file themselves.
43+
/// The file of the URI must exist, be readable,
44+
/// and be a valid `package_config.json` file.
6545
///
6646
/// If [loader] is provided, URIs are loaded using that function.
6747
/// The future returned by the loader must complete with a [Uint8List]
@@ -88,15 +68,19 @@ Future<PackageConfig> loadPackageConfig(File file,
8868
/// If no [onError] is provided, errors are thrown immediately.
8969
Future<PackageConfig> loadPackageConfigUri(Uri file,
9070
{Future<Uint8List?> Function(Uri uri)? loader,
91-
bool preferNewest = true,
9271
void Function(Object error)? onError}) =>
93-
readAnyConfigFileUri(file, loader, onError ?? throwError, preferNewest);
72+
readConfigFileUri(file, loader, onError ?? throwError);
73+
74+
/// @nodoc
75+
@Deprecated('use loadPackageConfigUri instead')
76+
Future<PackageConfig> loadAnyPackageConfigUri(Uri uri,
77+
{bool preferNewest = true, void Function(Object error)? onError}) =>
78+
loadPackageConfigUri(uri, onError: onError);
9479

9580
/// Finds a package configuration relative to [directory].
9681
///
97-
/// If [directory] contains a package configuration,
98-
/// either a `.dart_tool/package_config.json` file or,
99-
/// if not, a `.packages`, then that file is loaded.
82+
/// If [directory] contains a `.dart_tool/package_config.json` file,
83+
/// then that file is loaded.
10084
///
10185
/// If no file is found in the current directory,
10286
/// then the parent directories are checked recursively,
@@ -129,9 +113,8 @@ Future<PackageConfig?> findPackageConfig(Directory directory,
129113

130114
/// Finds a package configuration relative to [location].
131115
///
132-
/// If [location] contains a package configuration,
133-
/// either a `.dart_tool/package_config.json` file or,
134-
/// if not, a `.packages`, then that file is loaded.
116+
/// If [location] contains a `.dart_tool/package_config.json`
117+
/// package configuration file or, then that file is loaded.
135118
/// The [location] URI *must not* be a `package:` URI.
136119
/// It should be a hierarchical URI which is supported
137120
/// by [loader].
@@ -189,9 +172,6 @@ Future<PackageConfig?> findPackageConfigUri(Uri location,
189172
/// If the `.dart_tool/` directory does not exist, it is created.
190173
/// If it cannot be created, this operation fails.
191174
///
192-
/// Also writes a `.packages` file in [directory].
193-
/// This will stop happening eventually as the `.packages` file becomes
194-
/// discontinued.
195175
/// A comment is generated if `[PackageConfig.extraData]` contains a
196176
/// `"generator"` entry.
197177
Future<void> savePackageConfig(

pkgs/package_config/lib/package_config_types.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,5 @@ export 'src/package_config.dart'
1717
show
1818
InvalidLanguageVersion,
1919
LanguageVersion,
20-
LanguageVersionRelationalOperators,
2120
Package,
2221
PackageConfig;

pkgs/package_config/lib/src/discovery.dart

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import 'dart:io';
66
import 'dart:typed_data';
77

88
import 'errors.dart';
9-
import 'package_config_impl.dart';
9+
import 'package_config.dart';
1010
import 'package_config_io.dart';
1111
import 'package_config_json.dart';
12-
import 'packages_file.dart' as packages_file;
1312
import 'util_io.dart' show defaultLoader, pathJoin;
1413

1514
final Uri packageConfigJsonPath = Uri(path: '.dart_tool/package_config.json');
16-
final Uri dotPackagesPath = Uri(path: '.packages');
1715
final Uri currentPath = Uri(path: '.');
1816
final Uri parentPath = Uri(path: '..');
1917

@@ -24,16 +22,13 @@ final Uri parentPath = Uri(path: '..');
2422
/// and stopping when something is found.
2523
///
2624
/// * Check if a `.dart_tool/package_config.json` file exists in the directory.
27-
/// * Check if a `.packages` file exists in the directory
28-
/// (if `minVersion <= 1`).
29-
/// * Repeat these checks for the parent directories until reaching the
25+
/// * Repeat this check for the parent directories until reaching the
3026
/// root directory if [recursive] is true.
3127
///
32-
/// If any of these tests succeed, a `PackageConfig` class is returned.
28+
/// If any such a test succeeds, a `PackageConfig` class is returned.
3329
/// Returns `null` if no configuration was found. If a configuration
3430
/// is needed, then the caller can supply [PackageConfig.empty].
3531
///
36-
/// If [minVersion] is greater than 1, `.packages` files are ignored.
3732
/// If [minVersion] is greater than the version read from the
3833
/// `package_config.json` file, it too is ignored.
3934
Future<PackageConfig?> findPackageConfig(Directory baseDirectory,
@@ -44,7 +39,6 @@ Future<PackageConfig?> findPackageConfig(Directory baseDirectory,
4439
return null;
4540
}
4641
do {
47-
// Check for $cwd/.packages
4842
var packageConfig =
4943
await findPackageConfigInDirectory(directory, minVersion, onError);
5044
if (packageConfig != null) return packageConfig;
@@ -87,13 +81,6 @@ Future<PackageConfig?> findPackageConfigUri(
8781
var config = parsePackageConfigBytes(bytes, file, onError);
8882
if (config.version >= minVersion) return config;
8983
}
90-
if (minVersion <= 1) {
91-
file = location.resolveUri(dotPackagesPath);
92-
bytes = await loader(file);
93-
if (bytes != null) {
94-
return packages_file.parse(bytes, file, onError);
95-
}
96-
}
9784
if (!recursive) break;
9885
var parent = location.resolveUri(parentPath);
9986
if (parent == location) break;
@@ -102,7 +89,7 @@ Future<PackageConfig?> findPackageConfigUri(
10289
return null;
10390
}
10491

105-
/// Finds a `.packages` or `.dart_tool/package_config.json` file in [directory].
92+
/// Finds a `.dart_tool/package_config.json` file in [directory].
10693
///
10794
/// Loads the file, if it is there, and returns the resulting [PackageConfig].
10895
/// Returns `null` if the file isn't there.
@@ -113,7 +100,6 @@ Future<PackageConfig?> findPackageConfigUri(
113100
/// a best-effort attempt is made to return a package configuration.
114101
/// This may be the empty package configuration.
115102
///
116-
/// If [minVersion] is greater than 1, `.packages` files are ignored.
117103
/// If [minVersion] is greater than the version read from the
118104
/// `package_config.json` file, it too is ignored.
119105
Future<PackageConfig?> findPackageConfigInDirectory(Directory directory,
@@ -124,12 +110,6 @@ Future<PackageConfig?> findPackageConfigInDirectory(Directory directory,
124110
if (config.version < minVersion) return null;
125111
return config;
126112
}
127-
if (minVersion <= 1) {
128-
packageConfigFile = await checkForDotPackagesFile(directory);
129-
if (packageConfigFile != null) {
130-
return await readDotPackagesFile(packageConfigFile, onError);
131-
}
132-
}
133113
return null;
134114
}
135115

@@ -140,9 +120,3 @@ Future<File?> checkForPackageConfigJsonFile(Directory directory) async {
140120
if (await file.exists()) return file;
141121
return null;
142122
}
143-
144-
Future<File?> checkForDotPackagesFile(Directory directory) async {
145-
var file = File(pathJoin(directory.path, '.packages'));
146-
if (await file.exists()) return file;
147-
return null;
148-
}

0 commit comments

Comments
 (0)