From 8cfb61655b8055cda0bf46d058072a58d9b53fab Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Fri, 7 Jul 2023 11:02:01 -0400 Subject: [PATCH] [tool] Fix --current-package for app-facing packages 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. --- script/tool/lib/src/common/package_command.dart | 10 +++++++++- script/tool/test/common/package_command_test.dart | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/script/tool/lib/src/common/package_command.dart b/script/tool/lib/src/common/package_command.dart index 00a38e7045a1..b9587ac2909e 100644 --- a/script/tool/lib/src/common/package_command.dart +++ b/script/tool/lib/src/common/package_command.dart @@ -595,7 +595,15 @@ abstract class PackageCommand extends Command { // ... 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]. diff --git a/script/tool/test/common/package_command_test.dart b/script/tool/test/common/package_command_test.dart index 2ef9b9e8438e..e907829f594a 100644 --- a/script/tool/test/common/package_command_test.dart +++ b/script/tool/test/common/package_command_test.dart @@ -433,6 +433,21 @@ packages/plugin1/plugin1/plugin1.dart expect(command.plugins, unorderedEquals([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, ['sample', '--current-package']); + + expect(command.plugins, unorderedEquals([package.path])); + }); + test('runs on a package when run from a package example directory', () async { final RepositoryPackage package = createFakePlugin(