Skip to content

Commit

Permalink
dapp: remappings: use shortest path when deduplicating
Browse files Browse the repository at this point in the history
  • Loading branch information
d-xo committed Sep 8, 2021
1 parent c01b0b5 commit e42da31
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/dapp/libexec/dapp/dapp-remappings
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ function deduplicate(pkg) {
// walk tree and build a mapping from hash => path
function mapHashes(pkg) {
const go = (mapping, dep) => {
mapping[dep.hash] = dep.path
// we collect the shortest path (aka closest to the root) for each dep
if (mapping[dep.hash] == undefined || dep.path.length < mapping[dep.hash].length) {
mapping[dep.hash] = dep.path
}

return dep.deps.reduce(go, mapping)
}
return pkg.deps.reduce(go, { [pkg.hash]: pkg.path })
Expand Down

0 comments on commit e42da31

Please sign in to comment.