Skip to content

Commit 9e3d1a2

Browse files
Merge pull request #1 from matthewnitschke/ci_implementation
CI Implementation
2 parents 67639c6 + cdcb844 commit 9e3d1a2

11 files changed

+123
-128
lines changed

.tool-versions

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dart 2.14.4

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
[![Dart](https://github.com/matthewnitschke/pubspec_lock_parse/actions/workflows/dart.yml/badge.svg)](https://github.com/matthewnitschke/pubspec_lock_parse/actions/workflows/dart.yml)
2+
[![pub package](https://img.shields.io/pub/v/pubspec_lock_parse.svg)](https://pub.dev/packages/pubspec_lock_parse)
3+
14
Supports parsing `pubspec.lock` files with robust error reporting
25

36
Designed around the [`pubspec_parse`](https://github.com/dart-lang/pubspec_parse) package, and mirrors its implementation and interface

lib/src/package.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import 'package:pub_semver/pub_semver.dart';
55
part 'package.g.dart';
66

77
Map<String, Package> parsePackages(Map source) =>
8-
source?.map((k, v) {
8+
source.map((k, v) {
99
final value = v as Map;
1010
return MapEntry(k, Package.fromJson(value));
11-
}) ?? {};
11+
});
1212

1313
@JsonSerializable()
1414
class Package {
@@ -23,10 +23,10 @@ class Package {
2323
final Version version;
2424

2525
Package({
26-
this.dependency,
27-
this.description,
28-
this.source,
29-
this.version,
26+
required this.dependency,
27+
required this.description,
28+
required this.source,
29+
required this.version,
3030
});
3131

3232
factory Package.fromJson(Map json) => _$PackageFromJson(json);
@@ -40,5 +40,4 @@ enum PackageSource {
4040

4141
// ---------------------------------- Parsers ----------------------------------
4242

43-
Version _versionFromString(String input) =>
44-
input == null ? null : Version.parse(input);
43+
Version _versionFromString(String input) => Version.parse(input);

lib/src/package.g.dart

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

lib/src/package_description.dart

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PackageDescription parsePackageDescription(Object data) {
1313
return HostedPackageDescription.fromJson(data);
1414
}
1515
}
16+
17+
throw FormatException('Unknown package description type');
1618
}
1719

1820
abstract class PackageDescription { }
@@ -23,7 +25,10 @@ class HostedPackageDescription extends PackageDescription {
2325

2426
final String url;
2527

26-
HostedPackageDescription({ this.name, this.url });
28+
HostedPackageDescription({
29+
required this.name,
30+
required this.url,
31+
});
2732

2833
factory HostedPackageDescription.fromJson(Map json) => _$HostedPackageDescriptionFromJson(json);
2934
}
@@ -39,7 +44,12 @@ class GitPackageDescription extends PackageDescription {
3944

4045
final String url;
4146

42-
GitPackageDescription({ this.path, this.ref, this.resolvedRef, this.url });
47+
GitPackageDescription({
48+
required this.path,
49+
required this.ref,
50+
required this.resolvedRef,
51+
required this.url,
52+
});
4353

4454
factory GitPackageDescription.fromJson(Map json) => _$GitPackageDescriptionFromJson(json);
4555
}
@@ -50,7 +60,10 @@ class PathPackageDescription extends PackageDescription {
5060

5161
final bool relative;
5262

53-
PathPackageDescription({ this.path, this.relative });
63+
PathPackageDescription({
64+
required this.path,
65+
required this.relative,
66+
});
5467

5568
factory PathPackageDescription.fromJson(Map json) => _$PathPackageDescriptionFromJson(json);
5669
}

lib/src/package_description.g.dart

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

lib/src/pubspec_lock.dart

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@ class PubspecLock {
1515
final Map<String, VersionConstraint> sdks;
1616

1717
PubspecLock({
18-
this.packages,
19-
this.sdks,
18+
required this.packages,
19+
required this.sdks,
2020
});
2121

2222
factory PubspecLock.fromJson(Map json) => _$PubspecLockFromJson(json);
2323

24-
factory PubspecLock.parse(String yaml, {Uri sourceUrl}) =>
24+
factory PubspecLock.parse(String yaml, {Uri? sourceUrl}) =>
2525
checkedYamlDecode(
2626
yaml,
27-
(map) => PubspecLock.fromJson(map),
27+
(map) => PubspecLock.fromJson(map ?? {}),
2828
sourceUrl: sourceUrl
2929
);
3030
}
3131

3232
// ---------------------------------- Parsers ----------------------------------
3333

34-
Map<String, VersionConstraint> _parseSdks(Map source) =>
35-
source?.map((k, v) => MapEntry(k, _versionConstraintFromString(v as String))) ?? {};
34+
Map<String, VersionConstraint> _parseSdks(Map source) => source.map((k, v) => MapEntry(k, _versionConstraintFromString(v as String)));
3635

37-
VersionConstraint _versionConstraintFromString(String input) =>
38-
input == null ? null : VersionConstraint.parse(input);
36+
VersionConstraint _versionConstraintFromString(String input) => VersionConstraint.parse(input);

lib/src/pubspec_lock.g.dart

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

pubspec.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ description: Simple package for parsing pubspec.lock files with a type-safe API
44
repository: https://github.com/matthewnitschke/pubspec_lock_parse
55

66
environment:
7-
sdk: '>=2.7.0 <3.0.0'
7+
sdk: '>=2.14.0 <3.0.0'
88

99
dependencies:
10-
args: ^1.6.0
11-
json_annotation: ^3.1.1
12-
pub_semver: ^1.4.4
13-
checked_yaml: ^1.0.4
10+
args: ^2.3.0
11+
json_annotation: ^4.3.0
12+
pub_semver: ^2.1.0
13+
checked_yaml: ^2.0.1
1414

1515
dev_dependencies:
1616
build_runner: ^1.10.1
17-
json_serializable: ^3.5.1
17+
json_serializable: ^6.0.1
1818
test: ^1.15.7
1919
stack_trace: ^1.9.2

test/parse_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ void main() {
88
test('minimal set values', () {
99
final value = parse(defaultPubspecLock);
1010
expect(value.packages, isEmpty);
11-
expect(value.sdks, VersionConstraint.parse('>=2.7.0 <3.0.0'));
11+
expect(value.sdks['dart'], VersionConstraint.parse('>=2.7.0 <3.0.0'));
1212
});
1313

1414
group('package types -', () {
@@ -25,7 +25,7 @@ void main() {
2525
});
2626

2727

28-
final package = value.packages['package_a'];
28+
final package = value.packages['package_a']!;
2929
expect(package.dependency, 'transitive');
3030
expect(package.description is HostedPackageDescription, isTrue);
3131
expect(package.version, Version.parse('1.2.3'));
@@ -50,7 +50,7 @@ void main() {
5050
}
5151
});
5252

53-
final package = value.packages['package_a'];
53+
final package = value.packages['package_a']!;
5454
expect(package.dependency, 'transitive');
5555
expect(package.description is GitPackageDescription, isTrue);
5656
expect(package.version, Version.parse('1.2.3'));
@@ -75,7 +75,7 @@ void main() {
7575
}
7676
});
7777

78-
final package = value.packages['package_a'];
78+
final package = value.packages['package_a']!;
7979
expect(package.dependency, 'direct');
8080
expect(package.description is PathPackageDescription, isTrue);
8181
expect(package.version, Version.parse('1.2.3'));

0 commit comments

Comments
 (0)