Skip to content

[tool] Support third_party for --current-package #7967

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
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
22 changes: 15 additions & 7 deletions script/tool/lib/src/common/package_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -662,22 +662,30 @@ abstract class PackageCommand extends Command<void> {
}

String? _getCurrentDirectoryPackageName() {
// Ensure that the current directory is within the packages directory.
final Directory absolutePackagesDir = packagesDir.absolute;
final Set<Directory> absolutePackagesDirs = <Directory>{
packagesDir.absolute,
thirdPartyPackagesDir.absolute,
};
bool isATopLevelPackagesDir(Directory directory) =>
absolutePackagesDirs.any((Directory d) => d.path == directory.path);

Directory currentDir = packagesDir.fileSystem.currentDirectory.absolute;
if (!currentDir.path.startsWith(absolutePackagesDir.path) ||
currentDir.path == packagesDir.path) {
// Ensure that the current directory is within one of the top-level packages
// directories.
if (isATopLevelPackagesDir(currentDir) ||
!absolutePackagesDirs
.any((Directory d) => currentDir.path.startsWith(d.path))) {
return null;
}
// If the current directory is a direct subdirectory of the packages
// If the current directory is a direct subdirectory of a packages
// directory, then that's the target.
if (currentDir.parent.path == absolutePackagesDir.path) {
if (isATopLevelPackagesDir(currentDir.parent)) {
return currentDir.basename;
}
// Otherwise, walk up until a package is found...
while (!isPackage(currentDir)) {
currentDir = currentDir.parent;
if (currentDir.path == absolutePackagesDir.path) {
if (isATopLevelPackagesDir(currentDir)) {
return null;
}
}
Expand Down
13 changes: 13 additions & 0 deletions script/tool/test/common/package_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,19 @@ packages/plugin1/plugin1/plugin1.dart
expect(command.plugins, unorderedEquals(<String>[package.path]));
});

test('runs on a package when run from the third_party/packages directory',
() async {
final RepositoryPackage package =
createFakePlugin('a_package', thirdPartyPackagesDir);
createFakePlugin('another_package', thirdPartyPackagesDir);
fileSystem.currentDirectory = package.directory;

await runCapturingPrint(
runner, <String>['sample', '--current-package']);

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);
Expand Down