Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/pubspec_parse/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Preserve nested `Map` (`YamlMap`) keys and spans when `git` or `hosted`
dependency shorthands fail to parse or when `Pubspec.fromJson` is called with
a non-`YamlMap` `Map`.
- Added `platforms` field to `Pubspec`.

## 1.6.0

Expand Down
9 changes: 9 additions & 0 deletions pkgs/pubspec_parse/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,14 @@ class Pubspec {
/// Specifies how to resolve dependencies with the surrounding Pub Workspace.
final String? resolution;

/// The platforms this package explicitly declares support for.
///
/// Keys are platform names, such as `android`, `ios`, `linux`, `macos`,
/// `web` and `windows`. Values are currently always `null`.
///
/// See https://dart.dev/tools/pub/pubspec#platforms.
final Map<String, Object?>? platforms;

/// If [author] and [authors] are both provided, their values are combined
/// with duplicates eliminated.
Pubspec(
Expand All @@ -121,6 +129,7 @@ class Pubspec {
this.description,
this.workspace,
this.resolution,
this.platforms,
Map<String, Dependency>? dependencies,
Map<String, Dependency>? devDependencies,
Map<String, Dependency>? dependencyOverrides,
Expand Down
5 changes: 5 additions & 0 deletions pkgs/pubspec_parse/lib/src/pubspec.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions pkgs/pubspec_parse/test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ void main() {
expect(value.workspace, isNull);
expect(value.resolution, isNull);
expect(value.executables, isEmpty);
expect(value.platforms, isNull);
});

test('all fields set', () async {
Expand All @@ -58,6 +59,7 @@ void main() {
],
'workspace': ['pkg1', 'pkg2'],
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -101,6 +103,7 @@ void main() {
expect(value.workspace!.first, 'pkg1');
expect(value.workspace!.last, 'pkg2');
expect(value.resolution, 'workspace');
expect(value.platforms, {'android': null, 'web': null});
});

test('environment values can be null', () async {
Expand Down Expand Up @@ -398,6 +401,34 @@ line 4, column 10: Unsupported value for "sdk". Could not parse version "silly".
});
});

group('platforms', () {
test('map with null values', () async {
final value = await parse({
...defaultPubspec,
'platforms': {'android': null, 'ios': null, 'web': null},
});
expect(value.platforms, {'android': null, 'ios': null, 'web': null});
});

test('not a map', () {
expectParseThrowsContaining(
{...defaultPubspec, 'platforms': 1},
"Unsupported value for \"platforms\". type 'int' is not a subtype of type 'Map<dynamic, dynamic>?'",
skipTryPub: true,
);
});

test('invalid data - lenient', () async {
final value = await parse(
{...defaultPubspec, 'platforms': 1},
skipTryPub: true,
lenient: true,
);
expect(value.name, 'sample');
expect(value.platforms, isNull);
});
});

group('funding', () {
test('not a list', () {
expectParseThrowsContaining(
Expand Down
6 changes: 6 additions & 0 deletions pkgs/pubspec_parse/test/tojson_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ void main() {
'funding': null,
'topics': null,
'ignored_advisories': null,
'platforms': null,
});
});

Expand All @@ -65,6 +66,7 @@ void main() {
],
'workspace': ['pkg1', 'pkg2'],
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -106,6 +108,7 @@ void main() {
'ignored_advisories': ['111', '222'],
'workspace': ['pkg1', 'pkg2'],
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -139,6 +142,7 @@ void main() {
expect(newValue.workspace, value.workspace);
expect(newValue.resolution, value.resolution);
expect(newValue.executables, value.executables);
expect(newValue.platforms, value.platforms);
});

test('all fields set', () async {
Expand All @@ -163,6 +167,7 @@ void main() {
],
'workspace': ['pkg1', 'pkg2'],
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -200,6 +205,7 @@ void main() {
expect(newValue.workspace, value.workspace);
expect(newValue.resolution, value.resolution);
expect(newValue.executables, value.executables);
expect(newValue.platforms, value.platforms);
});

test('dependencies', () async {
Expand Down
Loading