mirror of
https://github.com/flutter/packages.git
synced 2025-07-01 07:08:10 +08:00
[tool] Fix --current-package for app-facing packages (#4399)
The new `--current-package` flag was returning `foo` when run in the app-facing package of a federated plugin called `foo`, but `foo` as a package argument is treated as being the entire group, so it was running all for all of the packages in the plugin. This fixes it to return `foo/foo` in that case, which is how the tool targets app-facing packages specifically.
This commit is contained in:
@ -595,7 +595,15 @@ abstract class PackageCommand extends Command<void> {
|
||||
// ... and then check whether it has an enclosing package.
|
||||
final RepositoryPackage package = RepositoryPackage(currentDir);
|
||||
final RepositoryPackage? enclosingPackage = package.getEnclosingPackage();
|
||||
return (enclosingPackage ?? package).directory.basename;
|
||||
final RepositoryPackage rootPackage = enclosingPackage ?? package;
|
||||
final String name = rootPackage.directory.basename;
|
||||
// For an app-facing package in a federated plugin, return the fully
|
||||
// qualified name, since returning just the name will cause the entire
|
||||
// group to run.
|
||||
if (rootPackage.directory.parent.basename == name) {
|
||||
return '$name/$name';
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
// Returns true if the current checkout is on an ancestor of [branch].
|
||||
|
@ -433,6 +433,21 @@ packages/plugin1/plugin1/plugin1.dart
|
||||
expect(command.plugins, unorderedEquals(<String>[package.path]));
|
||||
});
|
||||
|
||||
test('runs only app-facing package of a federated plugin', () async {
|
||||
const String pluginName = 'foo';
|
||||
final Directory groupDir = packagesDir.childDirectory(pluginName);
|
||||
final RepositoryPackage package =
|
||||
createFakePlugin(pluginName, groupDir);
|
||||
createFakePlugin('${pluginName}_someplatform', groupDir);
|
||||
createFakePackage('${pluginName}_platform_interface', groupDir);
|
||||
fileSystem.currentDirectory = package.directory;
|
||||
|
||||
await runCapturingPrint(
|
||||
runner, <String>['sample', '--current-package']);
|
||||
|
||||
expect(command.plugins, unorderedEquals(<String>[package.path]));
|
||||
});
|
||||
|
||||
test('runs on a package when run from a package example directory',
|
||||
() async {
|
||||
final RepositoryPackage package = createFakePlugin(
|
||||
|
Reference in New Issue
Block a user