     }
 
     // Gather all module aliases specified for targets in all dependent packages
-    let pkgToAliasesMap = gatherModuleAliases(for: rootManifests.first?.key, with: packagesByIdentity, onError: observabilityScope)
+    let packageAliases = gatherModuleAliases(from: packageBuilders, for: rootManifests.first?.key, with: packagesByIdentity, onError: observabilityScope)
 
     // Scan and validate the dependencies
     for packageBuilder in packageBuilders {

}

// Create a map between a package and module aliases specified for the targets in the package.
private func gatherModuleAliases(for rootPkgID: PackageIdentity?,
                                 with packagesByIdentity: [PackageIdentity: ResolvedPackageBuilder],
                                 onError observabilityScope: ObservabilityScope) -> [PackageIdentity: [String: String]] {
    var result = [PackageIdentity: [String: String]]()
    
    // There could be multiple root packages but the common cases involve

            metadata: package.diagnosticsMetadata
        )
        
        if let aliasMap = packageAliases?[package.identity] {
            package.setModuleAliasesForTargets(with: aliasMap)
        }

