Skip to content

Commit 26b7456

Browse files
[flutter_tools] remove late from update-packages command (#121891)
[flutter_tools] remove late from update-packages command
1 parent b81b1e2 commit 26b7456

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

packages/flutter_tools/lib/src/commands/update_packages.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -771,10 +771,8 @@ class PubspecYaml {
771771
}
772772
} else {
773773
// We're in a section we care about. Try to parse out the dependency:
774-
final PubspecDependency? dependency = PubspecDependency.parse(line, filename: filename);
774+
final PubspecDependency? dependency = PubspecDependency.parse(line, filename: filename, isDevDependency: seenDev);
775775
if (dependency != null) { // We got one!
776-
// Track whether or not this a dev dependency.
777-
dependency.isDevDependency = seenDev;
778776
result.add(dependency);
779777
if (dependency.kind == DependencyKind.unknown) {
780778
// If we didn't get a version number, then we need to be ready to
@@ -1198,9 +1196,14 @@ class PubspecDependency extends PubspecLine {
11981196
required DependencyKind kind,
11991197
required this.version,
12001198
required this.sourcePath,
1199+
required this.isDevDependency,
12011200
}) : _kind = kind;
12021201

1203-
static PubspecDependency? parse(String line, { required String filename }) {
1202+
static PubspecDependency? parse(
1203+
String line, {
1204+
required String filename,
1205+
required bool isDevDependency,
1206+
}) {
12041207
// We recognize any line that:
12051208
// * starts with exactly two spaces, no more or less
12061209
// * has some content, then a colon
@@ -1249,15 +1252,23 @@ class PubspecDependency extends PubspecLine {
12491252
if (colonIndex != -1) {
12501253
version = line.substring(colonIndex + 1, hashIndex != -1 ? hashIndex : line.length).trim();
12511254
}
1252-
return PubspecDependency(line, package, suffix, isTransitive: isTransitive, version: version, kind: stripped.isEmpty ? DependencyKind.unknown : DependencyKind.normal, sourcePath: filename);
1255+
return PubspecDependency(
1256+
line,
1257+
package,
1258+
suffix,
1259+
isTransitive: isTransitive,
1260+
version: version,
1261+
kind: stripped.isEmpty ? DependencyKind.unknown : DependencyKind.normal, sourcePath: filename,
1262+
isDevDependency: isDevDependency,
1263+
);
12531264
}
12541265

12551266
final String name; // the package name
12561267
final String suffix; // any trailing comment we found
12571268
final String version; // the version string if found, or blank.
12581269
final bool isTransitive; // whether the suffix matched kTransitiveMagicString
12591270
final String sourcePath; // the filename of the pubspec.yaml file, for error messages
1260-
late bool isDevDependency; // Whether this dependency is under the `dev dependencies` section.
1271+
final bool isDevDependency; // Whether this dependency is under the `dev dependencies` section.
12611272

12621273
DependencyKind get kind => _kind;
12631274
DependencyKind _kind = DependencyKind.normal;
@@ -1274,8 +1285,7 @@ class PubspecDependency extends PubspecLine {
12741285
/// dependencies/dev_dependencies section, or a dependency_overrides section.
12751286
/// We track this so that we can put ourselves in the right section when
12761287
/// generating the fake pubspec.yaml.
1277-
bool get lockIsOverride => _lockIsOverride;
1278-
late bool _lockIsOverride;
1288+
bool _lockIsOverride = false;
12791289

12801290
static const String _pathPrefix = ' path: ';
12811291
static const String _sdkPrefix = ' sdk: ';
@@ -1372,7 +1382,7 @@ class PubspecDependency extends PubspecLine {
13721382
}
13731383
break;
13741384
case DependencyKind.path:
1375-
if (lockIsOverride) {
1385+
if (_lockIsOverride) {
13761386
dependencies.writeln(' $name: $versionToUse');
13771387
overrides.writeln(' $name:');
13781388
overrides.writeln(' path: $_lockTarget');
@@ -1382,7 +1392,7 @@ class PubspecDependency extends PubspecLine {
13821392
}
13831393
break;
13841394
case DependencyKind.sdk:
1385-
if (lockIsOverride) {
1395+
if (_lockIsOverride) {
13861396
dependencies.writeln(' $name: $versionToUse');
13871397
overrides.writeln(' $name:');
13881398
overrides.writeln(' sdk: $_lockTarget');
@@ -1392,7 +1402,7 @@ class PubspecDependency extends PubspecLine {
13921402
}
13931403
break;
13941404
case DependencyKind.git:
1395-
if (lockIsOverride) {
1405+
if (_lockIsOverride) {
13961406
dependencies.writeln(' $name: $versionToUse');
13971407
overrides.writeln(' $name:');
13981408
overrides.writeln(lockLine);

packages/flutter_tools/test/commands.shard/hermetic/update_packages_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ void main() {
236236
sourcePath: '/path/to/pubspec.yaml',
237237
kind: DependencyKind.normal,
238238
isTransitive: false,
239+
isDevDependency: false,
239240
),
240241
],
241242
doUpgrade: true,
@@ -255,6 +256,7 @@ void main() {
255256
sourcePath: '/path/to/pubspec.yaml',
256257
kind: DependencyKind.normal,
257258
isTransitive: false,
259+
isDevDependency: false,
258260
),
259261
],
260262
);

0 commit comments

Comments
 (0)