Skip to content

Commit

Permalink
Improve dart pub outdated output for discontinued packages (#4046)
Browse files Browse the repository at this point in the history
  • Loading branch information
szakarias authored Nov 20, 2023
1 parent 5f30108 commit 1e0bc33
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 16 deletions.
39 changes: 29 additions & 10 deletions lib/src/command/outdated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,8 @@ Future<void> _outputHuman(
? ', replaced by ${package.discontinuedReplacedBy}.'
: '.';
log.message(
' Package ${package.name} has been discontinued$replacedByText',
' Package ${package.name} has been discontinued$replacedByText '
'See https://dart.dev/go/package-discontinue',
);
}
}
Expand All @@ -658,7 +659,7 @@ abstract class _Mode {
/// Analyzes the [_PackageDetails] according to a --mode and outputs a
/// corresponding list of the versions
/// [current, upgradable, resolvable, latest].
Future<List<List<_MarkedVersionDetails>>> markVersionDetails(
Future<List<List<_Details>>> markVersionDetails(
List<_PackageDetails> packageDetails,
);

Expand Down Expand Up @@ -697,12 +698,12 @@ Showing outdated packages$directoryDescription.
String get allSafe => 'all dependencies are up-to-date.';

@override
Future<List<List<_MarkedVersionDetails>>> markVersionDetails(
Future<List<List<_Details>>> markVersionDetails(
List<_PackageDetails> packages,
) async {
final rows = <List<_MarkedVersionDetails>>[];
final rows = <List<_Details>>[];
for (final packageDetails in packages) {
final cols = <_MarkedVersionDetails>[];
final cols = <_Details>[];
_VersionDetails? previous;
for (final versionDetails in [
packageDetails.current,
Expand All @@ -717,10 +718,6 @@ Showing outdated packages$directoryDescription.
final isLatest = versionDetails == packageDetails.latest;
if (isLatest) {
color = versionDetails == previous ? color = log.gray : null;
if (packageDetails.isDiscontinued &&
identical(versionDetails, packageDetails.latest)) {
suffix = ' (discontinued)';
}
} else {
color = log.red;
}
Expand All @@ -736,6 +733,9 @@ Showing outdated packages$directoryDescription.
);
previous = versionDetails;
}
if (packageDetails.isDiscontinued == true) {
cols.add(_SimpleDetails('(discontinued)'));
}
rows.add(cols);
}
return rows;
Expand Down Expand Up @@ -879,7 +879,24 @@ _FormattedString _format(
return _FormattedString(value, format: format, prefix: prefix);
}

class _MarkedVersionDetails {
abstract class _Details {
_FormattedString toHuman();
Object? toJson();
}

class _SimpleDetails implements _Details {
final String details;

_SimpleDetails(this.details);

@override
_FormattedString toHuman() => _FormattedString(details);

@override
Object? toJson() => null;
}

class _MarkedVersionDetails implements _Details {
final MapEntry<String, Object>? _jsonExplanation;
final _VersionDetails? _versionDetails;
final String Function(String)? _format;
Expand All @@ -897,13 +914,15 @@ class _MarkedVersionDetails {
_suffix = suffix,
_jsonExplanation = jsonExplanation;

@override
_FormattedString toHuman() => _FormattedString(
_versionDetails?.describe ?? '-',
format: _format,
prefix: _prefix,
suffix: _suffix,
);

@override
Object? toJson() {
if (_versionDetails == null) return null;

Expand Down
25 changes: 25 additions & 0 deletions test/outdated/outdated_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,31 @@ Future<void> main() async {
await ctx.runOutdatedTests();
});

testWithGolden('show discontinued with no latest version', (ctx) async {
final builder = await servePackages();
builder
..serve('foo', '1.2.3', deps: {'transitive': '^1.0.0'})
..serve('bar', '1.0.0')
..serve('baz', '1.0.0')
..serve('transitive', '1.2.3');

await d.dir(appPath, [
d.pubspec({
'name': 'app',
'dependencies': {
'foo': '^1.0.0',
'bar': '^1.0.0',
'baz': '^1.0.0',
},
}),
]).create();
await pubGet();
builder.retractPackageVersion('foo', '1.2.3');
builder.discontinue('foo');
builder.discontinue('baz', replacementText: 'newbaz');
await ctx.runOutdatedTests();
});

testWithGolden('circular dependency on root', (ctx) async {
final server = await servePackages();
server.serve('foo', '1.2.3', deps: {'app': '^1.0.0'});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# GENERATED BY: test/outdated/outdated_test.dart

## Section 0
$ pub outdated --json
{
"packages": [
{
"package": "foo",
"kind": "direct",
"isDiscontinued": true,
"current": {
"version": "1.2.3"
},
"upgradable": {
"version": "1.2.3"
},
"resolvable": {
"version": "1.2.3"
},
"latest": null
}
]
}

-------------------------------- END OF OUTPUT ---------------------------------

## Section 1
$ pub outdated --no-color
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest

direct dependencies:
foo *1.2.3 *1.2.3 *1.2.3 - (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

foo
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

## Section 2
$ pub outdated --no-color --no-transitive
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest

direct dependencies:
foo *1.2.3 *1.2.3 *1.2.3 - (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

foo
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

## Section 3
$ pub outdated --no-color --up-to-date
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest

direct dependencies:
bar 1.0.0 1.0.0 1.0.0 1.0.0
baz 1.0.0 1.0.0 1.0.0 1.0.0 (discontinued)
foo *1.2.3 *1.2.3 *1.2.3 - (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

baz
Package baz has been discontinued, replaced by newbaz. See https://dart.dev/go/package-discontinue
foo
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

## Section 4
$ pub outdated --no-color --prereleases
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest

direct dependencies:
foo *1.2.3 *1.2.3 *1.2.3 - (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

foo
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

## Section 5
$ pub outdated --no-color --no-dev-dependencies
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest

direct dependencies:
foo *1.2.3 *1.2.3 *1.2.3 - (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

foo
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

## Section 6
$ pub outdated --no-color --no-dependency-overrides
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest

direct dependencies:
foo *1.2.3 *1.2.3 *1.2.3 - (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

foo
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

## Section 7
$ pub outdated --json --no-dev-dependencies
{
"packages": [
{
"package": "foo",
"kind": "direct",
"isDiscontinued": true,
"current": {
"version": "1.2.3"
},
"upgradable": {
"version": "1.2.3"
},
"resolvable": {
"version": "1.2.3"
},
"latest": null
}
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,19 @@ $ pub outdated --no-color --up-to-date
Showing outdated packages.
[*] indicates versions that are not the latest available.

Package Name Current Upgradable Resolvable Latest
Package Name Current Upgradable Resolvable Latest

direct dependencies:
bar 1.0.0 1.0.0 1.0.0 1.0.0
baz 1.0.0 1.0.0 1.0.0 1.0.0 (discontinued)
foo 1.2.3 1.2.3 1.2.3 1.2.3 (discontinued)
bar 1.0.0 1.0.0 1.0.0 1.0.0
baz 1.0.0 1.0.0 1.0.0 1.0.0 (discontinued)
foo 1.2.3 1.2.3 1.2.3 1.2.3 (discontinued)
You are already using the newest resolvable versions listed in the 'Resolvable' column.
Newer versions, listed in 'Latest', may not be mutually compatible.

baz
Package baz has been discontinued, replaced by newbaz.
Package baz has been discontinued, replaced by newbaz. See https://dart.dev/go/package-discontinue
foo
Package foo has been discontinued.
Package foo has been discontinued. See https://dart.dev/go/package-discontinue

-------------------------------- END OF OUTPUT ---------------------------------

Expand Down

0 comments on commit 1e0bc33

Please sign in to comment.