Skip to content

Commit 901eb0f

Browse files
author
Michael Klimushyn
authored
Add a note to generated plugins files (flutter#45557)
There has been some confusion about whether or not .flutter-plugins-dependencies should be tracked in version control or not. Added a comment to both it and .flutter-plugins explaining that it's generated and shouldn't be. .flutter-plugins-dependencies is parsed through JSON, and the JSON spec doesn't support comments. So unfortunately the note is living in an arbitrary "_info" key instead of an obvious top level comment.
1 parent 4cc10a1 commit 901eb0f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/flutter_tools/lib/src/plugins.dart

+5-3
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,8 @@ List<Plugin> findPlugins(FlutterProject project) {
317317
/// otherwise returns [false].
318318
bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
319319
final List<dynamic> directAppDependencies = <dynamic>[];
320-
final StringBuffer flutterPluginsBuffer = StringBuffer();
320+
const String info = 'This is a generated file; do not edit or check into version control.';
321+
final StringBuffer flutterPluginsBuffer = StringBuffer('# $info\n');
321322

322323
final Set<String> pluginNames = <String>{};
323324
for (Plugin plugin in plugins) {
@@ -334,7 +335,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
334335
final File pluginsFile = project.flutterPluginsFile;
335336
final String oldPluginFileContent = _readFileContent(pluginsFile);
336337
final String pluginFileContent = flutterPluginsBuffer.toString();
337-
if (pluginFileContent.isNotEmpty) {
338+
if (pluginNames.isNotEmpty) {
338339
pluginsFile.writeAsStringSync(pluginFileContent, flush: true);
339340
} else {
340341
if (pluginsFile.existsSync()) {
@@ -345,9 +346,10 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
345346
final File dependenciesFile = project.flutterPluginsDependenciesFile;
346347
final String oldDependenciesFileContent = _readFileContent(dependenciesFile);
347348
final String dependenciesFileContent = json.encode(<String, dynamic>{
349+
'_info': '// $info',
348350
'dependencyGraph': directAppDependencies,
349351
});
350-
if (pluginFileContent.isNotEmpty) {
352+
if (pluginNames.isNotEmpty) {
351353
dependenciesFile.writeAsStringSync(dependenciesFileContent, flush: true);
352354
} else {
353355
if (dependenciesFile.existsSync()) {

packages/flutter_tools/test/general.shard/plugins_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -273,13 +273,15 @@ dependencies:
273273
expect(flutterProject.flutterPluginsFile.existsSync(), true);
274274
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true);
275275
expect(flutterProject.flutterPluginsFile.readAsStringSync(),
276+
'# This is a generated file; do not edit or check into version control.\n'
276277
'plugin-a=/.tmp_rand0/plugin.rand0/\n'
277278
'plugin-b=/.tmp_rand0/plugin.rand1/\n'
278279
'plugin-c=/.tmp_rand0/plugin.rand2/\n'
279280
''
280281
);
281282
expect(flutterProject.flutterPluginsDependenciesFile.readAsStringSync(),
282283
'{'
284+
'"_info":"// This is a generated file; do not edit or check into version control.",'
283285
'"dependencyGraph":['
284286
'{'
285287
'"name":"plugin-a",'

0 commit comments

Comments
 (0)