From e42da31638e8626d0d719eed8b20b79d49245f41 Mon Sep 17 00:00:00 2001 From: David Terry Date: Wed, 8 Sep 2021 18:06:53 +0200 Subject: [PATCH] dapp: remappings: use shortest path when deduplicating --- src/dapp/libexec/dapp/dapp-remappings | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/dapp/libexec/dapp/dapp-remappings b/src/dapp/libexec/dapp/dapp-remappings index 0a1ea5a46..f1b16d390 100755 --- a/src/dapp/libexec/dapp/dapp-remappings +++ b/src/dapp/libexec/dapp/dapp-remappings @@ -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 })