Unverified Commit 546b521f authored by Claire Davis's avatar Claire Davis Committed by GitHub

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

parent 1cb0a24a
...@@ -1139,7 +1139,8 @@ Future<void> refreshPluginsList( ...@@ -1139,7 +1139,8 @@ Future<void> refreshPluginsList(
bool macOSPlatform = false, bool macOSPlatform = false,
}) async { }) async {
final List<Plugin> plugins = await findPlugins(project); 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. // TODO(franciscojma): Remove once migration is complete.
// Write the legacy plugin files to avoid breaking existing apps. // Write the legacy plugin files to avoid breaking existing apps.
final bool legacyChanged = _writeFlutterPluginsListLegacy(project, plugins); final bool legacyChanged = _writeFlutterPluginsListLegacy(project, plugins);
......
...@@ -390,14 +390,25 @@ dependencies: ...@@ -390,14 +390,25 @@ dependencies:
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
testUsingContext('Refreshing the plugin list creates a plugin directory when there are plugins', () async { testUsingContext('Refreshing the plugin list creates a sorted plugin directory when there are plugins', () async {
createFakePlugin(fs); createFakePlugins(fs, <String>[
'plugin_d',
'plugin_a',
'/local_plugins/plugin_c',
'/local_plugins/plugin_b'
]);
when(iosProject.existsSync()).thenReturn(true); when(iosProject.existsSync()).thenReturn(true);
await refreshPluginsList(flutterProject); await refreshPluginsList(flutterProject);
expect(flutterProject.flutterPluginsFile.existsSync(), true); expect(flutterProject.flutterPluginsFile.existsSync(), true);
expect(flutterProject.flutterPluginsDependenciesFile.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>{ }, overrides: <Type, Generator>{
FileSystem: () => fs, FileSystem: () => fs,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment