Skip to content

[tool] Fix --current-package for app-facing packages #4399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion script/tool/lib/src/common/package_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't you just always return rootPackage.directory.parent.basename/name instead of having this extra logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because for, e.g., pigeon that would be packages/pigeon which doesn't work.

(I could always do it for federated plugins, but that ends up being about the same amount of logic.)

return '$name/$name';
}
return name;
}

// Returns true if the current checkout is on an ancestor of [branch].
Expand Down
15 changes: 15 additions & 0 deletions script/tool/test/common/package_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down