Add dev_dependency
attribute to plugins in .flutter-plugins-dependencies
(#158009)
Adds whether or not the plugins in `.flutter-plugins-dependencies` are dev dependencies or not (as the `dev_dependency` attribute). Fixes https://github.com/flutter/flutter/issues/157948.
This commit is contained in:
parent
752ac20f87
commit
46a41585eb
@ -143,6 +143,7 @@ const String _kFlutterPluginsPathKey = 'path';
|
|||||||
const String _kFlutterPluginsDependenciesKey = 'dependencies';
|
const String _kFlutterPluginsDependenciesKey = 'dependencies';
|
||||||
const String _kFlutterPluginsHasNativeBuildKey = 'native_build';
|
const String _kFlutterPluginsHasNativeBuildKey = 'native_build';
|
||||||
const String _kFlutterPluginsSharedDarwinSource = 'shared_darwin_source';
|
const String _kFlutterPluginsSharedDarwinSource = 'shared_darwin_source';
|
||||||
|
const String _kFlutterPluginsDevDependencyKey = 'dev_dependency';
|
||||||
|
|
||||||
/// Writes the .flutter-plugins-dependencies file based on the list of plugins.
|
/// Writes the .flutter-plugins-dependencies file based on the list of plugins.
|
||||||
/// If there aren't any plugins, then the files aren't written to disk. The resulting
|
/// If there aren't any plugins, then the files aren't written to disk. The resulting
|
||||||
@ -270,6 +271,7 @@ List<Map<String, Object>> _createPluginMapOfPlatform(
|
|||||||
if (platformPlugin is NativeOrDartPlugin)
|
if (platformPlugin is NativeOrDartPlugin)
|
||||||
_kFlutterPluginsHasNativeBuildKey: (platformPlugin as NativeOrDartPlugin).hasMethodChannel() || (platformPlugin as NativeOrDartPlugin).hasFfi(),
|
_kFlutterPluginsHasNativeBuildKey: (platformPlugin as NativeOrDartPlugin).hasMethodChannel() || (platformPlugin as NativeOrDartPlugin).hasFfi(),
|
||||||
_kFlutterPluginsDependenciesKey: <String>[...plugin.dependencies.where(pluginNames.contains)],
|
_kFlutterPluginsDependenciesKey: <String>[...plugin.dependencies.where(pluginNames.contains)],
|
||||||
|
_kFlutterPluginsDevDependencyKey: plugin.isDevDependency,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return pluginInfo;
|
return pluginInfo;
|
||||||
|
@ -508,6 +508,7 @@ dependencies:
|
|||||||
'plugin-b',
|
'plugin-b',
|
||||||
'plugin-c',
|
'plugin-c',
|
||||||
],
|
],
|
||||||
|
'dev_dependency': false,
|
||||||
},
|
},
|
||||||
<String, dynamic> {
|
<String, dynamic> {
|
||||||
'name': 'plugin-b',
|
'name': 'plugin-b',
|
||||||
@ -516,12 +517,14 @@ dependencies:
|
|||||||
'dependencies': <String>[
|
'dependencies': <String>[
|
||||||
'plugin-c',
|
'plugin-c',
|
||||||
],
|
],
|
||||||
|
'dev_dependency': false,
|
||||||
},
|
},
|
||||||
<String, dynamic> {
|
<String, dynamic> {
|
||||||
'name': 'plugin-c',
|
'name': 'plugin-c',
|
||||||
'path': '${pluginC.path}/',
|
'path': '${pluginC.path}/',
|
||||||
'native_build': true,
|
'native_build': true,
|
||||||
'dependencies': <String>[],
|
'dependencies': <String>[],
|
||||||
|
'dev_dependency': false,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
expect(plugins['ios'], expectedPlugins);
|
expect(plugins['ios'], expectedPlugins);
|
||||||
@ -614,7 +617,8 @@ dependencies:
|
|||||||
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
||||||
'shared_darwin_source': true,
|
'shared_darwin_source': true,
|
||||||
'native_build': true,
|
'native_build': true,
|
||||||
'dependencies': <String>[]
|
'dependencies': <String>[],
|
||||||
|
'dev_dependency': false,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'android': <Map<String, Object>>[
|
'android': <Map<String, Object>>[
|
||||||
@ -622,7 +626,8 @@ dependencies:
|
|||||||
'name': 'plugin-a',
|
'name': 'plugin-a',
|
||||||
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
||||||
'native_build': true,
|
'native_build': true,
|
||||||
'dependencies': <String>[]
|
'dependencies': <String>[],
|
||||||
|
'dev_dependency': false,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'macos': <Map<String, Object>>[],
|
'macos': <Map<String, Object>>[],
|
||||||
@ -632,14 +637,16 @@ dependencies:
|
|||||||
'name': 'plugin-a',
|
'name': 'plugin-a',
|
||||||
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
||||||
'native_build': false,
|
'native_build': false,
|
||||||
'dependencies': <String>[]
|
'dependencies': <String>[],
|
||||||
|
'dev_dependency': false,
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
'web': <Map<String, Object>>[
|
'web': <Map<String, Object>>[
|
||||||
<String, Object>{
|
<String, Object>{
|
||||||
'name': 'plugin-a',
|
'name': 'plugin-a',
|
||||||
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
'path': '/.tmp_rand0/flutter_plugin.rand0/',
|
||||||
'dependencies': <String>[]
|
'dependencies': <String>[],
|
||||||
|
'dev_dependency': false,
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1,140 @@
|
|||||||
|
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
import 'dart:convert';
|
||||||
|
import 'package:file/file.dart';
|
||||||
|
|
||||||
|
import '../src/common.dart';
|
||||||
|
import 'test_utils.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late Directory tempProjectDir;
|
||||||
|
late Directory tempPluginADir;
|
||||||
|
late Directory tempPluginBDir;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
tempProjectDir = createResolvedTempDirectorySync(
|
||||||
|
'flutter_plugins_dependencies_test_project.');
|
||||||
|
tempPluginADir = createResolvedTempDirectorySync(
|
||||||
|
'flutter_plugins_dependencies_test_plugin_a.');
|
||||||
|
tempPluginBDir = createResolvedTempDirectorySync(
|
||||||
|
'flutter_plugins_dependencies_test_plugin_b.');
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() {
|
||||||
|
tryToDelete(tempProjectDir);
|
||||||
|
});
|
||||||
|
|
||||||
|
test(
|
||||||
|
'.flutter-plugins-dependencies correctly denotes project dev dependencies on all default platforms',
|
||||||
|
() async {
|
||||||
|
// Create Flutter project.
|
||||||
|
final String flutterBin =
|
||||||
|
fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
|
||||||
|
|
||||||
|
await processManager.run(<String>[
|
||||||
|
flutterBin,
|
||||||
|
'create',
|
||||||
|
tempProjectDir.path,
|
||||||
|
'--project-name=testapp',
|
||||||
|
], workingDirectory: tempProjectDir.path);
|
||||||
|
|
||||||
|
final File pubspecFile = tempProjectDir.childFile('pubspec.yaml');
|
||||||
|
expect(pubspecFile.existsSync(), true);
|
||||||
|
|
||||||
|
// Create Flutter plugins to add as dependencies to Flutter project.
|
||||||
|
final String pluginAPath = '${tempPluginADir.path}/plugin_a_real_dependency';
|
||||||
|
final String pluginBPath = '${tempPluginBDir.path}/plugin_b_dev_dependency';
|
||||||
|
|
||||||
|
await processManager.run(<String>[
|
||||||
|
flutterBin,
|
||||||
|
'create',
|
||||||
|
pluginAPath,
|
||||||
|
'--template=plugin',
|
||||||
|
'--project-name=plugin_a_real_dependency',
|
||||||
|
], workingDirectory: tempPluginADir.path);
|
||||||
|
|
||||||
|
await processManager.run(<String>[
|
||||||
|
flutterBin,
|
||||||
|
'create',
|
||||||
|
pluginBPath,
|
||||||
|
'--template=plugin',
|
||||||
|
'--project-name=plugin_b_dev_dependency',
|
||||||
|
], workingDirectory: tempPluginBDir.path);
|
||||||
|
|
||||||
|
// Add dependency on two plugin: one dependency, one dev dependency.
|
||||||
|
await processManager.run(<String>[
|
||||||
|
flutterBin,
|
||||||
|
'pub',
|
||||||
|
'add',
|
||||||
|
'plugin_a_real_dependency',
|
||||||
|
'--path',
|
||||||
|
pluginAPath,
|
||||||
|
], workingDirectory: tempProjectDir.path);
|
||||||
|
|
||||||
|
await processManager.run(<String>[
|
||||||
|
flutterBin,
|
||||||
|
'pub',
|
||||||
|
'add',
|
||||||
|
'dev:plugin_b_dev_dependency',
|
||||||
|
'--path',
|
||||||
|
pluginBPath,
|
||||||
|
], workingDirectory: tempProjectDir.path);
|
||||||
|
|
||||||
|
// Run `flutter pub get` to generate .flutter-plugins-dependencies.
|
||||||
|
await processManager.run(<String>[
|
||||||
|
flutterBin,
|
||||||
|
'--no-implicit-pubspec-resolution',
|
||||||
|
'pub',
|
||||||
|
'get',
|
||||||
|
], workingDirectory: tempProjectDir.path);
|
||||||
|
|
||||||
|
final File flutterPluginsDependenciesFile =
|
||||||
|
tempProjectDir.childFile('.flutter-plugins-dependencies');
|
||||||
|
expect(flutterPluginsDependenciesFile.existsSync(), true);
|
||||||
|
|
||||||
|
// Check that .flutter-plugin-dependencies denotes the dependency and
|
||||||
|
// dev dependency as expected.
|
||||||
|
final String pluginsString =
|
||||||
|
flutterPluginsDependenciesFile.readAsStringSync();
|
||||||
|
final Map<String, dynamic> jsonContent =
|
||||||
|
json.decode(pluginsString) as Map<String, dynamic>;
|
||||||
|
final Map<String, dynamic> plugins =
|
||||||
|
jsonContent['plugins'] as Map<String, dynamic>;
|
||||||
|
|
||||||
|
// Loop through all platforms supported by default to verify that the
|
||||||
|
// dependency and dev dependency are handled appropriately.
|
||||||
|
final List<String> platformsToVerify = <String>[
|
||||||
|
'ios',
|
||||||
|
'android',
|
||||||
|
'windows',
|
||||||
|
'linux',
|
||||||
|
'macos',
|
||||||
|
'web',
|
||||||
|
];
|
||||||
|
|
||||||
|
for (final String platform in platformsToVerify) {
|
||||||
|
final List<dynamic> pluginsForPlatform =
|
||||||
|
plugins[platform] as List<dynamic>;
|
||||||
|
|
||||||
|
for (final dynamic plugin in pluginsForPlatform) {
|
||||||
|
final Map<String, dynamic> pluginProperties =
|
||||||
|
plugin as Map<String, dynamic>;
|
||||||
|
final String pluginName = pluginProperties['name'] as String;
|
||||||
|
final bool pluginIsDevDependency =
|
||||||
|
pluginProperties['dev_dependency'] as bool;
|
||||||
|
|
||||||
|
// Check camera dependencies are not marked as dev dependencies.
|
||||||
|
if (pluginName.startsWith('plugin_a_real_dependency')) {
|
||||||
|
expect(pluginIsDevDependency, isFalse);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check video_player dependencies are marked as dev dependencies.
|
||||||
|
if (pluginName.startsWith('plugin_b_dev_dependency')) {
|
||||||
|
expect(pluginIsDevDependency, isTrue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user