[all] Add topics to pubspecs (#4771)

Adds [topics](https://dart.dev/tools/pub/pubspec#topics) to all
packages, supporting the new pub feature for categorizing packages. The
heuristics I used were:
- Try to use existing topics from https://pub.dev/topics where
applicable
- Add new topics as necessary to cover things that seemed like obvious
relevant topics
- Include the plugin name as a topic for all federated plugin packages,
for grouping (since pub doesn't inherently group or cross-link
implementations)

This is not an attempt to be exhaustive; as topics evolve I expect we
will add more or adjust.

Also updates the repo tooling to enforce topics, so that we don't forget
to add them to new packages. The enforced rule is:
- All packages must have at least one topic. We could potentially change
this to allow an empty `topics` section so that we are enforcing that we
didn't just forget to add the section, but in practice even for packages
that we don't expect people to be likely to use, I didn't have any issue
coming up with at least one relevant topic.
- Federated plugin packages must contain the plugin name as a topic.

While this isn't time-critical, I chose to include version bumps so that
we aren't rolling out topics in a piecemeal way (e.g., with only a
random subset of a federated plugin's packages having topics on pub.dev
based on what has happened to have a bugfix).
This commit is contained in:
stuartmorgan
2023-08-29 10:31:23 -07:00
committed by GitHub
parent 2fe1961828
commit b4985e25fe
216 changed files with 1029 additions and 207 deletions

View File

@ -11,6 +11,7 @@ import 'package:yaml/yaml.dart';
import 'common/core.dart';
import 'common/output_utils.dart';
import 'common/package_looping_command.dart';
import 'common/plugin_utils.dart';
import 'common/repository_package.dart';
/// A command to enforce pubspec conventions across the repository.
@ -58,6 +59,8 @@ class PubspecCheckCommand extends PackageLoopingCommand {
'flutter:',
'dependencies:',
'dev_dependencies:',
'topics:',
'screenshots:',
'false_secrets:',
];
@ -66,6 +69,8 @@ class PubspecCheckCommand extends PackageLoopingCommand {
'dependencies:',
'dev_dependencies:',
'flutter:',
'topics:',
'screenshots:',
'false_secrets:',
];
@ -219,6 +224,12 @@ class PubspecCheckCommand extends PackageLoopingCommand {
passing = false;
}
final String? topicsError = _checkTopics(pubspec, package: package);
if (topicsError != null) {
printError('$indentation$topicsError');
passing = false;
}
// Don't check descriptions for federated package components other than
// the app-facing package, since they are unlisted, and are expected to
// have short descriptions.
@ -321,6 +332,29 @@ class PubspecCheckCommand extends PackageLoopingCommand {
false;
}
// Validates the "implements" keyword for a plugin, returning an error
// string if there are any issues.
String? _checkTopics(
Pubspec pubspec, {
required RepositoryPackage package,
}) {
final List<String> topics = pubspec.topics ?? <String>[];
if (topics.isEmpty) {
return 'A published package should include "topics". '
'See https://dart.dev/tools/pub/pubspec#topics.';
}
if (isFlutterPlugin(package) && package.isFederated) {
final String pluginName = package.directory.parent.basename;
// '_' isn't allowed in topics, so convert to '-'.
final String topicName = pluginName.replaceAll('_', '-');
if (!topics.contains(topicName)) {
return 'A federated plugin package should include its plugin name as '
'a topic. Add "$topicName" to the "topics" section.';
}
}
return null;
}
// Validates the "implements" keyword for a plugin, returning an error
// string if there are any issues.
//