Skip to content

Commit 51174d1

Browse files
[tool] Use ^ for Dart SDK (#5623)
The update-min-sdk command has been using explicitly ranges for the Dart SDK, because that used to be required. Current versions of `pub` no longer require that, and using `^` for Dart ranges is okay, so this updates the tooling to use that format in the future. Also removes the special casing that changed the upper bound from 3 to 4, since we have passed the point where we are generating upper bounds less than 4 anyway. To minimize churn, this doesn't update the existing pubspecs. We can incrementally adopt this going forward as we roll dependencies forward. Fixes flutter/flutter#139806
1 parent 5e81fd5 commit 51174d1

File tree

2 files changed

+27
-42
lines changed

2 files changed

+27
-42
lines changed

script/tool/lib/src/update_min_sdk_command.dart

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,8 @@ class UpdateMinSdkCommand extends PackageLoopingCommand {
6969
YamlEditor(package.pubspecFile.readAsStringSync());
7070
if (dartRange != null &&
7171
(dartRange.min ?? Version.none) < _dartMinVersion) {
72-
Version upperBound = _dartMinVersion.nextMajor;
73-
// pub special-cases 3.0.0 as an upper bound to be treated as 4.0.0, and
74-
// using 3.0.0 is now an error at upload time, so special case it here.
75-
if (upperBound.major == 3) {
76-
upperBound = upperBound.nextMajor;
77-
}
78-
editablePubspec.update(
79-
<String>[environmentKey, dartSdkKey],
80-
VersionRange(min: _dartMinVersion, includeMin: true, max: upperBound)
81-
.toString());
72+
editablePubspec
73+
.update(<String>[environmentKey, dartSdkKey], '^$_dartMinVersion');
8274
print('${indentation}Updating Dart minimum to $_dartMinVersion');
8375
}
8476
if (flutterRange != null &&

script/tool/test/update_min_sdk_command_test.dart

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,98 +38,91 @@ void main() {
3838
expect(commandError, isA<ArgumentError>());
3939
});
4040

41-
test('updates Dart when only Dart is present', () async {
41+
test('updates Dart when only Dart is present, with manual range', () async {
4242
final RepositoryPackage package = createFakePackage(
4343
'a_package', packagesDir,
44-
dartConstraint: '>=2.12.0 <4.0.0');
44+
dartConstraint: '>=3.0.0 <4.0.0');
4545

4646
await runCapturingPrint(runner, <String>[
4747
'update-min-sdk',
4848
'--flutter-min',
49-
'3.3.0', // Corresponds to Dart 2.18.0
49+
'3.13.0', // Corresponds to Dart 3.1.0
5050
]);
5151

5252
final String dartVersion =
5353
package.parsePubspec().environment?['sdk'].toString() ?? '';
54-
expect(dartVersion, '>=2.18.0 <4.0.0');
54+
expect(dartVersion, '^3.1.0');
5555
});
5656

57-
test('does not update Dart if it is already higher', () async {
58-
final RepositoryPackage package = createFakePackage(
59-
'a_package', packagesDir,
60-
dartConstraint: '>=2.19.0 <4.0.0');
57+
test('updates Dart when only Dart is present, with carrot', () async {
58+
final RepositoryPackage package =
59+
createFakePackage('a_package', packagesDir, dartConstraint: '^3.0.0');
6160

6261
await runCapturingPrint(runner, <String>[
6362
'update-min-sdk',
6463
'--flutter-min',
65-
'3.3.0', // Corresponds to Dart 2.18.0
64+
'3.13.0', // Corresponds to Dart 3.1.0
6665
]);
6766

6867
final String dartVersion =
6968
package.parsePubspec().environment?['sdk'].toString() ?? '';
70-
expect(dartVersion, '>=2.19.0 <4.0.0');
69+
expect(dartVersion, '^3.1.0');
7170
});
7271

73-
test('updates both Dart and Flutter when both are present', () async {
74-
final RepositoryPackage package = createFakePackage(
75-
'a_package', packagesDir,
76-
isFlutter: true,
77-
dartConstraint: '>=2.12.0 <4.0.0',
78-
flutterConstraint: '>=2.10.0');
72+
test('does not update Dart if it is already higher', () async {
73+
final RepositoryPackage package =
74+
createFakePackage('a_package', packagesDir, dartConstraint: '^3.2.0');
7975

8076
await runCapturingPrint(runner, <String>[
8177
'update-min-sdk',
8278
'--flutter-min',
83-
'3.3.0', // Corresponds to Dart 2.18.0
79+
'3.13.0', // Corresponds to Dart 3.1.0
8480
]);
8581

8682
final String dartVersion =
8783
package.parsePubspec().environment?['sdk'].toString() ?? '';
88-
final String flutterVersion =
89-
package.parsePubspec().environment?['flutter'].toString() ?? '';
90-
expect(dartVersion, '>=2.18.0 <4.0.0');
91-
expect(flutterVersion, '>=3.3.0');
84+
expect(dartVersion, '^3.2.0');
9285
});
9386

94-
test('handles Flutter 3.10.0', () async {
87+
test('updates both Dart and Flutter when both are present', () async {
9588
final RepositoryPackage package = createFakePackage(
9689
'a_package', packagesDir,
9790
isFlutter: true,
98-
dartConstraint: '>=2.12.0 <4.0.0',
99-
flutterConstraint: '>=2.10.0');
91+
dartConstraint: '>=3.0.0 <4.0.0',
92+
flutterConstraint: '>=3.10.0');
10093

10194
await runCapturingPrint(runner, <String>[
10295
'update-min-sdk',
10396
'--flutter-min',
104-
'3.10.0', // Corresponds to Dart 3.0.0
97+
'3.13.0', // Corresponds to Dart 3.1.0
10598
]);
10699

107100
final String dartVersion =
108101
package.parsePubspec().environment?['sdk'].toString() ?? '';
109102
final String flutterVersion =
110103
package.parsePubspec().environment?['flutter'].toString() ?? '';
111-
expect(dartVersion, '>=3.0.0 <4.0.0');
112-
expect(flutterVersion, '>=3.10.0');
104+
expect(dartVersion, '^3.1.0');
105+
expect(flutterVersion, '>=3.13.0');
113106
});
114107

115108
test('does not update Flutter if it is already higher', () async {
116109
final RepositoryPackage package = createFakePackage(
117110
'a_package', packagesDir,
118111
isFlutter: true,
119-
dartConstraint: '>=2.19.0 <4.0.0',
120-
flutterConstraint: '>=3.7.0');
112+
dartConstraint: '^3.2.0',
113+
flutterConstraint: '>=3.16.0');
121114

122115
await runCapturingPrint(runner, <String>[
123116
'update-min-sdk',
124117
'--flutter-min',
125-
'3.3.0', // Corresponds to Dart 2.18.0
118+
'3.13.0', // Corresponds to Dart 3.1.0
126119
]);
127120

128121
final String dartVersion =
129122
package.parsePubspec().environment?['sdk'].toString() ?? '';
130123
final String flutterVersion =
131124
package.parsePubspec().environment?['flutter'].toString() ?? '';
132-
expect(dartVersion, '>=2.19.0 <4.0.0');
133-
expect(flutterVersion, '>=3.7.0');
125+
expect(dartVersion, '^3.2.0');
126+
expect(flutterVersion, '>=3.16.0');
134127
});
135128
}

0 commit comments

Comments
 (0)