diff --git a/packages/melos/lib/src/package.dart b/packages/melos/lib/src/package.dart index 6c972dc07..b95bda0af 100644 --- a/packages/melos/lib/src/package.dart +++ b/packages/melos/lib/src/package.dart @@ -755,17 +755,17 @@ class Package { }; /// The dependencies listed in `dependencies:` inside the package's - /// `pubspec.yaml` that are part of the melos workspace + /// `pubspec.yaml` that are part of the melos workspace. late final Map dependenciesInWorkspace = _packagesInWorkspaceForNames(dependencies); /// The dependencies listed in `dev_dependencies:` inside the package's - /// `pubspec.yaml` that are part of the melos workspace + /// `pubspec.yaml` that are part of the melos workspace. late final Map devDependenciesInWorkspace = _packagesInWorkspaceForNames(devDependencies); /// The dependencies listed in `dependency_overrides:` inside the package's - /// `pubspec.yaml` that are part of the melos workspace + /// `pubspec.yaml` that are part of the melos workspace. late final Map dependencyOverridesInWorkspace = _packagesInWorkspaceForNames(dependencyOverrides); @@ -776,7 +776,7 @@ class Package { entry.key: entry.value, }; - /// The packages that depend on this package as a dev dependency.. + /// The packages that depend on this package as a dev dependency. late final Map devDependentsInWorkspace = { for (final entry in _packageMap.entries) if (entry.value.devDependenciesInWorkspace.containsKey(name)) @@ -793,13 +793,15 @@ class Package { late final Map allTransitiveDependenciesInWorkspace = _transitivelyRelatedPackages( root: this, - directlyRelatedPackages: (package) => package.allDependenciesInWorkspace, + directlyRelatedPackages: (package, isRoot) => isRoot + ? package.allDependenciesInWorkspace + : package.dependenciesInWorkspace, ); late final Map allTransitiveDependentsInWorkspace = _transitivelyRelatedPackages( root: this, - directlyRelatedPackages: (package) => package.allDependentsInWorkspace, + directlyRelatedPackages: (package, _) => package.allDependentsInWorkspace, ); Map _packagesInWorkspaceForNames(List names) { @@ -1103,10 +1105,11 @@ class Package { /// related to it. Map _transitivelyRelatedPackages({ required Package root, - required Map Function(Package) directlyRelatedPackages, + required Map Function(Package, bool isRoot) + directlyRelatedPackages, }) { final result = {}; - final workingSet = directlyRelatedPackages(root).values.toList(); + final workingSet = directlyRelatedPackages(root, true).values.toList(); while (workingSet.isNotEmpty) { final current = workingSet.removeLast(); @@ -1120,7 +1123,7 @@ Map _transitivelyRelatedPackages({ // Since `current` is a package that was not in the result, we are // seeing it for the first time and still need to traverse its related // packages. - workingSet.insertAll(0, directlyRelatedPackages(current).values); + workingSet.insertAll(0, directlyRelatedPackages(current, false).values); return current; }); diff --git a/packages/melos/test/package_test.dart b/packages/melos/test/package_test.dart index 65f794f87..93190061d 100644 --- a/packages/melos/test/package_test.dart +++ b/packages/melos/test/package_test.dart @@ -77,6 +77,30 @@ void main() { ); }); + group('Package', () { + group('allTransitiveDependenciesInWorkspace', () { + test('does not included transitive dev dependencies', () { + final workspaceBuilder = VirtualWorkspaceBuilder('name: test'); + workspaceBuilder.addPackage(''' + name: a + '''); + workspaceBuilder.addPackage(''' + name: b + dev_dependencies: + a: any + '''); + workspaceBuilder.addPackage(''' + name: c + dependencies: + b: any + '''); + final workspace = workspaceBuilder.build(); + final cPackage = workspace.allPackages['c']!; + expect(cPackage.allTransitiveDependenciesInWorkspace.keys, ['b']); + }); + }); + }); + group('PackageFilter', () { test('default', () { final filter = PackageFilter();