[tool] Check for any Flutter SDK dependency#11875
Conversation
When determining whether a package requires `flutter`, look for any `sdk: flutter` dependency rather than just for the `flutter` dependency in particular. This will ensure that includes, for example, packages with a `flutter_test` dev dependency, but no `flutter` dependency.
There was a problem hiding this comment.
Code Review
This pull request updates the requiresFlutter method in RepositoryPackage to identify Flutter SDK dependencies within both dependencies and devDependencies using a new helper method. A corresponding test has been added to verify this behavior. The review feedback points out that mutating the parsed Pubspec object and writing its toString() representation to disk in the test is fragile and will corrupt the file, suggesting instead to write the YAML string directly to the file.
| test('returns true for a dev dependency on other Flutter SDK packages', () async { | ||
| final RepositoryPackage package = createFakePackage('a_package', packagesDir); | ||
| final File pubspecFile = package.pubspecFile; | ||
| final Pubspec pubspec = package.parsePubspec(); | ||
| pubspec.devDependencies['flutter_test'] = SdkDependency('flutter'); | ||
| pubspecFile.writeAsStringSync(pubspec.toString()); | ||
|
|
||
| expect(package.requiresFlutter(), true); | ||
| }); |
There was a problem hiding this comment.
Mutating the parsed Pubspec object in memory and writing pubspec.toString() to the file is fragile and corrupts the file on disk, as Pubspec from pubspec_parse does not serialize back to valid YAML via toString(). Instead, write the valid YAML string directly to the pubspecFile before calling any methods on the package.
test('returns true for a dev dependency on other Flutter SDK packages', () async {
final RepositoryPackage package = createFakePackage('a_package', packagesDir);
package.pubspecFile.writeAsStringSync('''
name: a_package
dev_dependencies:
flutter_test:
sdk: flutter
''');
expect(package.requiresFlutter(), true);
});There was a problem hiding this comment.
All the existing tests of this method use this pattern, and they've all been fine. Reworking all of these tests is out of scope here.
|
autosubmit label was removed for flutter/packages/11875, because - The status or check suite Linux_android_legacy android_platform_tests_legacy_api_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label.
|
jakemac53
left a comment
There was a problem hiding this comment.
LGTM but see the test comments from gemini
When determining whether a package requires
flutter, look for anysdk: flutterdependency rather than just for theflutterdependency in particular. This will ensure that includes, for example, packages with aflutter_testdev dependency, but noflutterdependency.