Skip to content

Commit 50e0308

Browse files
committed
Remove support for .packages files.
Simplify API which no longer needs to support two files. (Replaces two existing functions with different ones. The old methods are retained as deprecated, and will be removed in a future release.) Adds `@sealed` to model classes in anticipation of making them `final` or `sealed` classes in the future. Add tool to query the package configuration for a file or directory: `bin/package_config_of.dart PATH`.
1 parent d921e01 commit 50e0308

9 files changed

+119
-146
lines changed

pkgs/package_config/CHANGELOG.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
1-
## 3.0.0-wip
1+
## 2.3.0-wip
22

33
- Removes support for the `.packages` file.
44
The Dart SDK no longer supports that file, and no new `.packages` files
55
will be generated.
6+
Since the SDK requirement for this package is above 3.0.0,
7+
no supporting SDK can use or generate `.packages`.
68

7-
- **Breaking change**
8-
Simplifies API that no longer needs to support two separate files.
9+
- Simplifies API that no longer needs to support two separate files.
910
- Renamed `readAnyConfigFile` to `readConfigFile`, and removed
1011
the `preferNewest` parameter.
1112
- Same for `readAnyConfigFileUri` which becomes `readConfigFileUri`.
13+
- Old functions still exists as deprecated, forwarding to the new
14+
functions without the `preferNewest` argument.
1215

13-
Also makes `PackageConfig`, `Package` and `LanguageVersion` final classes.
16+
Also makes `PackageConfig`, `Package` and `LanguageVersion` `@sealed` classes,
17+
in preparation for making them `final` in a future update.
1418

1519
- Adds `PackageConfig.minVersion` to complement `.maxVersion`.
1620
Currently both are `2`.
1721

18-
- Adds relational operators to `LanguageVersion`.
22+
## 2.2.0
1923

20-
- Includes correct parameter names in errors when validating
21-
the `major` and `minor` versions in the `LanguageVersion()` constructor.
24+
- Add relational operators to `LanguageVersion` with extension methods
25+
exported under `LanguageVersionRelationalOperators`.
26+
27+
- Include correct parameter names in errors when validating
28+
the `major` and `minor` versions in the `LanguageVersion.new` constructor.
2229

2330
## 2.1.1
2431

