-
Notifications
You must be signed in to change notification settings - Fork 1
Analyze npm package dependencies #539
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ea6d2db
Analyze npm package dependencies
JohT d53826c
Add TypeScript module project info to longest path visualization
JohT 47fb79c
Avoid self-loops in CHANGED_TOGETHER_WITH edges
JohT d32fbe6
Add batch sizes to all transactional write operations for memory mana…
JohT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
cypher/Internal_Dependencies/NPM_Package_build_levels_for_graphviz.cypher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // List of all NPM packages and their dependencies with build levels for GraphViz Visualization | ||
|
|
||
| MATCH (sourceForStatistics:NPM:Package)-[dependencyForStatistics:DEPENDS_ON]->(targetForStatistics:NPM:Package) | ||
| WHERE sourceForStatistics.maxDistanceFromSource IS NOT NULL | ||
| AND targetForStatistics.maxDistanceFromSource IS NOT NULL | ||
| WITH min(dependencyForStatistics.weightByDependencyType) AS minWeight | ||
| ,max(dependencyForStatistics.weightByDependencyType) AS maxWeight | ||
| ,max(targetForStatistics.maxDistanceFromSource) AS maxLevel | ||
| MATCH (source:NPM:Package)-[dependency:DEPENDS_ON]->(target:NPM:Package) | ||
| WHERE source.maxDistanceFromSource IS NOT NULL | ||
| AND target.maxDistanceFromSource IS NOT NULL | ||
| WITH *, CASE | ||
| WHEN maxWeight = minWeight THEN 0.0 | ||
| ELSE toFloat(dependency.weightByDependencyType - minWeight) / toFloat(maxWeight - minWeight) | ||
| END AS normalizedWeight | ||
| WITH *, round((normalizedWeight * 5) + 1, 2) AS penWidth | ||
| WITH *, "\\n(level " + coalesce(source.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS sourceLevelInfo | ||
| WITH *, "\\n(level " + coalesce(target.maxDistanceFromSource + "/" + maxLevel, "?") + ")" AS targetLevelInfo | ||
| WITH *, source.name + sourceLevelInfo AS fullSourceName | ||
| WITH *, target.name + targetLevelInfo AS fullTargetName | ||
| WITH *, "\" -> \"" + fullTargetName | ||
| + "\" [label = " + dependency.weightByDependencyType + ";" | ||
| + " penwidth = " + penWidth + ";" | ||
| + " ];" AS graphVizDotNotationEdge | ||
| WITH *, "\"" + fullSourceName + coalesce(graphVizDotNotationEdge, "\" [];") AS graphVizDotNotationLine | ||
| ORDER BY dependency.weightByDependencyType DESC, target.maxDistanceFromSource DESC | ||
| RETURN graphVizDotNotationLine | ||
| //Debugging | ||
| //,source.name AS sourceName | ||
| //,target.name AS targetName | ||
| //,penWidth | ||
| //,normalizedWeight | ||
| //,dependency.weightByDependencyType AS weight | ||
| //,minWeight | ||
| //,maxWeight | ||
| LIMIT 440 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Example on how to set the parameters for path finding in this case for NPM Packages | ||
|
|
||
| :params { | ||
| "dependencies_projection_language":"NPM", | ||
| "dependencies_projection": "npm-package-path-finding", | ||
| "dependencies_projection_node": "Package", | ||
| "dependencies_projection_weight_property": "weightByDependencyType", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Example on how to set the parameters for path finding in this case for TypeScript modules | ||
|
|
||
| :params { | ||
| "dependencies_projection_language":"Typescript", | ||
| "dependencies_projection": "typescript-module-path-finding", | ||
| "dependencies_projection_node": "Module", | ||
| "dependencies_projection_weight_property": "lowCouplingElement25PercentWeight", | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| // Return the first node with a "maxDistanceFromSource" if it exists | ||
|
|
||
| MATCH (codeUnit) | ||
| WHERE codeUnit.maxDistanceFromSource IS NOT NULL | ||
| AND codeUnit.topologicalSortIndex IS NOT NULL | ||
| AND $dependencies_projection_node IN LABELS(codeUnit) | ||
| RETURN codeUnit.name AS shortCodeUnitName | ||
| ,elementId(codeUnit) AS nodeElementId | ||
| ,codeUnit.maxDistanceFromSource AS maxDistanceFromSource | ||
| LIMIT 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
cypher/Typescript_Enrichment/Enrich_npm_packages_with_dependency_counts.cypher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Enrich NPM:Package nodes with incoming and outgoing dependency counts | ||
| // Requires Link_npm_packages_with_depends_on_relationships.cypher | ||
|
|
||
| MATCH (package:NPM:Package) | ||
| WITH package, | ||
| // Private packages often contain test and example code. They will be left out of the main dependency graph analysis. | ||
| CASE WHEN package.private = true OR package.private = "true" THEN 1 ELSE 0 END AS testMarkerInteger, | ||
| COUNT {(package)<-[:DEPENDS_ON]-(:NPM:Package)} AS incomingDependencies, | ||
| COUNT {(package)-[:DEPENDS_ON]->(:NPM:Package)} AS outgoingDependencies | ||
| SET package.incomingDependencies = incomingDependencies, | ||
| package.outgoingDependencies = outgoingDependencies, | ||
| package.testMarkerInteger = testMarkerInteger | ||
| RETURN count(DISTINCT package) AS numberOfPackagesEnriched | ||
| ,sum(incomingDependencies) AS totalIncomingDependencies | ||
| ,sum(outgoingDependencies) AS totalOutgoingDependencies | ||
| ,avg(incomingDependencies) AS averageIncomingDependencies | ||
| ,avg(outgoingDependencies) AS averageOutgoingDependencies | ||
| // Debugging | ||
| // RETURN package.name, package.incomingDependencies, package.outgoingDependencies | ||
| // LIMIT 20 | ||
|
JohT marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
cypher/Typescript_Enrichment/Link_npm_dependencies_to_npm_packages.cypher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
cypher/Typescript_Enrichment/Link_npm_packages_with_depends_on_relationships.cypher
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // Link npm packages with DEPENDS_ON relationships. Requires Link_npm_dependencies_to_npm_packages. | ||
| // This creates direct package-to-package dependencies by following the chain: | ||
| // (source:NPM:Package)-[dependency_relationship]->(NPM:Dependency)-[:IS_DESCRIBED_IN_NPM_PACKAGE]->(target:NPM:Package) | ||
|
|
||
| MATCH (source:NPM:Package)-[dependency_relationship]->(npm_dependency:NPM:Dependency) | ||
| MATCH (npm_dependency)-[:IS_DESCRIBED_IN_NPM_PACKAGE]->(target:NPM:Package) | ||
| WHERE source <> target | ||
| AND source.name IS NOT NULL | ||
| AND target.name IS NOT NULL | ||
| WITH source | ||
| ,target | ||
| , | ||
| // Weight peer dependencies as 3, regular dependencies as 2, and dev dependencies as 1. | ||
| // The highest weight is used when multiple dependency types exist for the same package pair. | ||
| max(CASE | ||
| WHEN dependency_relationship:DECLARES_PEER_DEPENDENCY THEN 3 | ||
| WHEN dependency_relationship:DECLARES_DEPENDENCY THEN 2 | ||
| WHEN dependency_relationship:DECLARES_DEV_DEPENDENCY THEN 1 | ||
| ELSE 1 | ||
| END) AS weightByDependencyType | ||
| CALL { WITH source, target, weightByDependencyType | ||
| MERGE (source)-[dependsOnRelationship:DEPENDS_ON]->(target) | ||
| SET dependsOnRelationship.weightByDependencyType = weightByDependencyType | ||
| } IN TRANSACTIONS OF 1000 ROWS | ||
|
JohT marked this conversation as resolved.
|
||
| RETURN count(*) AS numberOfWrittenRelationships | ||
| ,count(DISTINCT source) AS numberOfDistinctSourcePackages | ||
| ,count(DISTINCT target) AS numberOfDistinctTargetPackages | ||
| // Debugging | ||
| // RETURN source.name, target.name, weightByDependencyType | ||
| // LIMIT 10 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.