[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:
stuartmorgan
2023-07-07 15:04:13 -04:00
committed by GitHub
parent f2ff19c745
commit 902e4bef4c
2 changed files with 24 additions and 1 deletions

View File

@ -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].

View File

@ -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(