Skip to content

Commit c1726db

Browse files
committed
Enrich Graph for Typescript with multiple projects and packages
1 parent 6d9e999 commit c1726db

File tree

5 files changed

+55
-0
lines changed

5 files changed

+55
-0
lines changed

cypher/Typescript_Enrichment/Add_RESOLVES_TO_relationship_for_matching_modules.cypher

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Adds a relation "RESOLVES_TO" from an external module to a module if their global fully qualified names match.
2+
// Depends on "Add_module_properties.cypher" to be run first
23
// Inspired by https://github.com/jQAssistant/jqassistant/blob/4cd7face5d6d2953449d8e6ff5b484f00ffbdc2f/plugin/java/src/main/resources/META-INF/jqassistant-rules/java-classpath.xml#L5
34
// Related to https://github.com/jqassistant-plugin/jqassistant-typescript-plugin/issues/35
45

@@ -9,6 +10,7 @@ WHERE module.globalFqn IS NOT NULL
910
AND (module.globalFqn = externalModule.globalFqn
1011
OR module.globalFqn = split(externalModule.globalFqn, '/index.')[0]
1112
OR externalModule.globalFqn = split(module.globalFqn, '/index.')[0]
13+
OR (externalModule.name = module.name AND externalModule.namespace = module.namespace)
1214
)
1315
AND module <> externalModule
1416
CALL { WITH module, externalModule
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Set name property on Typescript project nodes
2+
3+
MATCH (project:TS:Project)-[:HAS_ROOT]->(root:Directory)
4+
WITH project
5+
,reverse(split(reverse(root.absoluteFileName), '/')[0]) AS projectName
6+
SET project.name = projectName
7+
RETURN count(*) AS numberOfNamesProjects
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Set name property on Typescript scan nodes
2+
3+
MATCH (typescriptScan:TS:Scan)
4+
WITH typescriptScan
5+
,replace(reverse(split(reverse(typescriptScan.fileName), '/')[0]), '.json', '') AS scanName
6+
SET typescriptScan.name = scanName
7+
RETURN count(*) AS numberOfNamesScans
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Link Typescript projects to npm packages
2+
3+
MATCH (npmPackage:NPM:Package)
4+
WITH npmPackage
5+
// Remove the first ("/npm-package-json/")" and the last part ("/package.json")
6+
// of the file name to get the actual relative path to the directory
7+
// that contains the package.json file
8+
,replace(
9+
replace(npmPackage.fileName, '/' + split(npmPackage.fileName, '/')[1], '')
10+
, '/package.json'
11+
, ''
12+
) AS relativeNpmPackageDirectory
13+
MATCH (project:TS:Project)-[:HAS_ROOT]->(projectRoot:Directory)
14+
WHERE projectRoot.absoluteFileName ENDS WITH relativeNpmPackageDirectory
15+
WITH npmPackage
16+
,relativeNpmPackageDirectory
17+
,collect(DISTINCT project) AS projects
18+
,collect(DISTINCT projectRoot) AS projectRoots
19+
// Assure that the found connection is unique and not ambiguous
20+
WHERE size(projects) = 1
21+
AND size(projectRoots) = 1
22+
UNWIND projects AS project
23+
// Create a HAS_NPM_PACKAGE relationship between the Typescript project and the npm package
24+
MERGE (project)-[:HAS_NPM_PACKAGE]->(npmPackage)
25+
// Set the "relativeFileDirectory" on the npm package to the relative directory
26+
// that contains the package.json file
27+
SET npmPackage.relativeFileDirectory = relativeNpmPackageDirectory
28+
RETURN count(*) AS numberOfCreatedNpmPackageRelationships
29+
// Detailed results for debugging
30+
//RETURN npmPackage.fileName AS npmPackageFileName
31+
// ,projectRoots[0].absoluteFileName AS projectRootDirectory
32+
// ,relativeNpmPackageDirectory

scripts/prepareAnalysis.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,18 @@ execute_cypher "${CYPHER_DIR}/Create_Typescript_index_for_name.cypher"
5555
# Preparation - Enrich Graph for Typescript by adding "module" and "name" properties
5656
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_module_properties.cypher"
5757

58+
# Preparation - Enrich Graph for Typescript by adding a name properties
59+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_projects.cypher"
60+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_name_to_property_on_scan_nodes.cypher"
61+
5862
# Preparation - Enrich Graph for Typescript by adding relationships between Modules with the same globalFqn
5963
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_modules.cypher"
6064
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_RESOLVES_TO_relationship_for_matching_declarations.cypher"
6165
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Add_DEPENDS_ON_relationship_to_resolved_modules.cypher"
6266

67+
# Preparation - Enrich Graph for Typescript by adding relationships between corresponding TS:Project and NPM:Package nodes
68+
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Link_projects_to_npm_packages.cypher"
69+
6370
# Preparation - Add weights to Java Package DEPENDS_ON relationships
6471
execute_cypher_summarized "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_for_Java_Interface_Dependencies_to_Package_DEPENDS_ON_Relationship.cypher"
6572
execute_cypher_summarized "${DEPENDS_ON_CYPHER_DIR}/Add_weight_property_to_Java_Package_DEPENDS_ON_Relationship.cypher"

0 commit comments

Comments
 (0)