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

fix: Properly format Git and HostedDependency #841

Merged
merged 1 commit into from
Jan 19, 2025
Merged
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
50 changes: 24 additions & 26 deletions packages/melos/lib/src/common/extensions/dependency.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@ extension DependencyExtension on Dependency {
return null;
}

/// Whether the json can be inlined with its parent.
///
/// For example for [HostedDependency] the version shouldn't be on a separate
/// line when only the version is defined.
bool get inlineVersion {
if (this is HostedDependency) {
return (this as HostedDependency).hosted == null &&
versionConstraint != null;
}
return false;
}

Object toJson() {
final self = this;
if (self is PathDependency) {
Expand All @@ -47,31 +35,41 @@ extension PathDependencyExtension on PathDependency {

extension HostedDependencyExtension on HostedDependency {
Object toJson() {
return inlineVersion
return _inlineVersion
? version.toString()
: {
'hosted': {
'version': version.toString(),
if (hosted != null)
'hosted': {
'name': hosted!.declaredName,
'url': hosted!.url?.toString(),
},
},
'hosted': hosted!.url?.toString(),
'version': version.toString(),
};
}

/// Whether the json can be inlined with its parent.
///
/// For example for [HostedDependency] the version shouldn't be on a separate
/// line when only the version is defined.
bool get _inlineVersion {
return hosted == null;
}
}

extension GitDependencyExtension on GitDependency {
Map<String, dynamic> toJson() {
return {
'git': {
'url': url.toString(),
if (ref != null) 'ref': ref,
if (path != null) 'path': path,
},
'git': _inlineUrl
? url.toString()
: {
'url': url.toString(),
if (ref != null) 'ref': ref,
if (path != null) 'path': path,
},
};
}

/// Whether the url can be inlined with its parent.
/// This happens when the [ref] and [path] are null.
bool get _inlineUrl {
return ref == null && path == null;
}
}

extension SdkDependencyExtension on SdkDependency {
Expand Down
Loading