@snyk/dep-graph
Advanced tools
Comparing version 1.26.0 to 1.27.0
@@ -7,2 +7,4 @@ "use strict"; | ||
const objectHash = require("object-hash"); | ||
const cycles_1 = require("./cycles"); | ||
const memiozation_1 = require("./memiozation"); | ||
function addLabel(dep, key, value) { | ||
@@ -144,7 +146,3 @@ if (!dep.labels) { | ||
const depGraph = depGraphInterface; | ||
// TODO: implement cycles support | ||
if (depGraph.hasCycles()) { | ||
throw new Error('Conversion to DepTree does not support cyclic graphs yet'); | ||
} | ||
const depTree = await buildSubtree(depGraph, depGraph.rootNodeId, opts.deduplicateWithinTopLevelDeps ? null : false); | ||
const [depTree] = await buildSubtree(depGraph, depGraph.rootNodeId, opts.deduplicateWithinTopLevelDeps ? null : false); | ||
depTree.type = depGraph.pkgManager.name; | ||
@@ -180,5 +178,8 @@ depTree.packageFormatVersion = constructPackageFormatVersion(pkgType); | ||
async function buildSubtree(depGraph, nodeId, maybeDeduplicationSet = false, // false = disabled; null = not in deduplication scope yet | ||
memoizationMap = new Map()) { | ||
if (!maybeDeduplicationSet && memoizationMap.has(nodeId)) { | ||
return memoizationMap.get(nodeId); | ||
ancestors = [], memoizationMap = new Map()) { | ||
if (!maybeDeduplicationSet) { | ||
const memoizedDepTree = memiozation_1.getMemoizedDepTree(nodeId, ancestors, memoizationMap); | ||
if (memoizedDepTree) { | ||
return [memoizedDepTree, undefined]; | ||
} | ||
} | ||
@@ -199,5 +200,11 @@ const isRoot = nodeId === depGraph.rootNodeId; | ||
if (!depInstanceIds || depInstanceIds.length === 0) { | ||
memoizationMap.set(nodeId, depTree); | ||
return depTree; | ||
memoizationMap.set(nodeId, { depTree }); | ||
return [depTree, undefined]; | ||
} | ||
const cycle = cycles_1.getCycle(ancestors, nodeId); | ||
if (cycle) { | ||
// This node starts a cycle and now it's the second visit. | ||
addLabel(depTree, 'pruned', 'cyclic'); | ||
return [depTree, [cycle]]; | ||
} | ||
if (maybeDeduplicationSet) { | ||
@@ -208,6 +215,7 @@ if (maybeDeduplicationSet.has(nodeId)) { | ||
} | ||
return depTree; | ||
return [depTree, undefined]; | ||
} | ||
maybeDeduplicationSet.add(nodeId); | ||
} | ||
const cycles = []; | ||
for (const depInstId of depInstanceIds) { | ||
@@ -219,3 +227,8 @@ // Deduplication of nodes occurs only within a scope of a top-level dependency. | ||
} | ||
const subtree = await buildSubtree(depGraph, depInstId, maybeDeduplicationSet, memoizationMap); | ||
const [subtree, subtreeCycles] = await buildSubtree(depGraph, depInstId, maybeDeduplicationSet, ancestors.concat(nodeId), memoizationMap); | ||
if (subtreeCycles) { | ||
for (const cycle of subtreeCycles) { | ||
cycles.push(cycle); | ||
} | ||
} | ||
if (!subtree) { | ||
@@ -232,4 +245,5 @@ continue; | ||
} | ||
memoizationMap.set(nodeId, depTree); | ||
return depTree; | ||
const partitionedCycles = cycles_1.partitionCycles(nodeId, cycles); | ||
memiozation_1.memoize(nodeId, memoizationMap, depTree, partitionedCycles); | ||
return [depTree, partitionedCycles.cyclesWithThisNode]; | ||
} | ||
@@ -236,0 +250,0 @@ function trimAfterLastSep(str, sep) { |
@@ -71,3 +71,3 @@ { | ||
}, | ||
"version": "1.26.0" | ||
"version": "1.27.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
110596
57
1667