Skip to content

Commit e51b160

Browse files
authored
Remove features for migrating to null safety (#3713)
1 parent f3cf3ac commit e51b160

27 files changed

+39
-2921
lines changed

lib/src/command/outdated.dart

Lines changed: 11 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ import 'dart:convert';
77
import 'dart:io';
88
import 'dart:math';
99

10-
import 'package:collection/collection.dart'
11-
show IterableExtension, IterableNullableExtension;
10+
import 'package:collection/collection.dart' show IterableExtension;
1211
import 'package:path/path.dart' as path;
1312

1413
import '../command.dart';
@@ -69,12 +68,12 @@ class OutdatedCommand extends PubCommand {
6968
valueHelp: 'PROPERTY',
7069
allowed: ['outdated', 'null-safety'],
7170
defaultsTo: 'outdated',
71+
hide: true,
7272
);
7373

7474
argParser.addFlag(
7575
'prereleases',
76-
help: 'Include prereleases in latest version.\n'
77-
'(defaults to on in --mode=null-safety).',
76+
help: 'Include prereleases in latest version.',
7877
);
7978

8079
// Preserve for backwards compatibility.
@@ -98,20 +97,19 @@ class OutdatedCommand extends PubCommand {
9897
);
9998
argParser.addFlag(
10099
'transitive',
101-
help: 'Show transitive dependencies.\n'
102-
'(defaults to off in --mode=null-safety).',
100+
help: 'Show transitive dependencies.',
103101
);
104102
argParser.addOption('directory',
105103
abbr: 'C', help: 'Run this in the directory<dir>.', valueHelp: 'dir');
106104
}
107105

108106
@override
109107
Future<void> runProtected() async {
110-
final mode = <String, _Mode>{
111-
'outdated': _OutdatedMode(),
112-
'null-safety': _NullSafetyMode(cache, entrypoint,
113-
shouldShowSpinner: _shouldShowSpinner),
114-
}[argResults['mode']]!;
108+
if (argResults['mode'] == 'null-safety') {
109+
dataError('''The `--mode=null-safety` option is no longer supported.
110+
Consider using the Dart 2.19 sdk to migrate to null safety.''');
111+
}
112+
final mode = _OutdatedMode();
115113

116114
final includeDevDependencies = argResults['dev-dependencies'];
117115
final includeDependencyOverrides = argResults['dependency-overrides'];
@@ -288,11 +286,7 @@ class OutdatedCommand extends PubCommand {
288286
}
289287

290288
bool get showTransitiveDependencies {
291-
if (argResults.wasParsed('transitive')) {
292-
return argResults['transitive'];
293-
}
294-
// We default to hidding transitive dependencies in --mode=null-safety
295-
return argResults['mode'] != 'null-safety';
289+
return argResults['transitive'];
296290
}
297291

298292
late final bool prereleases = () {
@@ -306,7 +300,7 @@ class OutdatedCommand extends PubCommand {
306300
if (argResults.wasParsed('pre-releases')) {
307301
return argResults['pre-releases'];
308302
}
309-
return argResults['mode'] == 'null-safety';
303+
return false;
310304
}();
311305

312306
/// Retrieves the pubspec of package [name] in [version] from [source].
@@ -691,115 +685,6 @@ Showing outdated packages$directoryDescription.
691685
}
692686
}
693687

694-
class _NullSafetyMode implements _Mode {
695-
final SystemCache cache;
696-
final Entrypoint entrypoint;
697-
final bool shouldShowSpinner;
698-
699-
final _compliantEmoji = emoji('✓', '+');
700-
final _notCompliantEmoji = emoji('✗', 'x');
701-
702-
_NullSafetyMode(this.cache, this.entrypoint,
703-
{required this.shouldShowSpinner});
704-
705-
@override
706-
String explanation(String directoryDescription) => '''
707-
Showing dependencies$directoryDescription that are currently not opted in to null-safety.
708-
[${log.red(_notCompliantEmoji)}] indicates versions without null safety support.
709-
[${log.green(_compliantEmoji)}] indicates versions opting in to null safety.
710-
''';
711-
712-
@override
713-
String get foundNoBadText =>
714-
'All your dependencies declare support for null-safety.';
715-
716-
@override
717-
String get allGood => 'all support null safety.';
718-
719-
@override
720-
String get noResolutionText =>
721-
'''No resolution was found. Try running `$topLevelProgram pub upgrade --null-safety --dry-run` to explore why.''';
722-
723-
@override
724-
String get upgradeConstrained =>
725-
'edit pubspec.yaml, or run `$topLevelProgram pub upgrade --null-safety`';
726-
727-
@override
728-
String get allSafe => 'All dependencies opt in to null-safety.';
729-
730-
@override
731-
Future<List<List<_MarkedVersionDetails>>> markVersionDetails(
732-
List<_PackageDetails> packages) async {
733-
final nullSafetyMap =
734-
await log.spinner('Computing null safety support', () async {
735-
/// Find all unique ids.
736-
final ids = {
737-
for (final packageDetails in packages) ...[
738-
packageDetails.current?._id,
739-
packageDetails.upgradable?._id,
740-
packageDetails.resolvable?._id,
741-
packageDetails.latest?._id,
742-
]
743-
}.whereNotNull();
744-
745-
return Map.fromEntries(
746-
await Future.wait(
747-
ids.map(
748-
(id) async => MapEntry(id,
749-
(await cache.describe(id)).languageVersion.supportsNullSafety),
750-
),
751-
),
752-
);
753-
}, condition: shouldShowSpinner);
754-
return [
755-
for (final packageDetails in packages)
756-
[
757-
packageDetails.current,
758-
packageDetails.upgradable,
759-
packageDetails.resolvable,
760-
packageDetails.latest
761-
].map(
762-
(versionDetails) {
763-
String Function(String)? color;
764-
String? prefix;
765-
String? suffix;
766-
MapEntry<String, Object>? jsonExplanation;
767-
var asDesired = false;
768-
if (versionDetails != null) {
769-
if (packageDetails.isDiscontinued &&
770-
identical(versionDetails, packageDetails.latest)) {
771-
suffix = ' (discontinued)';
772-
}
773-
if (nullSafetyMap[versionDetails._id]!) {
774-
color = log.green;
775-
prefix = _compliantEmoji;
776-
jsonExplanation = MapEntry('nullSafety', true);
777-
asDesired = true;
778-
} else {
779-
color = log.red;
780-
prefix = _notCompliantEmoji;
781-
jsonExplanation = MapEntry('nullSafety', false);
782-
}
783-
}
784-
return _MarkedVersionDetails(
785-
versionDetails,
786-
asDesired: asDesired,
787-
format: color,
788-
prefix: prefix,
789-
suffix: suffix,
790-
jsonExplanation: jsonExplanation,
791-
);
792-
},
793-
).toList()
794-
];
795-
}
796-
797-
@override
798-
Future<Pubspec> resolvablePubspec(Pubspec pubspec) async {
799-
return constrainedToAtLeastNullSafetyPubspec(pubspec, cache);
800-
}
801-
}
802-
803688
/// Details about a single version of a package.
804689
class _VersionDetails {
805690
final Pubspec _pubspec;

0 commit comments

Comments
 (0)