diff --git a/lib/src/package_name.dart b/lib/src/package_name.dart index af1a24cd1..a4b2f80a9 100644 --- a/lib/src/package_name.dart +++ b/lib/src/package_name.dart @@ -4,6 +4,7 @@ import 'package:pub_semver/pub_semver.dart'; +import 'log.dart'; import 'package.dart'; import 'source.dart'; import 'source/hosted.dart'; @@ -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'); } diff --git a/lib/src/solver/incompatibility.dart b/lib/src/solver/incompatibility.dart index 8b815019c..d1522c235 100644 --- a/lib/src/solver/incompatibility.dart +++ b/lib/src/solver/incompatibility.dart @@ -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'; @@ -475,10 +476,11 @@ class Incompatibility { } /// Returns a terse representation of [term]'s package ref. - String _terseRef(Term term, Map? details) => - term.package - .toRef() - .toString(details == null ? null : details[term.package.name]); + String _terseRef(Term term, Map? details) => bold( + term.package + .toRef() + .toString(details == null ? null : details[term.package.name]), + ); /// Returns a terse representation of [term]'s package. /// @@ -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, + ); } } } diff --git a/test/version_solver_test.dart b/test/version_solver_test.dart index 394859ed2..d17132b95 100644 --- a/test/version_solver_test.dart +++ b/test/version_solver_test.dart @@ -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'; @@ -3037,9 +3038,10 @@ Future expectResolves({ int? tries, Map? 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 @@ -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, + ); + }); }