Skip to content
Draft
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
5 changes: 3 additions & 2 deletions lib/src/package_name.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:pub_semver/pub_semver.dart';

import 'log.dart';
import 'package.dart';
import 'source.dart';
import 'source/hosted.dart';
Expand Down Expand Up @@ -153,10 +154,10 @@ class PackageRange {
PackageRef toRef() => _ref;

@override
String toString([PackageDetail? detail]) {
String toString({PackageDetail? detail, bool boldName = false}) {
detail ??= PackageDetail.defaults;

var buffer = StringBuffer(name);
var buffer = StringBuffer(boldName ? bold(name) : name);
if (detail.showVersion ?? _showVersionConstraint) {
buffer.write(' $constraint');
}
Expand Down
16 changes: 10 additions & 6 deletions lib/src/solver/incompatibility.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:pub_semver/pub_semver.dart';

import '../log.dart';
import '../package_name.dart';
import 'incompatibility_cause.dart';
import 'term.dart';
Expand Down Expand Up @@ -475,10 +476,11 @@ class Incompatibility {
}

/// Returns a terse representation of [term]'s package ref.
String _terseRef(Term term, Map<String, PackageDetail>? details) =>
term.package
.toRef()
.toString(details == null ? null : details[term.package.name]);
String _terseRef(Term term, Map<String, PackageDetail>? details) => bold(
term.package
.toRef()
.toString(details == null ? null : details[term.package.name]),
);

/// Returns a terse representation of [term]'s package.
///
Expand All @@ -492,8 +494,10 @@ class Incompatibility {
if (allowEvery && term!.constraint.isAny) {
return 'every version of ${_terseRef(term, details)}';
} else {
return term!.package
.toString(details == null ? null : details[term.package.name]);
return term!.package.toString(
detail: details == null ? null : details[term.package.name],
boldName: true,
);
}
}
}
31 changes: 30 additions & 1 deletion test/version_solver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'dart:io';

import 'package:path/path.dart' as p;
import 'package:pub/src/lock_file.dart';
import 'package:pub/src/log.dart';
import 'package:pub/src/pubspec.dart';
import 'package:pub/src/source/hosted.dart';
import 'package:pub/src/system_cache.dart';
Expand Down Expand Up @@ -3037,9 +3038,10 @@ Future expectResolves({
int? tries,
Map<String, String>? environment,
bool downgrade = false,
bool colors = false,
}) async {
await runPub(
args: [downgrade ? 'downgrade' : 'get'],
args: [if (colors) '--color', downgrade ? 'downgrade' : 'get'],
environment: environment,
output: output ??
(error == null
Expand Down Expand Up @@ -3132,4 +3134,31 @@ void regressions() {
environment: {'FLUTTER_ROOT': p.join(d.sandbox, 'flutter')},
);
});
test('uses colors to highlight package names in solve-traces', () async {
await d.dir('a', [d.libPubspec('a', '1.0.0')]).create();

await servePackages()
..serve('a', '1.0.0')
..serve(
'b',
'1.0.0',
deps: {
'a': {'path': p.join(d.sandbox, 'shared')}
},
)
..serve('c', '1.0.0')
..serve('c', '2.0.0')
..serve('c', '3.0.0')
..serve('c', '4.0.0')
..serve('c', '5.0.0');

await d.appDir(dependencies: {'a': 'any', 'b': 'any', 'c': 'any'}).create();
await expectResolves(
error: '''
Because every version of ${bold('b')} depends on ${bold('a')} from path and ${bold('myapp')} depends on ${bold('a')} from hosted, ${bold('${bold('b')} is forbidden')}.
So, because ${bold('myapp')} depends on ${bold('b')} any, ${bold('version solving failed')}.
''',
colors: true,
);
});
}