-
Notifications
You must be signed in to change notification settings - Fork 71
Handle tag_pattern in git dependencies #2159
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
base: main
Are you sure you want to change the base?
Changes from all commits
4d9d72f
c295fdb
4816a89
97f8f55
23db882
c103e01
0b3a469
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ Dependency? _fromJson(Object? data, String name) { | |
final key = matchedKeys.single; | ||
|
||
return switch (key) { | ||
'git' => GitDependency.fromData(data[key]), | ||
'git' => GitDependency.fromJson(data), | ||
'path' => PathDependency.fromData(data[key]), | ||
'sdk' => _$SdkDependencyFromJson(data), | ||
'hosted' => _$HostedDependencyFromJson(data) | ||
|
@@ -112,25 +112,65 @@ class SdkDependency extends Dependency { | |
String toString() => 'SdkDependency: $sdk'; | ||
} | ||
|
||
@JsonSerializable() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps add a line comment here explaining why we don't use json serializable here - that's it's deliberate (in order to have custom parsing in fromJson). |
||
class GitDependency extends Dependency { | ||
@JsonKey(fromJson: parseGitUri) | ||
final Uri url; | ||
final String? ref; | ||
final String? path; | ||
|
||
GitDependency(this.url, {this.ref, this.path}); | ||
|
||
factory GitDependency.fromData(Object? data) { | ||
if (data is String) { | ||
data = {'url': data}; | ||
} | ||
|
||
if (data is Map) { | ||
return _$GitDependencyFromJson(data); | ||
} | ||
|
||
throw ArgumentError.value(data, 'git', 'Must be a String or a Map.'); | ||
final String? tagPattern; | ||
final VersionConstraint? version; | ||
|
||
GitDependency(this.url, {this.ref, this.path, this.tagPattern, this.version}); | ||
|
||
factory GitDependency.fromJson(Map data) { | ||
final version = switch (data['version']) { | ||
final String? s => _constraintFromString(s), | ||
_ => throw ArgumentError.value( | ||
data['version'], | ||
'version', | ||
'if present must be a string.', | ||
), | ||
}; | ||
final gitData = switch (data['git']) { | ||
final String s => {'url': s}, | ||
final Map m => m, | ||
_ => throw ArgumentError.value( | ||
data['git'], | ||
'git', | ||
'Must be a string or map.', | ||
), | ||
}; | ||
final url = switch (gitData['url']) { | ||
final String s => parseGitUri(s), | ||
_ => | ||
throw ArgumentError.value(gitData['url'], 'url', 'Must be a String.'), | ||
}; | ||
final ref = switch (gitData['ref']) { | ||
final String? s => s, | ||
_ => | ||
throw ArgumentError.value(gitData['ref'], 'ref', 'Must be a String.'), | ||
}; | ||
final path = switch (gitData['path']) { | ||
final String? s => s, | ||
_ => | ||
throw ArgumentError.value(gitData['path'], 'path', 'Must be a String.'), | ||
}; | ||
final tagPattern = switch (gitData['tag_pattern']) { | ||
final String? s => s, | ||
_ => throw ArgumentError.value( | ||
gitData['tag_pattern'], | ||
'tag_pattern', | ||
'Must be a String.', | ||
), | ||
}; | ||
|
||
return GitDependency( | ||
url, | ||
ref: ref, | ||
path: path, | ||
tagPattern: tagPattern, | ||
version: version, | ||
); | ||
} | ||
|
||
@override | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I note that PathDependency - which also isn't generated via JsonSerializable - uses
fromData
instead offromJson
. Perhaps also appropriate for GitDependency?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm Yeah - the difference is that
fromData
takes the descriptor only and throws away any version constraint (at least that was my interpretation).For tag_pattern git dependencies, you need the version constraint to make any sense of it all.