snyk / nodejs-lockfile-parser

Generate a Snyk dependency tree from package-lock.json or yarn.lock file
Other
57 stars 28 forks source link

Feat/use dfs to detect cycle and build graph #150

Closed xzhou-snyk closed 1 year ago

xzhou-snyk commented 1 year ago

This PR uses DFS to traverse all package nodes and detect cyclic dependencies.

The reason for the improvement is, the ancestorMap in the original solution could be expensive as it will copy ancestorMap entries a lot of times. Also there is actually standard solution for detecting cycles using DFS.

This PR also did some refactoring and grouped some reused functions together :)