Skip to content

Commit 902e4be

Browse files
[tool] Fix --current-package for app-facing packages (flutter#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.
1 parent f2ff19c commit 902e4be

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

script/tool/lib/src/common/package_command.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,15 @@ abstract class PackageCommand extends Command<void> {
595595
// ... and then check whether it has an enclosing package.
596596
final RepositoryPackage package = RepositoryPackage(currentDir);
597597
final RepositoryPackage? enclosingPackage = package.getEnclosingPackage();
598-
return (enclosingPackage ?? package).directory.basename;
598+
final RepositoryPackage rootPackage = enclosingPackage ?? package;
599+
final String name = rootPackage.directory.basename;
600+
// For an app-facing package in a federated plugin, return the fully
601+
// qualified name, since returning just the name will cause the entire
602+
// group to run.
603+
if (rootPackage.directory.parent.basename == name) {
604+
return '$name/$name';
605+
}
606+
return name;
599607
}
600608

601609
// Returns true if the current checkout is on an ancestor of [branch].

script/tool/test/common/package_command_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ packages/plugin1/plugin1/plugin1.dart
433433
expect(command.plugins, unorderedEquals(<String>[package.path]));
434434
});
435435

436+
test('runs only app-facing package of a federated plugin', () async {
437+
const String pluginName = 'foo';
438+
final Directory groupDir = packagesDir.childDirectory(pluginName);
439+
final RepositoryPackage package =
440+
createFakePlugin(pluginName, groupDir);
441+
createFakePlugin('${pluginName}_someplatform', groupDir);
442+
createFakePackage('${pluginName}_platform_interface', groupDir);
443+
fileSystem.currentDirectory = package.directory;
444+
445+
await runCapturingPrint(
446+
runner, <String>['sample', '--current-package']);
447+
448+
expect(command.plugins, unorderedEquals(<String>[package.path]));
449+
});
450+
436451
test('runs on a package when run from a package example directory',
437452
() async {
438453
final RepositoryPackage package = createFakePlugin(

0 commit comments

Comments
 (0)