Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Enrich Graph for Typescript with multiple projects and packages
  • Loading branch information
JohT committed Jul 31, 2024
commit c1726dbcfa2e64b7a544b34f3e9c7630e0495da6
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Adds a relation "RESOLVES_TO" from an external module to a module if their global fully qualified names match.
// Depends on "Add_module_properties.cypher" to be run first
// Inspired by https://github.com/jQAssistant/jqassistant/blob/4cd7face5d6d2953449d8e6ff5b484f00ffbdc2f/plugin/java/src/main/resources/META-INF/jqassistant-rules/java-classpath.xml#L5
// Related to https://github.com/jqassistant-plugin/jqassistant-typescript-plugin/issues/35

Expand All @@ -9,6 +10,7 @@ WHERE module.globalFqn IS NOT NULL
AND (module.globalFqn = externalModule.globalFqn
OR module.globalFqn = split(externalModule.globalFqn, '/index.')[0]
OR externalModule.globalFqn = split(module.globalFqn, '/index.')[0]
OR (externalModule.name = module.name AND externalModule.namespace = module.namespace)
)
AND module <> externalModule
CALL { WITH module, externalModule
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Set name property on Typescript project nodes

MATCH (project:TS:Project)-[:HAS_ROOT]->(root:Directory)
WITH project
,reverse(split(reverse(root.absoluteFileName), '/')[0]) AS projectName
SET project.name = projectName
RETURN count(*) AS numberOfNamesProjects
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Set name property on Typescript scan nodes

MATCH (typescriptScan:TS:Scan)
WITH typescriptScan
,replace(reverse(split(reverse(typescriptScan.fileName), '/')[0]), '.json', '') AS scanName
SET typescriptScan.name = scanName
RETURN count(*) AS numberOfNamesScans
32 changes: 32 additions & 0 deletions cypher/Typescript_Enrichment/Link_projects_to_npm_packages.cypher
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Link Typescript projects to npm packages

MATCH (npmPackage:NPM:Package)
WITH npmPackage
// Remove the first ("/npm-package-json/")" and the last part ("/package.json")
// of the file name to get the actual relative path to the directory
// that contains the package.json file
,replace(
replace(npmPackage.fileName, '/' + split(npmPackage.fileName, '/')[1], '')
, '/package.json'
, ''
) AS relativeNpmPackageDirectory
MATCH (project:TS:Project)-[:HAS_ROOT]->(projectRoot:Directory)
WHERE projectRoot.absoluteFileName ENDS WITH relativeNpmPackageDirectory
WITH npmPackage
,relativeNpmPackageDirectory
,collect(DISTINCT project) AS projects
,collect(DISTINCT projectRoot) AS projectRoots
// Assure that the found connection is unique and not ambiguous
WHERE size(projects) = 1
AND size(projectRoots) = 1
UNWIND projects AS project
// Create a HAS_NPM_PACKAGE relationship between the Typescript project and the npm package
MERGE (project)-[:HAS_NPM_PACKAGE]->(npmPackage)
// Set the "relativeFileDirectory" on the npm package to the relative directory
// that contains the package.json file
SET npmPackage.relativeFileDirectory = relativeNpmPackageDirectory
RETURN count(*) AS numberOfCreatedNpmPackageRelationships
// Detailed results for debugging
//RETURN npmPackage.fileName AS npmPackageFileName
// ,projectRoots[0].absoluteFileName AS projectRootDirectory
// ,relativeNpmPackageDirectory
7 changes: 7 additions & 0 deletions scripts/prepareAnalysis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ execute_cypher "${CYPHER_DIR}/Create_Typescript_index_for_name.cypher"
# Preparation - Enrich Graph for Typescript by adding "module" and "name" properties
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_module_properties.cypher"

# Preparation - Enrich Graph for Typescript by adding a name properties
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_projects.cypher"
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_scan_nodes.cypher"

# Preparation - Enrich Graph for Typescript by adding relationships between Modules with the same globalFqn
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_modules.cypher"
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_declarations.cypher"
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_DEPENDS_ON_relationship_to_resolved_modules.cypher"

# Preparation - Enrich Graph for Typescript by adding relationships between corresponding TS:Project and NPM:Package nodes
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Link_projects_to_npm_packages.cypher"

# Preparation - Add weights to Java Package DEPENDS_ON relationships
execute_cypher_summarized "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_for_Java_Interface_Dependencies_to_Package_DEPENDS_ON_Relationship.cypher"
execute_cypher_summarized "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_to_Java_Package_DEPENDS_ON_Relationship.cypher"
Expand Down