Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added workspace: and resolution: fields #1948

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion pkgs/pubspec_parse/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.5.0

- Add `Pubspec.workspace` and `Pubspec.resolution` fields.

## 1.4.0

- Require Dart 3.2
Expand Down Expand Up @@ -31,7 +35,7 @@
- Added support for `screenshots` field.
- Update `HostedDetails` to reflect how `hosted` dependencies are parsed in
Dart 2.15:
- Add `HostedDetails.declaredName` as the (optional) `name` property in a
- Add `HostedDetails.declaredName` as the (optional) `name` property in a
`hosted` block.
- `HostedDetails.name` now falls back to the name of the dependency if no
name is declared in the block.
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 @@ -93,6 +93,12 @@ class Pubspec {
/// and other settings.
final Map<String, dynamic>? flutter;

/// If this package is a Pub Workspace, this field lists the sub-packages.
final List<String>? workspace;

/// Specifies how to resolve dependencies with the surrounding Pub Workspace.
final String? resolution;

/// If [author] and [authors] are both provided, their values are combined
/// with duplicates eliminated.
Pubspec(
Expand All @@ -117,6 +123,8 @@ class Pubspec {
this.screenshots,
this.documentation,
this.description,
this.workspace,
this.resolution,
Map<String, Dependency>? dependencies,
Map<String, Dependency>? devDependencies,
Map<String, Dependency>? dependencyOverrides,
Expand Down
3 changes: 3 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.

2 changes: 1 addition & 1 deletion pkgs/pubspec_parse/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: pubspec_parse
version: 1.4.0
version: 1.5.0
description: >-
Simple package for parsing pubspec.yaml files with a type-safe API and rich
error reporting.
Expand Down
92 changes: 71 additions & 21 deletions pkgs/pubspec_parse/test/parse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,41 @@ void main() {
expect(value.repository, isNull);
expect(value.issueTracker, isNull);
expect(value.screenshots, isEmpty);
expect(value.workspace, isNull);
expect(value.resolution, isNull);
});

test('all fields set', () async {
final version = Version.parse('1.2.3');
final sdkConstraint = VersionConstraint.parse('>=2.12.0 <3.0.0');
final value = await parse({
'name': 'sample',
'version': version.toString(),
'publish_to': 'none',
'author': '[email protected]',
'environment': {'sdk': sdkConstraint.toString()},
'description': 'description',
'homepage': 'homepage',
'documentation': 'documentation',
'repository': 'https://github.com/example/repo',
'issue_tracker': 'https://github.com/example/repo/issues',
'funding': [
'https://patreon.com/example',
],
'topics': ['widget', 'button'],
'ignored_advisories': ['111', '222'],
'screenshots': [
{'description': 'my screenshot', 'path': 'path/to/screenshot'},
],
});
final sdkConstraint = VersionConstraint.parse('>=3.6.0 <4.0.0');
final value = await parse(
{
'name': 'sample',
'version': version.toString(),
'publish_to': 'none',
'author': '[email protected]',
'environment': {'sdk': sdkConstraint.toString()},
'description': 'description',
'homepage': 'homepage',
'documentation': 'documentation',
'repository': 'https://github.com/example/repo',
'issue_tracker': 'https://github.com/example/repo/issues',
'funding': [
'https://patreon.com/example',
],
'topics': ['widget', 'button'],
'ignored_advisories': ['111', '222'],
'screenshots': [
{'description': 'my screenshot', 'path': 'path/to/screenshot'},
],
'workspace': [
'pkg1',
'pkg2',
],
'resolution': 'workspace',
},
skipTryPub: true,
);
expect(value.name, 'sample');
expect(value.version, version);
expect(value.publishTo, 'none');
Expand Down Expand Up @@ -86,6 +96,10 @@ void main() {
expect(value.screenshots, hasLength(1));
expect(value.screenshots!.first.description, 'my screenshot');
expect(value.screenshots!.first.path, 'path/to/screenshot');
expect(value.workspace, hasLength(2));
expect(value.workspace!.first, 'pkg1');
expect(value.workspace!.last, 'pkg2');
expect(value.resolution, 'workspace');
});

test('environment values can be null', () async {
Expand Down Expand Up @@ -712,4 +726,40 @@ line 1, column 1: Not a map
);
});
});

group('workspaces', () {
test('workspace key must be a list', () {
expectParseThrowsContaining(
{
...defaultPubspec,
'workspace': 42,
},
'Unsupported value for "workspace". type \'int\' is not a subtype of type \'List<dynamic>?\' in type cast',
skipTryPub: true,
);
});

test('workspace key must be a list of strings', () {
expectParseThrowsContaining(
{
...defaultPubspec,
'workspace': [42],
},
'Unsupported value for "workspace". type \'int\' is not a subtype of type \'String\' in type cast',
skipTryPub: true,
);
});

test('resolution key must be a string', () {
expectParseThrowsContaining(
{
'name': 'sample',
'environment': {'sdk': '^3.6.0'},
'resolution': 42,
},
'Unsupported value for "resolution". type \'int\' is not a subtype of type \'String?\' in type cast',
skipTryPub: true,
);
});
});
}
Loading