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
2 changes: 1 addition & 1 deletion pkgs/pubspec_parse/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +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 fields to `Pubspec`: `falseSecrets`, `platforms`.
- Added fields to `Pubspec`: `falseSecrets`, `hooks`, `platforms`.

## 1.6.0

Expand Down
8 changes: 8 additions & 0 deletions pkgs/pubspec_parse/lib/src/pubspec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ class Pubspec {
/// See https://dart.dev/tools/pub/pubspec#false_secrets.
final List<String>? falseSecrets;

/// Configuration for hooks, such as native build or link hooks.
///
/// May include `user_defines` and other settings.
///
/// See https://dart.dev/tools/pub/pubspec#hooks.
final Map<String, Object?>? hooks;

/// If [author] and [authors] are both provided, their values are combined
/// with duplicates eliminated.
Pubspec(
Expand All @@ -137,6 +144,7 @@ class Pubspec {
this.resolution,
this.platforms,
this.falseSecrets,
this.hooks,
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.

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

test('all fields set', () async {
Expand All @@ -62,6 +63,11 @@ void main() {
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'false_secrets': ['/lib/src/hardcoded_api_key.dart', '/test/*.pem'],
'hooks': {
'user_defines': {
'my_package': {'enable_experimental': true},
},
},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -110,6 +116,11 @@ void main() {
'/lib/src/hardcoded_api_key.dart',
'/test/*.pem',
]);
expect(value.hooks, {
'user_defines': {
'my_package': {'enable_experimental': true},
},
});
});

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

group('hooks', () {
test('map', () async {
final value = await parse({
...defaultPubspec,
'hooks': {
'user_defines': {
'my_package': {'enable_experimental': true},
},
},
});
expect(value.hooks, {
'user_defines': {
'my_package': {'enable_experimental': true},
},
});
});

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

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

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

Expand Down Expand Up @@ -69,6 +70,11 @@ void main() {
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'false_secrets': ['/lib/src/hardcoded_api_key.dart', '/test/*.pem'],
'hooks': {
'user_defines': {
'my_package': {'enable_experimental': true},
},
},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -112,6 +118,11 @@ void main() {
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'false_secrets': ['/lib/src/hardcoded_api_key.dart', '/test/*.pem'],
'hooks': {
'user_defines': {
'my_package': {'enable_experimental': true},
},
},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -147,6 +158,7 @@ void main() {
expect(newValue.executables, value.executables);
expect(newValue.platforms, value.platforms);
expect(newValue.falseSecrets, value.falseSecrets);
expect(newValue.hooks, value.hooks);
});

test('all fields set', () async {
Expand All @@ -173,6 +185,11 @@ void main() {
'resolution': 'workspace',
'platforms': {'android': null, 'web': null},
'false_secrets': ['/lib/src/hardcoded_api_key.dart', '/test/*.pem'],
'hooks': {
'user_defines': {
'my_package': {'enable_experimental': true},
},
},
'executables': {
'my_script': 'bin/my_script.dart',
'my_script2': 'bin/my_script2.dart',
Expand Down Expand Up @@ -212,6 +229,7 @@ void main() {
expect(newValue.executables, value.executables);
expect(newValue.platforms, value.platforms);
expect(newValue.falseSecrets, value.falseSecrets);
expect(newValue.hooks, value.hooks);
});

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