Skip to content

Commit 643d105

Browse files
committed
Fix broken merge
1 parent 6288c09 commit 643d105

18 files changed

+290
-733
lines changed

lib/src/command/deps.dart

Lines changed: 43 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'dart:collection';
6-
import 'dart:convert';
6+
7+
import 'package:path/path.dart' as p;
78

89
import '../ascii_tree.dart' as tree;
910
import '../command.dart';
@@ -52,10 +53,6 @@ class DepsCommand extends PubCommand {
5253
argParser.addFlag('executables',
5354
negatable: false, help: 'List all available executables.');
5455

55-
argParser.addFlag('json',
56-
negatable: false,
57-
help: 'Output dependency information in a json format.');
58-
5956
argParser.addOption('directory',
6057
abbr: 'C', help: 'Run this in the directory<dir>.', valueHelp: 'dir');
6158
}
@@ -67,98 +64,26 @@ class DepsCommand extends PubCommand {
6764

6865
_buffer = StringBuffer();
6966

70-
if (argResults['json']) {
71-
if (argResults.wasParsed('dev')) {
72-
usageException(
73-
'Cannot combine --json and --dev.\nThe json output contains the dependency type in the output.');
74-
}
75-
if (argResults.wasParsed('executables')) {
76-
usageException(
77-
'Cannot combine --json and --executables.\nThe json output always lists available executables.');
78-
}
79-
if (argResults.wasParsed('style')) {
80-
usageException('Cannot combine --json and --style.');
81-
}
82-
final visited = <String>[];
83-
final toVisit = [entrypoint.root.name];
84-
final packagesJson = <dynamic>[];
85-
while (toVisit.isNotEmpty) {
86-
final current = toVisit.removeLast();
87-
if (visited.contains(current)) continue;
88-
visited.add(current);
89-
final currentPackage = entrypoint.packageGraph.packages[current];
90-
final next = (current == entrypoint.root.name
91-
? entrypoint.root.immediateDependencies
92-
: currentPackage.dependencies)
93-
.keys
94-
.toList();
95-
final dependencyType = entrypoint.root.dependencyType(current);
96-
final kind = currentPackage == entrypoint.root
97-
? 'root'
98-
: (dependencyType == DependencyType.direct
99-
? 'direct'
100-
: (dependencyType == DependencyType.dev
101-
? 'dev'
102-
: 'transitive'));
103-
final source =
104-
entrypoint.packageGraph.lockFile.packages[current]?.source?.name ??
105-
'root';
106-
packagesJson.add({
107-
'name': current,
108-
'version': currentPackage.version.toString(),
109-
'kind': kind,
110-
'source': source,
111-
'dependencies': next
112-
});
113-
toVisit.addAll(next);
114-
}
115-
var executables = [
116-
for (final package in [
117-
entrypoint.root,
118-
...entrypoint.root.immediateDependencies.keys
119-
.map((name) => entrypoint.packageGraph.packages[name])
120-
])
121-
...package.executableNames.map((name) => package == entrypoint.root
122-
? ':$name'
123-
: (package.name == name ? name : '${package.name}:$name'))
124-
];
125-
126-
_buffer.writeln(
127-
JsonEncoder.withIndent(' ').convert(
128-
{
129-
'root': entrypoint.root.name,
130-
'packages': packagesJson,
131-
'sdks': [
132-
for (var sdk in sdks.values)
133-
if (sdk.version != null)
134-
{'name': sdk.name, 'version': sdk.version.toString()}
135-
],
136-
'executables': executables
137-
},
138-
),
139-
);
67+
if (argResults['executables']) {
68+
_outputExecutables();
14069
} else {
141-
if (argResults['executables']) {
142-
_outputExecutables();
143-
} else {
144-
for (var sdk in sdks.values) {
145-
if (!sdk.isAvailable) continue;
146-
_buffer.writeln("${log.bold('${sdk.name} SDK')} ${sdk.version}");
147-
}
148-
149-
_buffer.writeln(_labelPackage(entrypoint.root));
150-
151-
switch (argResults['style']) {
152-
case 'compact':
153-
_outputCompact();
154-
break;
155-
case 'list':
156-
_outputList();
157-
break;
158-
case 'tree':
159-
_outputTree();
160-
break;
161-
}
70+
for (var sdk in sdks.values) {
71+
if (!sdk.isAvailable) continue;
72+
_buffer.writeln("${log.bold('${sdk.name} SDK')} ${sdk.version}");
73+
}
74+
75+
_buffer.writeln(_labelPackage(entrypoint.root));
76+
77+
switch (argResults['style']) {
78+
case 'compact':
79+
_outputCompact();
80+
break;
81+
case 'list':
82+
_outputList();
83+
break;
84+
case 'tree':
85+
_outputTree();
86+
break;
16287
}
16388
}
16489

@@ -343,13 +268,34 @@ class DepsCommand extends PubCommand {
343268
];
344269

345270
for (var package in packages) {
346-
var executables = package.executableNames;
271+
var executables = _getExecutablesFor(package);
347272
if (executables.isNotEmpty) {
348273
_buffer.writeln(_formatExecutables(package.name, executables.toList()));
349274
}
350275
}
351276
}
352277

278+
/// Returns `true` if [path] looks like a Dart entrypoint.
279+
bool _isDartExecutable(String path) {
280+
try {
281+
var unit = analysisContextManager.parse(path);
282+
return isEntrypoint(unit);
283+
} on AnalyzerErrorGroup {
284+
return false;
285+
}
286+
}
287+
288+
/// Lists all Dart files in the `bin` directory of the [package].
289+
///
290+
/// Returns file names without extensions.
291+
Iterable<String> _getExecutablesFor(Package package) {
292+
var packagePath = p.normalize(p.absolute(package.dir));
293+
analysisContextManager.createContextsForDirectory(packagePath);
294+
return package.executablePaths
295+
.where((e) => _isDartExecutable(p.absolute(package.dir, e)))
296+
.map(p.basenameWithoutExtension);
297+
}
298+
353299
/// Returns formatted string that lists [executables] for the [packageName].
354300
/// Examples:
355301
///

lib/src/command/login.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class LoginCommand extends PubCommand {
4343
final discovery = await httpClient.get(Uri.https(
4444
'accounts.google.com', '/.well-known/openid-configuration'));
4545
final userInfoEndpoint = json.decode(discovery.body)['userinfo_endpoint'];
46-
final userInfoRequest = await client.get(Uri.parse(userInfoEndpoint));
46+
final userInfoRequest = await client.get(userInfoEndpoint);
4747
if (userInfoRequest.statusCode != 200) return null;
4848
try {
4949
final userInfo = json.decode(userInfoRequest.body);
@@ -60,5 +60,5 @@ class _UserInfo {
6060
final String email;
6161
_UserInfo(this.name, this.email);
6262
@override
63-
String toString() => ['<$email>', if (name != null) name].join(' ');
63+
String toString() => '<$email> "$name"';
6464
}

lib/src/ignore.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,8 @@ class _IgnorePrefixPair {
531531
_IgnorePrefixPair(this.ignore, this.prefix);
532532
@override
533533
String toString() {
534-
return '{${ignore._rules.map((r) => r.original)} $prefix}';
534+
// TODO: implement toString
535+
return '{${ignore._rules.map((r) => r.original)} ${prefix}}';
535536
}
536537
}
537538

lib/src/io.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -902,16 +902,13 @@ Future extractTarGz(Stream<List<int>> stream, String destination) async {
902902
/// working directory.
903903
///
904904
/// Returns a [ByteStream] that emits the contents of the archive.
905-
ByteStream createTarGz(
906-
List<String> contents, {
907-
@required String baseDir,
908-
}) {
905+
ByteStream createTarGz(List<String> contents, {String baseDir}) {
909906
var buffer = StringBuffer();
910907
buffer.write('Creating .tar.gz stream containing:\n');
911908
contents.forEach(buffer.writeln);
912909
log.fine(buffer.toString());
913910

914-
ArgumentError.checkNotNull(baseDir, 'baseDir');
911+
baseDir ??= path.current;
915912
baseDir = path.absolute(baseDir);
916913

917914
final tarContents = Stream.fromIterable(contents.map((entry) {

lib/src/package.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
import 'dart:io';
66

77
import 'package:path/path.dart' as p;
8+
import 'package:pub/src/exceptions.dart';
89
import 'package:pub_semver/pub_semver.dart';
910

10-
import 'exceptions.dart';
1111
import 'git.dart' as git;
1212
import 'ignore.dart';
1313
import 'io.dart';
@@ -84,9 +84,6 @@ class Package {
8484
.toList();
8585
}
8686

87-
List<String> get executableNames =>
88-
executablePaths.map(p.basenameWithoutExtension).toList();
89-
9087
/// Returns the path to the README file at the root of the entrypoint, or null
9188
/// if no README file is found.
9289
///

lib/src/solver/report.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,25 @@ class SolveReport {
143143
}
144144
}
145145

146+
/// Displays a single-line message, number of discontinued packages
147+
/// if discontinued packages are detected.
148+
Future<void> reportDiscontinued() async {
149+
var numDiscontinued = 0;
150+
for (var id in _result.packages) {
151+
if (id.source == null) continue;
152+
final status =
153+
await _cache.source(id.source).status(id, Duration(days: 3));
154+
if (status.isDiscontinued) numDiscontinued++;
155+
}
156+
if (numDiscontinued > 0) {
157+
if (numDiscontinued == 1) {
158+
log.message('1 package is discontinued.');
159+
} else {
160+
log.message('$numDiscontinued packages are discontinued.');
161+
}
162+
}
163+
}
164+
146165
/// Displays a two-line message, number of outdated packages and an
147166
/// instruction to run `pub outdated` if outdated packages are detected.
148167
void reportOutdated() {

lib/src/solver/result.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class SolveResult {
109109
SolveReport(type, _sources, _root, _previousLockFile, this, cache);
110110
report.summarize(dryRun: dryRun);
111111
if (type == SolveType.UPGRADE) {
112+
await report.reportDiscontinued();
112113
report.reportOutdated();
113114
}
114115
}

0 commit comments

Comments
 (0)