Skip to content

Commit

Permalink
fix: correctly prune within top level deps only
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesPatrickGill committed May 15, 2023
1 parent 6d70e90 commit e8af954
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
8 changes: 4 additions & 4 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ function buildGraph(
const depPackagesLen = depPackages.length;

for (let i = depPackagesLen - 1; i >= 0; i--) {
visited = visited || new Set<string>();
const localVisited = visited || new Set<string>();
const packageImport = depPackages[i];
let version = 'unknown';
if (isBuiltinPackage(packageImport)) {
Expand Down Expand Up @@ -639,7 +639,7 @@ function buildGraph(
continue;
}

if (visited.has(packageImport)) {
if (localVisited.has(packageImport)) {
const prunedId = `${packageImport}:pruned`;
depGraphBuilder.addPkgNode(newNode, prunedId, {
labels: { pruned: 'true' },
Expand All @@ -650,7 +650,7 @@ function buildGraph(

depGraphBuilder.addPkgNode(newNode, packageImport);
depGraphBuilder.connectDep(currentParent, packageImport);
visited.add(packageImport);
localVisited.add(packageImport);

childrenChain.set(currentParent, [...currentChildren, packageImport]);
ancestorsChain.set(packageImport, [...currentAncestors, currentParent]);
Expand All @@ -664,7 +664,7 @@ function buildGraph(
packageImport,
childrenChain,
ancestorsChain,
visited,
localVisited,
);
}
}
Expand Down
20 changes: 8 additions & 12 deletions test/fixtures/gomod-small/expected-gomodules-depgraph.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"nodeId": "github.com/rivo/tview"
},
{
"nodeId": "github.com/gdamore/tcell:pruned"
"nodeId": "github.com/gdamore/tcell"
},
{
"nodeId": "github.com/antlr/antlr4/runtime/Go/antlr"
Expand Down Expand Up @@ -186,6 +186,12 @@
},
{
"nodeId": "github.com/gdamore/encoding"
},
{
"nodeId": "github.com/mattn/go-runewidth"
},
{
"nodeId": "github.com/lucasb-eyer/go-colorful"
}
]
},
Expand Down Expand Up @@ -268,16 +274,6 @@
}
}
},
{
"nodeId": "github.com/gdamore/tcell:pruned",
"pkgId": "github.com/gdamore/[email protected]",
"deps": [],
"info": {
"labels": {
"pruned": "true"
}
}
},
{
"nodeId": "github.com/antlr/antlr4/runtime/Go/antlr",
"pkgId": "github.com/antlr/antlr4/runtime/Go/antlr@#edae2a1c9b4b",
Expand All @@ -288,7 +284,7 @@
"pkgId": "golang.org/x/text/[email protected]",
"deps": [
{
"nodeId": "golang.org/x/text/transform:pruned"
"nodeId": "golang.org/x/text/transform"
}
]
}
Expand Down

0 comments on commit e8af954

Please sign in to comment.