fix: Pubspec.environment can never be null (dart-lang/pubspec_parse#137)
* fix: Pubspec.environment can never be null
* chore: Add changelog entry
* fix: _environmentMap to return empty map when input is null
diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md
index 91613cc..2768cde 100644
--- a/pkgs/pubspec_parse/CHANGELOG.md
+++ b/pkgs/pubspec_parse/CHANGELOG.md
@@ -1,6 +1,7 @@
## 1.3.1-wip
- Require Dart 3.2
+- Set `Pubspec.environment` to non-nullable.
- Remove deprecated package_api_docs rule
## 1.3.0
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.dart b/pkgs/pubspec_parse/lib/src/pubspec.dart
index f6934ee..1317a23 100644
--- a/pkgs/pubspec_parse/lib/src/pubspec.dart
+++ b/pkgs/pubspec_parse/lib/src/pubspec.dart
@@ -74,7 +74,7 @@
final String? documentation;
@JsonKey(fromJson: _environmentMap)
- final Map<String, VersionConstraint?>? environment;
+ final Map<String, VersionConstraint?> environment;
@JsonKey(fromJson: parseDeps)
final Map<String, Dependency> dependencies;
@@ -186,7 +186,7 @@
Version? _versionFromString(String? input) =>
input == null ? null : Version.parse(input);
-Map<String, VersionConstraint?>? _environmentMap(Map? source) =>
+Map<String, VersionConstraint?> _environmentMap(Map? source) =>
source?.map((k, value) {
final key = k as String;
if (key == 'dart') {
@@ -222,4 +222,5 @@
}
return MapEntry(key, constraint);
- });
+ }) ??
+ {};