mergePackageRootsForDirs function
Merges the package roots resolved from each given package directory's
.dart_tool/package_config.json into a single name→root map.
This is what lets one packages.sum bundle cover the union of several
dependency closures — e.g. an editor's deps and a UI package whose widgets
a code-typed field references — without the editor having to depend on that
package directly (the bundle is loaded at runtime, never compiled against).
On a name collision the later directory wins; within one workspace these are
path deps resolving to the same root, so collisions are benign.
Throws SummaryConfigException if any directory lacks a resolved config.
Implementation
Map<String, String> mergePackageRootsForDirs(Iterable<String> packageDirs) {
final merged = <String, String>{};
for (final dir in packageDirs) {
final configFile =
io.File(p.join(dir, '.dart_tool', 'package_config.json'));
if (!configFile.existsSync()) {
throw SummaryConfigException(
'${configFile.path} not found — run `flutter pub get` / '
'`dart pub get` in $dir first.');
}
merged.addAll(readPackageRoots(configFile));
}
return merged;
}