Skip to content

Commit 531836e

Browse files
authored
Use sorted from package:collection instead of custom util function (#4516)
1 parent 2d61441 commit 531836e

File tree

8 files changed

+29
-29
lines changed

8 files changed

+29
-29
lines changed

lib/src/ascii_tree.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ library;
88

99
import 'dart:io';
1010

11+
import 'package:collection/collection.dart';
1112
import 'package:path/path.dart' as p;
1213

1314
import 'log.dart' as log;
@@ -165,7 +166,7 @@ void _draw(
165166
if (name != null) _drawLine(buffer, prefix, isLast, name, depth <= 1);
166167

167168
// Recurse to the children.
168-
final childNames = ordered(children.keys);
169+
final childNames = children.keys.sorted();
169170

170171
void drawChild(bool isLastChild, String child) {
171172
final childPrefix = _getPrefix(depth <= 1, isLast);

lib/src/command/deps.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'dart:collection';
66
import 'dart:convert';
77

8+
import 'package:collection/collection.dart';
9+
810
import '../ascii_tree.dart' as tree;
911
import '../command.dart';
1012
import '../command_runner.dart';
@@ -243,7 +245,7 @@ class DepsCommand extends PubCommand {
243245

244246
buffer.writeln();
245247
buffer.writeln('$section:');
246-
for (var name in ordered(names)) {
248+
for (var name in names.sorted()) {
247249
final package = await _getPackage(name);
248250

249251
buffer.write('- ${_labelPackage(package)}');
@@ -291,7 +293,7 @@ class DepsCommand extends PubCommand {
291293

292294
await _outputListSection(
293295
'transitive dependencies',
294-
ordered(transitive),
296+
transitive.sorted(),
295297
buffer,
296298
);
297299
}

lib/src/entrypoint.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'dart:convert';
77
import 'dart:io';
88
import 'dart:math';
99

10+
import 'package:collection/collection.dart';
1011
import 'package:path/path.dart' as p;
1112
import 'package:pool/pool.dart';
1213
import 'package:pub_semver/pub_semver.dart';
@@ -436,7 +437,7 @@ See $workspacesDocUrl for more information.''',
436437
final entries = <PackageConfigEntry>[];
437438
if (lockFile.packages.isNotEmpty) {
438439
final relativeFromPath = p.join(workspaceRoot.dir, '.dart_tool');
439-
for (final name in ordered(lockFile.packages.keys)) {
440+
for (final name in lockFile.packages.keys.sorted()) {
440441
final id = lockFile.packages[name]!;
441442
final rootPath = cache.getDirectory(id, relativeFrom: relativeFromPath);
442443
final pubspec = await cache.describe(id);

lib/src/global_packages.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import 'dart:async';
66
import 'dart:io';
77

8+
import 'package:collection/collection.dart';
89
import 'package:path/path.dart' as p;
910
import 'package:pub_semver/pub_semver.dart';
1011

@@ -767,7 +768,7 @@ Try reactivating the package.
767768

768769
final installed = <String>[];
769770
final collided = <String, String>{};
770-
final allExecutables = ordered(package.pubspec.executables.keys);
771+
final allExecutables = package.pubspec.executables.keys.sorted();
771772
for (var executable in allExecutables) {
772773
if (executables != null && !executables.contains(executable)) continue;
773774

@@ -799,7 +800,7 @@ Try reactivating the package.
799800

800801
// Show errors for any collisions.
801802
if (collided.isNotEmpty) {
802-
for (var command in ordered(collided.keys)) {
803+
for (var command in collided.keys.sorted()) {
803804
if (overwriteBinStubs) {
804805
log.warning('Replaced ${log.bold(command)} previously installed from '
805806
'${log.bold(collided[command].toString())}.');
@@ -817,10 +818,9 @@ Try reactivating the package.
817818

818819
// Show errors for any unknown executables.
819820
if (executables != null) {
820-
final unknown = ordered(
821-
executables
822-
.where((exe) => !package.pubspec.executables.keys.contains(exe)),
823-
);
821+
final unknown = executables
822+
.where((exe) => !package.pubspec.executables.keys.contains(exe))
823+
.sorted();
824824
if (unknown.isNotEmpty) {
825825
dataError("Unknown ${namedSequence('executable', unknown)}.");
826826
}

lib/src/package.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,23 @@ class Package {
9898
/// This includes regular, dev dependencies, and overrides from this package.
9999
Map<String, PackageRange> get immediateDependencies {
100100
// Make sure to add overrides last so they replace normal dependencies.
101-
return {}
102-
..addAll(dependencies)
103-
..addAll(devDependencies)
104-
..addAll(pubspec.dependencyOverrides);
101+
return {
102+
...dependencies,
103+
...devDependencies,
104+
...pubspec.dependencyOverrides,
105+
};
105106
}
106107

107-
/// Returns a list of paths to all Dart executables in this package's bin
108-
/// directory.
108+
/// Returns a list of paths to all Dart executables in
109+
/// this package's `bin` directory.
109110
List<String> get executablePaths {
110111
final binDir = p.join(dir, 'bin');
111112
if (!dirExists(binDir)) return <String>[];
112-
return ordered(listDir(p.join(dir, 'bin'), includeDirs: false))
113-
.where((executable) => p.extension(executable) == '.dart')
114-
.map((executable) => p.relative(executable, from: dir))
115-
.toList();
113+
return [
114+
for (var executable in listDir(binDir, includeDirs: false))
115+
if (p.extension(executable) == '.dart')
116+
p.relative(executable, from: dir),
117+
]..sort();
116118
}
117119

118120
List<String> get executableNames =>

lib/src/solver/package_lister.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ class PackageLister {
318318
final lower = await _dependencyBounds(dependencies, index, upper: false);
319319
final upper = await _dependencyBounds(dependencies, index);
320320

321-
return ordered(dependencies.keys).map((package) {
321+
return dependencies.keys.sorted().map((package) {
322322
final constraint = VersionRange(
323323
min: lower[package],
324324
includeMin: true,

lib/src/solver/report.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
import 'package:collection/collection.dart';
56
import 'package:path/path.dart' as p;
67
import 'package:pub_semver/pub_semver.dart';
78

@@ -225,7 +226,7 @@ $contentHashesDocumentationUrl
225226
removed.remove(_rootPubspec.name); // Never consider root.
226227
if (removed.isNotEmpty) {
227228
output.writeln('These packages are no longer being depended on:');
228-
for (var name in ordered(removed)) {
229+
for (var name in removed.sorted()) {
229230
await _reportPackage(name, output, alwaysShow: true);
230231
changes += 1;
231232
}

lib/src/utils.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,6 @@ bool isLoopback(String host) {
258258
return InternetAddress.tryParse(host)?.isLoopback ?? false;
259259
}
260260

261-
/// Returns a list containing the sorted elements of [iter].
262-
List<T> ordered<T extends Comparable<T>>(Iterable<T> iter) {
263-
final list = iter.toList();
264-
list.sort();
265-
return list;
266-
}
267-
268261
/// Given a list of filenames, returns a set of patterns that can be used to
269262
/// filter for those filenames.
270263
///

0 commit comments

Comments
 (0)