pkgs/package_config/lib/package_config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Future<PackageConfig> loadAnyPackageConfig(File file,
4141
/// Reads a specific package configuration URI.
4242
///
4343
/// The file of the URI must exist, be readable,
44-
/// and be a valid `package_config.json` file.
44+
/// and be a valid `package_config.json` file.
4545
///
4646
/// If [loader] is provided, URIs are loaded using that function.
4747
/// The future returned by the loader must complete with a [Uint8List]
@@ -54,7 +54,7 @@ Future<PackageConfig> loadAnyPackageConfig(File file,
5454
/// As such, it may throw any error that [loader] throws.
5555
///
5656
/// If no [loader] is supplied, a default loader is used which
57-
/// only accepts `file:`, `http:` and `https:` URIs,
57+
/// only accepts `file:`, `http:` and `https:` URIs,
5858
/// and which uses the platform file system and HTTP requests to
5959
/// fetch file content. The default loader never throws because
6060
/// of an I/O issue, as long as the location URIs are valid.

pkgs/package_config/lib/package_config_types.dart

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

pkgs/package_config/lib/src/package_config.dart

Lines changed: 89 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import 'dart:typed_data';
66

7+
import 'package:meta/meta.dart' show sealed;
8+
79
import 'errors.dart';
810
import 'package_config_json.dart';
911
import 'util.dart';
@@ -15,7 +17,8 @@ import 'util.dart';
1517
/// More members may be added to this class in the future,
1618
/// so classes outside of this package must not implement [PackageConfig]
1719
/// or any subclass of it.
18-
abstract final class PackageConfig {
20+
@sealed
21+
abstract class PackageConfig {
1922
/// The lowest configuration version currently supported.
2023
static const int minVersion = 2;
2124

@@ -213,7 +216,8 @@ abstract final class PackageConfig {
213216
}
214217

215218
/// Configuration data for a single package.
216-
abstract final class Package {
219+
@sealed
220+
abstract class Package {
217221
/// Creates a package with the provided properties.
218222
///
219223
/// The [name] must be a valid package name.
@@ -301,7 +305,8 @@ abstract final class Package {
301305
/// If errors during parsing are handled using an `onError` handler,
302306
/// then an *invalid* language version may be represented by an
303307
/// [InvalidLanguageVersion] object.
304-
abstract final class LanguageVersion implements Comparable<LanguageVersion> {
308+
@sealed
309+
abstract class LanguageVersion implements Comparable<LanguageVersion> {
305310
/// The maximal value allowed by [major] and [minor] values;
306311
static const int maxValue = 0x7FFFFFFF;
307312

@@ -368,40 +373,6 @@ abstract final class LanguageVersion implements Comparable<LanguageVersion> {
368373
@override
369374
int compareTo(LanguageVersion other);
370375

371-
/// Whether this language version is less than [other].
372-
///
373-
/// If either version being compared is an [InvalidLanguageVersion],
374-
/// a [StateError] is thrown. Verify versions are valid before comparing them.
375-
///
376-
/// For details on how valid language versions are compared,
377-
/// check out [LanguageVersion.compareTo].
378-
bool operator <(LanguageVersion other);
379-
380-
/// Whether this language version is less than or equal to [other].
381-
///
382-
/// If either version being compared is an [InvalidLanguageVersion],
383-
/// a [StateError] is thrown. Verify versions are valid before comparing them.
384-
///
385-
/// For details on how valid language versions are compared,
386-
/// check out [LanguageVersion.compareTo].
387-
bool operator <=(LanguageVersion other);
388-
389-
/// Whether this language version is greater than [other].
390-
///
391-
/// Neither version being compared must be an [InvalidLanguageVersion].
392-
///
393-
/// For details on how valid language versions are compared,
394-
/// check out [LanguageVersion.compareTo].
395-
bool operator >(LanguageVersion other);
396-
397-
/// Whether this language version is greater than or equal to [other].
398-
///
399-
/// Neither version being compared must be an [InvalidLanguageVersion].
400-
///
401-
/// For details on how valid language versions are compared,
402-
/// check out [LanguageVersion.compareTo].
403-
bool operator >=(LanguageVersion other);
404-
405376
/// Valid language versions with the same [major] and [minor] values are
406377
/// equal.
407378
///
@@ -428,7 +399,8 @@ abstract final class LanguageVersion implements Comparable<LanguageVersion> {
428399
/// which did not throw on an error.
429400
/// The caller which provided the `onError` handler which was called
430401
/// should be prepared to encounter invalid values.
431-
abstract final class InvalidLanguageVersion implements LanguageVersion {
402+
@sealed
403+
abstract class InvalidLanguageVersion implements LanguageVersion {
432404
/// The value -1 for an invalid language version.
433405
@override
434406
int get major;
@@ -449,14 +421,83 @@ abstract final class InvalidLanguageVersion implements LanguageVersion {
449421
String toString();
450422
}
451423

424+
/// Relational operators for [LanguageVersion].
425+
///
426+
/// Compares valid versions with [LanguageVersion.compareTo],
427+
/// and rejects invalid versions.
428+
///
429+
/// Versions should be verified as valid before using them.
430+
extension LanguageVersionRelationalOperators on LanguageVersion {
431+
/// Whether this language version is less than [other].
432+
///
433+
/// Neither version being compared must be an [InvalidLanguageVersion].
434+
///
435+
/// For details on how valid language versions are compared,
436+
/// check out [LanguageVersion.compareTo].
437+
bool operator <(LanguageVersion other) {
438+
// Throw an error if comparing an invalid language version.
439+
if (this is InvalidLanguageVersion) _throwThisInvalid();
440+
if (other is InvalidLanguageVersion) _throwOtherInvalid();
441+
return compareTo(other) < 0;
442+
}
443+
444+
/// Whether this language version is less than or equal to [other].
445+
///
446+
/// Neither version being compared must be an [InvalidLanguageVersion].
447+
///
448+
/// For details on how valid language versions are compared,
449+
/// check out [LanguageVersion.compareTo].
450+
bool operator <=(LanguageVersion other) {
451+
// Throw an error if comparing an invalid language version.
452+
if (this is InvalidLanguageVersion) _throwThisInvalid();
453+
if (other is InvalidLanguageVersion) _throwOtherInvalid();
454+
return compareTo(other) <= 0;
455+
}
456+
457+
/// Whether this language version is greater than [other].
458+
///
459+
/// Neither version being compared must be an [InvalidLanguageVersion].
460+
///
461+
/// For details on how valid language versions are compared,
462+
/// check out [LanguageVersion.compareTo].
463+
bool operator >(LanguageVersion other) {
464+
// Throw an error if comparing an invalid language version.
465+
if (this is InvalidLanguageVersion) _throwThisInvalid();
466+
if (other is InvalidLanguageVersion) _throwOtherInvalid();
467+
return compareTo(other) > 0;
468+
}
469+
470+
/// Whether this language version is greater than or equal to [other].
471+
///
472+
/// If either version being compared is an [InvalidLanguageVersion],
473+
/// a [StateError] is thrown. Verify versions are valid before comparing them.
474+
///
475+
/// For details on how valid language versions are compared,
476+
/// check out [LanguageVersion.compareTo].
477+
bool operator >=(LanguageVersion other) {
478+
// Throw an error if comparing an invalid language version.
479+
if (this is InvalidLanguageVersion) _throwThisInvalid();
480+
if (other is InvalidLanguageVersion) _throwOtherInvalid();
481+
return compareTo(other) >= 0;
482+
}
483+
484+
static Never _throwThisInvalid() => throw UnsupportedError(
485+
'Can\'t compare an invalid language version to another language version. '
486+
'Verify language versions are valid before use.');
487+
static Never _throwOtherInvalid() => throw UnsupportedError(
488+
'Can\'t compare a language version to an invalid language version. '
489+
'Verify language versions are valid before use.');
490+
}
491+
452492
// --------------------------------------------------------------------
453-
// Implementation of interfaces.
493+
// Implementation of interfaces. Not exported by top-level libraries.
454494

455495
const bool _disallowPackagesInsidePackageUriRoot = false;
456496

457497
// Implementations of the main data types exposed by the API of this package.
458498

459-
final class SimplePackageConfig implements PackageConfig {
499+
@sealed
500+
class SimplePackageConfig implements PackageConfig {
460501
@override
461502
final int version;
462503
final Map<String, Package> _packages;
@@ -620,7 +661,8 @@ final class SimplePackageConfig implements PackageConfig {
620661
}
621662

622663
/// Configuration data for a single package.
623-
final class SimplePackage implements Package {
664+
@sealed
665+
class SimplePackage implements Package {
624666
@override
625667
final String name;
626668
@override
@@ -779,7 +821,8 @@ LanguageVersion parseLanguageVersion(
779821
return SimpleLanguageVersion(major, minor, source);
780822
}
781823

782-
abstract final class _SimpleLanguageVersionBase implements LanguageVersion {
824+
@sealed
825+
abstract class _SimpleLanguageVersionBase implements LanguageVersion {
783826
@override
784827
int compareTo(LanguageVersion other) {
785828
var result = major - other.major;
@@ -788,7 +831,8 @@ abstract final class _SimpleLanguageVersionBase implements LanguageVersion {
788831
}
789832
}
790833

791-
final class SimpleLanguageVersion extends _SimpleLanguageVersionBase {
834+
@sealed
835+
class SimpleLanguageVersion extends _SimpleLanguageVersionBase {
792836
@override
793837
final int major;
794838
@override
@@ -805,66 +849,10 @@ final class SimpleLanguageVersion extends _SimpleLanguageVersionBase {
805849

806850
@override
807851
String toString() => _source ??= '$major.$minor';
808-
809-
/// Whether this language version is less than [other].
810-
///
811-
/// Neither version being compared must be an [InvalidLanguageVersion].
812-
///
813-
/// For details on how valid language versions are compared,
814-
/// check out [LanguageVersion.compareTo].
815-
@override
816-
bool operator <(LanguageVersion other) {
817-
// Throw an error if comparing with an invalid language version.
818-
if (other is InvalidLanguageVersion) _throwOtherInvalid();
819-
820-
return compareTo(other) < 0;
821-
}
822-
823-
/// Whether this language version is less than or equal to [other].
824-
///
825-
/// Neither version being compared must be an [InvalidLanguageVersion].
826-
///
827-
/// For details on how valid language versions are compared,
828-
/// check out [LanguageVersion.compareTo].
829-
@override
830-
bool operator <=(LanguageVersion other) {
831-
// Throw an error if comparing with an invalid language version.
832-
if (other is InvalidLanguageVersion) _throwOtherInvalid();
833-
return compareTo(other) <= 0;
834-
}
835-
836-
/// Whether this language version is greater than [other].
837-
///
838-
/// Neither version being compared must be an [InvalidLanguageVersion].
839-
///
840-
/// For details on how valid language versions are compared,
841-
/// check out [LanguageVersion.compareTo].
842-
@override
843-
bool operator >(LanguageVersion other) {
844-
if (other is InvalidLanguageVersion) _throwOtherInvalid();
845-
return compareTo(other) > 0;
846-
}
847-
848-
/// Whether this language version is greater than or equal to [other].
849-
///
850-
/// If either version being compared is an [InvalidLanguageVersion],
851-
/// a [StateError] is thrown. Verify versions are valid before comparing them.
852-
///
853-
/// For details on how valid language versions are compared,
854-
/// check out [LanguageVersion.compareTo].
855-
@override
856-
bool operator >=(LanguageVersion other) {
857-
// Throw an error if comparing with an invalid language version.
858-
if (other is InvalidLanguageVersion) _throwOtherInvalid();
859-
return compareTo(other) >= 0;
860-
}
861-
862-
static Never _throwOtherInvalid() => throw StateError(
863-
'Can\'t compare a language version to an invalid language version. '
864-
'Verify language versions are valid after parsing.');
865852
}
866853

867-
final class SimpleInvalidLanguageVersion extends _SimpleLanguageVersionBase
854+
@sealed
855+
class SimpleInvalidLanguageVersion extends _SimpleLanguageVersionBase
868856
implements InvalidLanguageVersion {
869857
final String? _source;
870858
SimpleInvalidLanguageVersion(this._source);
@@ -873,32 +861,8 @@ final class SimpleInvalidLanguageVersion extends _SimpleLanguageVersionBase
873861
@override
874862
int get minor => -1;
875863

876-
@override
877-
bool operator <(LanguageVersion other) {
878-
_throwThisInvalid();
879-
}
880-
881-
@override
882-
bool operator <=(LanguageVersion other) {
883-
_throwThisInvalid();
884-
}
885-
886-
@override
887-
bool operator >(LanguageVersion other) {
888-
_throwThisInvalid();
889-
}
890-
891-
@override
892-
bool operator >=(LanguageVersion other) {
893-
_throwThisInvalid();
894-
}
895-
896864
@override
897865
String toString() => _source!;
898-
899-
static Never _throwThisInvalid() => throw StateError(
900-
'Can\'t compare an invalid language version to another language version. '
901-
'Verify language versions are valid after parsing.');
902866
}
903867

904868
abstract class PackageTree {

pkgs/package_config/pubspec.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
name: package_config
2-
version: 3.0.0-wip
2+
version: 2.3.0-wip
33
description: Support for reading and writing Dart Package Configuration files.
44
repository: https://github.com/dart-lang/tools/tree/main/pkgs/package_config
55
issue_tracker: https://github.com/dart-lang/tools/labels/package%3Apackage_config
66

77
environment:
8-
sdk: ^3.4.0
8+
sdk: ^3.7.0
99

1010
dependencies:
11+
meta: ^1.15.0
1112
path: ^1.8.0
1213

1314
dev_dependencies:
14-
dart_flutter_team_lints: ^3.1.0
15+
dart_flutter_team_lints: ^3.4.0
1516
test: ^1.16.0

0 commit comments

Comments
 (0)