Skip to content

Commit 342e002

Browse files
Levi-Lescheskevmoo
andauthored
Added workspace: and resolution: fields (#1948)
Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
1 parent a04e631 commit 342e002

File tree

5 files changed

+88
-23
lines changed

5 files changed

+88
-23
lines changed

pkgs/pubspec_parse/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.5.0-wip
2+
3+
- Add `Pubspec.workspace` and `Pubspec.resolution` fields.
4+
15
## 1.4.0
26

37
- Require Dart 3.2
@@ -31,7 +35,7 @@
3135
- Added support for `screenshots` field.
3236
- Update `HostedDetails` to reflect how `hosted` dependencies are parsed in
3337
Dart 2.15:
34-
- Add `HostedDetails.declaredName` as the (optional) `name` property in a
38+
- Add `HostedDetails.declaredName` as the (optional) `name` property in a
3539
`hosted` block.
3640
- `HostedDetails.name` now falls back to the name of the dependency if no
3741
name is declared in the block.

pkgs/pubspec_parse/lib/src/pubspec.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ class Pubspec {
9393
/// and other settings.
9494
final Map<String, dynamic>? flutter;
9595

96+
/// If this package is a Pub Workspace, this field lists the sub-packages.
97+
final List<String>? workspace;
98+
99+
/// Specifies how to resolve dependencies with the surrounding Pub Workspace.
100+
final String? resolution;
101+
96102
/// If [author] and [authors] are both provided, their values are combined
97103
/// with duplicates eliminated.
98104
Pubspec(
@@ -117,6 +123,8 @@ class Pubspec {
117123
this.screenshots,
118124
this.documentation,
119125
this.description,
126+
this.workspace,
127+
this.resolution,
120128
Map<String, Dependency>? dependencies,
121129
Map<String, Dependency>? devDependencies,
122130
Map<String, Dependency>? dependencyOverrides,

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

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkgs/pubspec_parse/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: pubspec_parse
2-
version: 1.4.0
2+
version: 1.5.0-wip
33
description: >-
44
Simple package for parsing pubspec.yaml files with a type-safe API and rich
55
error reporting.

pkgs/pubspec_parse/test/parse_test.dart

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,41 @@ void main() {
3232
expect(value.repository, isNull);
3333
expect(value.issueTracker, isNull);
3434
expect(value.screenshots, isEmpty);
35+
expect(value.workspace, isNull);
36+
expect(value.resolution, isNull);
3537
});
3638

3739
test('all fields set', () async {
3840
final version = Version.parse('1.2.3');
39-
final sdkConstraint = VersionConstraint.parse('>=2.12.0 <3.0.0');
40-
final value = await parse({
41-
'name': 'sample',
42-
'version': version.toString(),
43-
'publish_to': 'none',
44-
'author': 'name@example.com',
45-
'environment': {'sdk': sdkConstraint.toString()},
46-
'description': 'description',
47-
'homepage': 'homepage',
48-
'documentation': 'documentation',
49-
'repository': 'https://github.com/example/repo',
50-
'issue_tracker': 'https://github.com/example/repo/issues',
51-
'funding': [
52-
'https://patreon.com/example',
53-
],
54-
'topics': ['widget', 'button'],
55-
'ignored_advisories': ['111', '222'],
56-
'screenshots': [
57-
{'description': 'my screenshot', 'path': 'path/to/screenshot'},
58-
],
59-
});
41+
final sdkConstraint = VersionConstraint.parse('>=3.6.0 <4.0.0');
42+
final value = await parse(
43+
{
44+
'name': 'sample',
45+
'version': version.toString(),
46+
'publish_to': 'none',
47+
'author': 'name@example.com',
48+
'environment': {'sdk': sdkConstraint.toString()},
49+
'description': 'description',
50+
'homepage': 'homepage',
51+
'documentation': 'documentation',
52+
'repository': 'https://github.com/example/repo',
53+
'issue_tracker': 'https://github.com/example/repo/issues',
54+
'funding': [
55+
'https://patreon.com/example',
56+
],
57+
'topics': ['widget', 'button'],
58+
'ignored_advisories': ['111', '222'],
59+
'screenshots': [
60+
{'description': 'my screenshot', 'path': 'path/to/screenshot'},
61+
],
62+
'workspace': [
63+
'pkg1',
64+
'pkg2',
65+
],
66+
'resolution': 'workspace',
67+
},
68+
skipTryPub: true,
69+
);
6070
expect(value.name, 'sample');
6171
expect(value.version, version);
6272
expect(value.publishTo, 'none');
@@ -86,6 +96,10 @@ void main() {
8696
expect(value.screenshots, hasLength(1));
8797
expect(value.screenshots!.first.description, 'my screenshot');
8898
expect(value.screenshots!.first.path, 'path/to/screenshot');
99+
expect(value.workspace, hasLength(2));
100+
expect(value.workspace!.first, 'pkg1');
101+
expect(value.workspace!.last, 'pkg2');
102+
expect(value.resolution, 'workspace');
89103
});
90104

91105
test('environment values can be null', () async {
@@ -712,4 +726,40 @@ line 1, column 1: Not a map
712726
);
713727
});
714728
});
729+
730+
group('workspaces', () {
731+
test('workspace key must be a list', () {
732+
expectParseThrowsContaining(
733+
{
734+
...defaultPubspec,
735+
'workspace': 42,
736+
},
737+
'Unsupported value for "workspace". type \'int\' is not a subtype of type \'List<dynamic>?\' in type cast',
738+
skipTryPub: true,
739+
);
740+
});
741+
742+
test('workspace key must be a list of strings', () {
743+
expectParseThrowsContaining(
744+
{
745+
...defaultPubspec,
746+
'workspace': [42],
747+
},
748+
'Unsupported value for "workspace". type \'int\' is not a subtype of type \'String\' in type cast',
749+
skipTryPub: true,
750+
);
751+
});
752+
753+
test('resolution key must be a string', () {
754+
expectParseThrowsContaining(
755+
{
756+
'name': 'sample',
757+
'environment': {'sdk': '^3.6.0'},
758+
'resolution': 42,
759+
},
760+
'Unsupported value for "resolution". type \'int\' is not a subtype of type \'String?\' in type cast',
761+
skipTryPub: true,
762+
);
763+
});
764+
});
715765
}

0 commit comments

Comments
 (0)