Skip to content

Commit

Permalink
pub upgrade command shows count of discontinued packages (#2908)
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharojha authored Mar 12, 2021
1 parent 5174480 commit d6308ef
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/src/solver/report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ class SolveReport {
}
}

/// Displays a single-line message, number of discontinued packages
/// if discontinued packages are detected.
Future<void> reportDiscontinued() async {
var numDiscontinued = 0;
for (var id in _result.packages) {
if (id.source == null) continue;
final status =
await _cache.source(id.source).status(id, Duration(days: 3));
if (status.isDiscontinued) numDiscontinued++;
}
if (numDiscontinued > 0) {
if (numDiscontinued == 1) {
log.message('1 package is discontinued.');
} else {
log.message('$numDiscontinued packages are discontinued.');
}
}
}

/// Displays a two-line message, number of outdated packages and an
/// instruction to run `pub outdated` if outdated packages are detected.
void reportOutdated() {
Expand Down
1 change: 1 addition & 0 deletions lib/src/solver/result.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class SolveResult {
SolveReport(type, _sources, _root, _previousLockFile, this, cache);
report.summarize(dryRun: dryRun);
if (type == SolveType.UPGRADE) {
await report.reportDiscontinued();
report.reportOutdated();
}
}
Expand Down
24 changes: 24 additions & 0 deletions test/upgrade/report/describes_change_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,30 @@ import '../../descriptor.dart' as d;
import '../../test_pub.dart';

void main() {
test('Shows count of discontinued packages', () async {
await servePackages((builder) {
builder.serve('foo', '2.0.0');
});

globalPackageServer.add((builder) => builder..discontinue('foo'));

// Create the first lockfile.
await d.appDir({'foo': '2.0.0'}).create();

await pubGet();

// Do the dry run.
await pubUpgrade(
args: ['--dry-run'],
output: contains('1 package is discontinued.'),
);

// Try without --dry-run
await pubUpgrade(
output: contains('1 package is discontinued.'),
);
});

test('shows how package changed from previous lockfile', () async {
await servePackages((builder) {
builder.serve('unchanged', '1.0.0');
Expand Down

0 comments on commit d6308ef

Please sign in to comment.