@snyk/dep-graph
Advanced tools
Comparing version 1.6.1 to 1.7.0
@@ -13,2 +13,3 @@ import * as types from '../core/types'; | ||
}; | ||
pruned?: boolean; | ||
} | ||
@@ -24,2 +25,5 @@ interface DepTree extends DepTreeDep { | ||
declare function depTreeToGraph(depTree: DepTree, pkgManagerName: string): Promise<types.DepGraph>; | ||
declare function graphToDepTree(depGraphInterface: types.DepGraph, pkgType: string): Promise<DepTree>; | ||
export interface GraphToTreeOptions { | ||
deduplicateWithinTopLevelDeps: boolean; | ||
} | ||
declare function graphToDepTree(depGraphInterface: types.DepGraph, pkgType: string, opts?: GraphToTreeOptions): Promise<DepTree>; |
@@ -192,3 +192,4 @@ "use strict"; | ||
} | ||
function graphToDepTree(depGraphInterface, pkgType) { | ||
function graphToDepTree(depGraphInterface, pkgType, opts) { | ||
if (opts === void 0) { opts = { deduplicateWithinTopLevelDeps: false }; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
@@ -205,3 +206,3 @@ var depGraph, eventLoopSpinner, depTree, targetOS; | ||
eventLoopSpinner = new event_loop_spinner_1.EventLoopSpinner(); | ||
return [4 /*yield*/, buildSubtree(depGraph, depGraph.rootNodeId, eventLoopSpinner)]; | ||
return [4 /*yield*/, buildSubtree(depGraph, depGraph.rootNodeId, eventLoopSpinner, opts.deduplicateWithinTopLevelDeps ? null : false)]; | ||
case 1: | ||
@@ -240,8 +241,10 @@ depTree = _a.sent(); | ||
} | ||
function buildSubtree(depGraph, nodeId, eventLoopSpinner) { | ||
function buildSubtree(depGraph, nodeId, eventLoopSpinner, maybeDeduplicationSet) { | ||
if (maybeDeduplicationSet === void 0) { maybeDeduplicationSet = null; } | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var nodePkg, nodeInfo, depTree, depInstanceIds, _i, depInstanceIds_1, depInstId, subtree; | ||
var isRoot, nodePkg, nodeInfo, depTree, depInstanceIds, _i, depInstanceIds_1, depInstId, subtree; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
isRoot = nodeId === depGraph.rootNodeId; | ||
nodePkg = depGraph.getNodePkg(nodeId); | ||
@@ -262,2 +265,11 @@ nodeInfo = depGraph.getNode(nodeId); | ||
} | ||
if (maybeDeduplicationSet) { | ||
if (maybeDeduplicationSet.has(nodeId)) { | ||
if (depInstanceIds.length > 0) { | ||
depTree.pruned = true; | ||
} | ||
return [2 /*return*/, depTree]; | ||
} | ||
maybeDeduplicationSet.add(nodeId); | ||
} | ||
_i = 0, depInstanceIds_1 = depInstanceIds; | ||
@@ -268,3 +280,8 @@ _a.label = 1; | ||
depInstId = depInstanceIds_1[_i]; | ||
return [4 /*yield*/, buildSubtree(depGraph, depInstId, eventLoopSpinner)]; | ||
// Deduplication of nodes occurs only within a scope of a top-level dependency. | ||
// Therefore, every top-level dep gets an independent set to track duplicates. | ||
if (isRoot && maybeDeduplicationSet !== false) { | ||
maybeDeduplicationSet = new Set(); | ||
} | ||
return [4 /*yield*/, buildSubtree(depGraph, depInstId, eventLoopSpinner, maybeDeduplicationSet)]; | ||
case 2: | ||
@@ -271,0 +288,0 @@ subtree = _a.sent(); |
@@ -50,3 +50,3 @@ { | ||
}, | ||
"version": "1.6.1" | ||
"version": "1.7.0" | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
64426
908