Skip to content

[tool] Handle Flutter dev dependencies #5775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions script/tool/lib/src/common/repository_package.dart
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ class RepositoryPackage {

/// Returns true if the package depends on Flutter.
bool requiresFlutter() {
const String flutterDependency = 'flutter';
final Pubspec pubspec = parsePubspec();
return pubspec.dependencies.containsKey('flutter');
return pubspec.dependencies.containsKey(flutterDependency) ||
pubspec.devDependencies.containsKey(flutterDependency);
}

/// True if this appears to be a federated plugin package, according to
Expand Down Expand Up @@ -151,7 +153,9 @@ class RepositoryPackage {
return false;
}
// Check whether this is one of the enclosing package's examples.
return enclosingPackage.getExamples().any((RepositoryPackage p) => p.path == path);
return enclosingPackage
.getExamples()
.any((RepositoryPackage p) => p.path == path);
}

/// Returns the Flutter example packages contained in the package, if any.
Expand Down
12 changes: 12 additions & 0 deletions script/tool/test/common/repository_package_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:test/test.dart';

import '../util.dart';
Expand Down Expand Up @@ -221,6 +222,17 @@ void main() {
expect(package.requiresFlutter(), true);
});

test('returns true for a dev dependency on Flutter', () async {
final RepositoryPackage package =
createFakePackage('a_package', packagesDir);
final File pubspecFile = package.pubspecFile;
final Pubspec pubspec = package.parsePubspec();
pubspec.devDependencies['flutter'] = SdkDependency('flutter');
pubspecFile.writeAsStringSync(pubspec.toString());

expect(package.requiresFlutter(), true);
});

test('returns false for non-Flutter package', () async {
final RepositoryPackage package =
createFakePackage('a_package', packagesDir);
Expand Down