Support the 'funding' field. (dart-lang/pubspec_parse#83)
diff --git a/pkgs/pubspec_parse/CHANGELOG.md b/pkgs/pubspec_parse/CHANGELOG.md index 6b5a04d..069e81c 100644 --- a/pkgs/pubspec_parse/CHANGELOG.md +++ b/pkgs/pubspec_parse/CHANGELOG.md
@@ -1,5 +1,9 @@ ## 1.2.1-dev +## 1.2.1 + +- Added support for `funding` field. + ## 1.2.0 - Added support for `screenshots` field.
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.dart b/pkgs/pubspec_parse/lib/src/pubspec.dart index 82c78aa..9943da8 100644 --- a/pkgs/pubspec_parse/lib/src/pubspec.dart +++ b/pkgs/pubspec_parse/lib/src/pubspec.dart
@@ -40,6 +40,10 @@ /// view existing ones. final Uri? issueTracker; + /// Optional field to list the URLs where the package authors accept + /// support or funding. + final List<Uri>? funding; + /// Optional field for specifying included screenshot files. @JsonKey(fromJson: parseScreenshots) final List<Screenshot>? screenshots; @@ -101,6 +105,7 @@ this.homepage, this.repository, this.issueTracker, + this.funding, this.screenshots, this.documentation, this.description,
diff --git a/pkgs/pubspec_parse/lib/src/pubspec.g.dart b/pkgs/pubspec_parse/lib/src/pubspec.g.dart index 221cc83..a1312a5 100644 --- a/pkgs/pubspec_parse/lib/src/pubspec.g.dart +++ b/pkgs/pubspec_parse/lib/src/pubspec.g.dart
@@ -27,6 +27,11 @@ 'repository', (v) => v == null ? null : Uri.parse(v as String)), issueTracker: $checkedConvert('issue_tracker', (v) => v == null ? null : Uri.parse(v as String)), + funding: $checkedConvert( + 'funding', + (v) => (v as List<dynamic>?) + ?.map((e) => Uri.parse(e as String)) + .toList()), screenshots: $checkedConvert( 'screenshots', (v) => parseScreenshots(v as List?)), documentation: $checkedConvert('documentation', (v) => v as String?),
diff --git a/pkgs/pubspec_parse/pubspec.yaml b/pkgs/pubspec_parse/pubspec.yaml index bb96369..23f15c1 100644 --- a/pkgs/pubspec_parse/pubspec.yaml +++ b/pkgs/pubspec_parse/pubspec.yaml
@@ -2,7 +2,7 @@ description: >- Simple package for parsing pubspec.yaml files with a type-safe API and rich error reporting. -version: 1.2.1-dev +version: 1.2.1 repository: https://github.com/dart-lang/pubspec_parse environment: @@ -11,7 +11,7 @@ dependencies: checked_yaml: ^2.0.1 collection: ^1.15.0 - json_annotation: ^4.4.0 + json_annotation: ^4.6.0 pub_semver: ^2.0.0 yaml: ^3.0.0
diff --git a/pkgs/pubspec_parse/test/parse_test.dart b/pkgs/pubspec_parse/test/parse_test.dart index 397a728..a12d034 100644 --- a/pkgs/pubspec_parse/test/parse_test.dart +++ b/pkgs/pubspec_parse/test/parse_test.dart
@@ -48,6 +48,9 @@ 'documentation': 'documentation', 'repository': 'https://github.com/example/repo', 'issue_tracker': 'https://github.com/example/repo/issues', + 'funding': [ + 'https://patreon.com/example', + ], 'screenshots': [ {'description': 'my screenshot', 'path': 'path/to/screenshot'} ], @@ -70,6 +73,8 @@ value.issueTracker, Uri.parse('https://github.com/example/repo/issues'), ); + expect(value.funding, hasLength(1)); + expect(value.funding!.single.toString(), 'https://patreon.com/example'); expect(value.screenshots, hasLength(1)); expect(value.screenshots!.first.description, 'my screenshot'); expect(value.screenshots!.first.path, 'path/to/screenshot'); @@ -367,6 +372,60 @@ }); }); + group('funding', () { + test('not a list', () { + expectParseThrows( + { + ...defaultPubspec, + 'funding': 1, + }, + r''' +line 6, column 13: Unsupported value for "funding". type 'int' is not a subtype of type 'List<dynamic>?' in type cast + ╷ +6 │ "funding": 1 + │ ^ + ╵''', + skipTryPub: true, + ); + }); + + test('not an uri', () { + expectParseThrows( + { + ...defaultPubspec, + 'funding': [1], + }, + r''' +line 6, column 13: Unsupported value for "funding". type 'int' is not a subtype of type 'String' in type cast + ╷ +6 │ "funding": [ + │ ┌─────────────^ +7 │ │ 1 +8 │ └ ] + ╵''', + skipTryPub: true, + ); + }); + + test('not an uri', () { + expectParseThrows( + { + ...defaultPubspec, + 'funding': ['ht tps://example.com/'], + }, + r''' +line 6, column 13: Unsupported value for "funding". Illegal scheme character at offset 2. + ╷ +6 │ "funding": [ + │ ┌─────────────^ +7 │ │ "ht tps://example.com/" +8 │ └ ] + ╵''', + skipTryPub: true, + ); + }); + }); + group('screenshots', () { test('one screenshot', () { final value = parse({