[flutter_tools] Sort plugins alphabetically when refreshed (#73803)

This commit is contained in:
Claire Davis 2021-01-13 12:41:16 -05:00 committed by GitHub
parent 1cb0a24a46
commit 546b521f33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 3 deletions

View file

@ -1139,7 +1139,8 @@ Future<void> refreshPluginsList(
bool macOSPlatform = false,
}) async {
final List<Plugin> plugins = await findPlugins(project);
// Sort the plugins by name to keep ordering stable in generated files.
plugins.sort((Plugin left, Plugin right) => left.name.compareTo(right.name));
// TODO(franciscojma): Remove once migration is complete.
// Write the legacy plugin files to avoid breaking existing apps.
final bool legacyChanged = _writeFlutterPluginsListLegacy(project, plugins);

View file

@ -390,14 +390,25 @@ dependencies:
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('Refreshing the plugin list creates a plugin directory when there are plugins', () async {
createFakePlugin(fs);
testUsingContext('Refreshing the plugin list creates a sorted plugin directory when there are plugins', () async {
createFakePlugins(fs, <String>[
'plugin_d',
'plugin_a',
'/local_plugins/plugin_c',
'/local_plugins/plugin_b'
]);
when(iosProject.existsSync()).thenReturn(true);
await refreshPluginsList(flutterProject);
expect(flutterProject.flutterPluginsFile.existsSync(), true);
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true);
final String pluginsFileContents = flutterProject.flutterPluginsFile.readAsStringSync();
expect(pluginsFileContents.indexOf('plugin_a'), lessThan(pluginsFileContents.indexOf('plugin_b')));
expect(pluginsFileContents.indexOf('plugin_b'), lessThan(pluginsFileContents.indexOf('plugin_c')));
expect(pluginsFileContents.indexOf('plugin_c'), lessThan(pluginsFileContents.indexOf('plugin_d')));
}, overrides: <Type, Generator>{
FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(),