[url_launcher] Support new desktop implementation versions (#4779)

This commit is contained in:
stuartmorgan
2022-02-10 17:35:22 -05:00
committed by GitHub
parent 7009234867
commit 4aeb80aed7
3 changed files with 148 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import 'package:file/file.dart';
import 'package:git/git.dart';
import 'package:platform/platform.dart';
import 'package:pubspec_parse/pubspec_parse.dart';
import 'package:yaml/yaml.dart';
import 'common/core.dart';
import 'common/package_looping_command.dart';
@ -100,9 +101,17 @@ class PubspecCheckCommand extends PackageLoopingCommand {
}
if (isPlugin) {
final String? error = _checkForImplementsError(pubspec, package: package);
if (error != null) {
printError('$indentation$error');
final String? implementsError =
_checkForImplementsError(pubspec, package: package);
if (implementsError != null) {
printError('$indentation$implementsError');
passing = false;
}
final String? defaultPackageError =
_checkForDefaultPackageError(pubspec, package: package);
if (defaultPackageError != null) {
printError('$indentation$defaultPackageError');
passing = false;
}
}
@ -243,6 +252,49 @@ class PubspecCheckCommand extends PackageLoopingCommand {
return null;
}
// Validates any "default_package" entries a plugin, returning an error
// string if there are any issues.
//
// Should only be called on plugin packages.
String? _checkForDefaultPackageError(
Pubspec pubspec, {
required RepositoryPackage package,
}) {
final dynamic platformsEntry = pubspec.flutter!['plugin']!['platforms'];
if (platformsEntry == null) {
logWarning('Does not implement any platforms');
return null;
}
final YamlMap platforms = platformsEntry as YamlMap;
final String packageName = package.directory.basename;
// Validate that the default_package entries look correct (e.g., no typos).
final Set<String> defaultPackages = <String>{};
for (final MapEntry<dynamic, dynamic> platformEntry in platforms.entries) {
final String? defaultPackage =
platformEntry.value['default_package'] as String?;
if (defaultPackage != null) {
defaultPackages.add(defaultPackage);
if (!defaultPackage.startsWith('${packageName}_')) {
return '"$defaultPackage" is not an expected implementation name '
'for "$packageName"';
}
}
}
// Validate that all default_packages are also dependencies.
final Iterable<String> dependencies = pubspec.dependencies.keys;
final Iterable<String> missingPackages = defaultPackages
.where((String package) => !dependencies.contains(package));
if (missingPackages.isNotEmpty) {
return 'The following default_packages are missing '
'corresponding dependencies:\n ' +
missingPackages.join('\n ');
}
return null;
}
// Returns true if [packageName] appears to be an implementation package
// according to repository conventions.
bool _isImplementationPackage(RepositoryPackage package) {