Add a note to generated plugins files (#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.
This commit is contained in:
committed by
GitHub
parent
4cc10a1fb8
commit
901eb0fc81
@@ -317,7 +317,8 @@ List<Plugin> findPlugins(FlutterProject project) {
|
||||
/// otherwise returns [false].
|
||||
bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
|
||||
final List<dynamic> directAppDependencies = <dynamic>[];
|
||||
final StringBuffer flutterPluginsBuffer = StringBuffer();
|
||||
const String info = 'This is a generated file; do not edit or check into version control.';
|
||||
final StringBuffer flutterPluginsBuffer = StringBuffer('# $info\n');
|
||||
|
||||
final Set<String> pluginNames = <String>{};
|
||||
for (Plugin plugin in plugins) {
|
||||
@@ -334,7 +335,7 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
|
||||
final File pluginsFile = project.flutterPluginsFile;
|
||||
final String oldPluginFileContent = _readFileContent(pluginsFile);
|
||||
final String pluginFileContent = flutterPluginsBuffer.toString();
|
||||
if (pluginFileContent.isNotEmpty) {
|
||||
if (pluginNames.isNotEmpty) {
|
||||
pluginsFile.writeAsStringSync(pluginFileContent, flush: true);
|
||||
} else {
|
||||
if (pluginsFile.existsSync()) {
|
||||
@@ -345,9 +346,10 @@ bool _writeFlutterPluginsList(FlutterProject project, List<Plugin> plugins) {
|
||||
final File dependenciesFile = project.flutterPluginsDependenciesFile;
|
||||
final String oldDependenciesFileContent = _readFileContent(dependenciesFile);
|
||||
final String dependenciesFileContent = json.encode(<String, dynamic>{
|
||||
'_info': '// $info',
|
||||
'dependencyGraph': directAppDependencies,
|
||||
});
|
||||
if (pluginFileContent.isNotEmpty) {
|
||||
if (pluginNames.isNotEmpty) {
|
||||
dependenciesFile.writeAsStringSync(dependenciesFileContent, flush: true);
|
||||
} else {
|
||||
if (dependenciesFile.existsSync()) {
|
||||
|
||||
@@ -273,6 +273,7 @@ dependencies:
|
||||
expect(flutterProject.flutterPluginsFile.existsSync(), true);
|
||||
expect(flutterProject.flutterPluginsDependenciesFile.existsSync(), true);
|
||||
expect(flutterProject.flutterPluginsFile.readAsStringSync(),
|
||||
'# This is a generated file; do not edit or check into version control.\n'
|
||||
'plugin-a=/.tmp_rand0/plugin.rand0/\n'
|
||||
'plugin-b=/.tmp_rand0/plugin.rand1/\n'
|
||||
'plugin-c=/.tmp_rand0/plugin.rand2/\n'
|
||||
@@ -280,6 +281,7 @@ dependencies:
|
||||
);
|
||||
expect(flutterProject.flutterPluginsDependenciesFile.readAsStringSync(),
|
||||
'{'
|
||||
'"_info":"// This is a generated file; do not edit or check into version control.",'
|
||||
'"dependencyGraph":['
|
||||
'{'
|
||||
'"name":"plugin-a",'
|
||||
|
||||
Reference in New Issue
Block a user