Skip to content

Commit 615f8bb

Browse files
authored
Support the 'funding' field. (dart-archive/pubspec_parse#83)
1 parent 622fee4 commit 615f8bb

File tree

5 files changed

+75
-2
lines changed

5 files changed

+75
-2
lines changed

pkgs/pubspec_parse/CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## 1.2.1-dev
22

3+
## 1.2.1
4+
5+
- Added support for `funding` field.
6+
37
## 1.2.0
48

59
- Added support for `screenshots` field.

pkgs/pubspec_parse/lib/src/pubspec.dart

+5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class Pubspec {
4040
/// view existing ones.
4141
final Uri? issueTracker;
4242

43+
/// Optional field to list the URLs where the package authors accept
44+
/// support or funding.
45+
final List<Uri>? funding;
46+
4347
/// Optional field for specifying included screenshot files.
4448
@JsonKey(fromJson: parseScreenshots)
4549
final List<Screenshot>? screenshots;
@@ -101,6 +105,7 @@ class Pubspec {
101105
this.homepage,
102106
this.repository,
103107
this.issueTracker,
108+
this.funding,
104109
this.screenshots,
105110
this.documentation,
106111
this.description,

pkgs/pubspec_parse/lib/src/pubspec.g.dart

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/pubspec_parse/pubspec.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pubspec_parse
22
description: >-
33
Simple package for parsing pubspec.yaml files with a type-safe API and rich
44
error reporting.
5-
version: 1.2.1-dev
5+
version: 1.2.1
66
repository: https://github.com/dart-lang/pubspec_parse
77

88
environment:
@@ -11,7 +11,7 @@ environment:
1111
dependencies:
1212
checked_yaml: ^2.0.1
1313
collection: ^1.15.0
14-
json_annotation: ^4.4.0
14+
json_annotation: ^4.6.0
1515
pub_semver: ^2.0.0
1616
yaml: ^3.0.0
1717

pkgs/pubspec_parse/test/parse_test.dart

+59
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ void main() {
4848
'documentation': 'documentation',
4949
'repository': 'https://github.com/example/repo',
5050
'issue_tracker': 'https://github.com/example/repo/issues',
51+
'funding': [
52+
'https://patreon.com/example',
53+
],
5154
'screenshots': [
5255
{'description': 'my screenshot', 'path': 'path/to/screenshot'}
5356
],
@@ -70,6 +73,8 @@ void main() {
7073
value.issueTracker,
7174
Uri.parse('https://github.com/example/repo/issues'),
7275
);
76+
expect(value.funding, hasLength(1));
77+
expect(value.funding!.single.toString(), 'https://patreon.com/example');
7378
expect(value.screenshots, hasLength(1));
7479
expect(value.screenshots!.first.description, 'my screenshot');
7580
expect(value.screenshots!.first.path, 'path/to/screenshot');
@@ -367,6 +372,60 @@ line 3, column 19: Unsupported value for "issue_tracker". type 'YamlMap' is not
367372
});
368373
});
369374

375+
group('funding', () {
376+
test('not a list', () {
377+
expectParseThrows(
378+
{
379+
...defaultPubspec,
380+
'funding': 1,
381+
},
382+
r'''
383+
line 6, column 13: Unsupported value for "funding". type 'int' is not a subtype of type 'List<dynamic>?' in type cast
384+
385+
6 │ "funding": 1
386+
│ ^
387+
╵''',
388+
skipTryPub: true,
389+
);
390+
});
391+
392+
test('not an uri', () {
393+
expectParseThrows(
394+
{
395+
...defaultPubspec,
396+
'funding': [1],
397+
},
398+
r'''
399+
line 6, column 13: Unsupported value for "funding". type 'int' is not a subtype of type 'String' in type cast
400+
401+
6 │ "funding": [
402+
│ ┌─────────────^
403+
7 │ │ 1
404+
8 │ └ ]
405+
╵''',
406+
skipTryPub: true,
407+
);
408+
});
409+
410+
test('not an uri', () {
411+
expectParseThrows(
412+
{
413+
...defaultPubspec,
414+
'funding': ['ht tps://example.com/'],
415+
},
416+
r'''
417+
line 6, column 13: Unsupported value for "funding". Illegal scheme character at offset 2.
418+
419+
6 │ "funding": [
420+
│ ┌─────────────^
421+
7 │ │ "ht tps://example.com/"
422+
8 │ └ ]
423+
╵''',
424+
skipTryPub: true,
425+
);
426+
});
427+
});
428+
370429
group('screenshots', () {
371430
test('one screenshot', () {
372431
final value = parse({

0 commit comments

Comments
 (0)