Skip to content

Commit d65c31d

Browse files
committed
Improve and verify linking Typescript projects to npm packages
1 parent 360e0f2 commit d65c31d

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

cypher/Typescript_Enrichment/Link_projects_to_npm_packages.cypher

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ MATCH (npmPackage:NPM:Package)
1010
, '/package.json'
1111
, ''
1212
) AS relativeNpmPackageDirectory
13-
MATCH (project:TS:Project)-[:HAS_ROOT]->(projectRoot:Directory)
14-
WHERE projectRoot.absoluteFileName ENDS WITH relativeNpmPackageDirectory
13+
MATCH (project:TS:Project)-[:HAS_CONFIG]->(config:File)<-[:CONTAINS]-(projectConfigDir:Directory)
14+
WHERE projectConfigDir.absoluteFileName ENDS WITH relativeNpmPackageDirectory
1515
WITH npmPackage
1616
,relativeNpmPackageDirectory
1717
,collect(DISTINCT project) AS projects
18-
,collect(DISTINCT projectRoot) AS projectRoots
18+
,collect(DISTINCT projectConfigDir) AS projectConfigDirs
1919
// Assure that the found connection is unique and not ambiguous
20-
WHERE size(projects) = 1
21-
AND size(projectRoots) = 1
20+
WHERE size(projects) = 1
21+
AND size(projectConfigDirs) = 1
2222
UNWIND projects AS project
2323
// Create a HAS_NPM_PACKAGE relationship between the Typescript project and the npm package
2424
MERGE (project)-[:HAS_NPM_PACKAGE]->(npmPackage)
@@ -28,5 +28,5 @@ MATCH (npmPackage:NPM:Package)
2828
RETURN count(*) AS numberOfCreatedNpmPackageRelationships
2929
// Detailed results for debugging
3030
//RETURN npmPackage.fileName AS npmPackageFileName
31-
// ,projectRoots[0].absoluteFileName AS projectRootDirectory
31+
// ,projectConfigDirs[0].absoluteFileName AS projectRootDirectory
3232
// ,relativeNpmPackageDirectory
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Verify that all Typescript projects are linked to npm packages
2+
3+
MATCH (p:TS:Project)
4+
WITH COUNT { (p)-[:HAS_NPM_PACKAGE]->(:NPM:Package) } AS npmLinkedProjectsCount
5+
,count(*) AS totalProjectsCount
6+
RETURN *
7+
,(totalProjectsCount - npmLinkedProjectsCount) AS unresolvedProjectsCount
8+
,(100.0 / totalProjectsCount * npmLinkedProjectsCount) AS npmLinkedProjectsPercentage

scripts/prepareAnalysis.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
88
set -o errexit -o pipefail
99

10+
# Overrideable Defaults
1011
IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT=${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT:-"full"} # Select how to import git log data. Options: "none", "aggregated", "full". Default="full".
1112

1213
## Get this "scripts" directory if not already set
@@ -40,10 +41,14 @@ ARTIFACT_DEPENDENCIES_CYPHER_DIR="$CYPHER_DIR/Artifact_Dependencies"
4041
TYPES_CYPHER_DIR="$CYPHER_DIR/Types"
4142
TYPESCRIPT_CYPHER_DIR="$CYPHER_DIR/Typescript_Enrichment"
4243

44+
COLOR_RED='\033[0;31m'
45+
COLOR_DEFAULT='\033[0m'
46+
4347
# Preparation - Data verification: DEPENDS_ON relationships
4448
dataVerificationResult=$( execute_cypher "${CYPHER_DIR}/Data_verification_DEPENDS_ON_relationships.cypher" "${@}")
4549
if ! is_csv_column_greater_zero "${dataVerificationResult}" "sourceNodeCount"; then
46-
echo "prepareAnalysis: Error: Data verification failed. At least one DEPENDS_ON relationship required. Check if the artifacts directory is empty or if the scan failed."
50+
echo -e "${COLOR_RED}prepareAnalysis: Error: Data verification failed. At least one DEPENDS_ON relationship is required. Check if the artifacts directory is empty or if the scan failed.${COLOR_DEFAULT}"
51+
echo -e "${COLOR_RED}${dataVerificationResult}${COLOR_DEFAULT}"
4752
exit 1
4853
fi
4954

@@ -71,6 +76,13 @@ execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Remove_duplicate_CONTAINS_relations_bet
7176

7277
# Preparation - Enrich Graph for Typescript by adding relationships between corresponding TS:Project and NPM:Package nodes
7378
execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Link_projects_to_npm_packages.cypher"
79+
dataVerificationResult=$( execute_cypher "${TYPESCRIPT_CYPHER_DIR}/Verify_projects_linked_to_npm_packages.cypher" "${@}")
80+
if is_csv_column_greater_zero "${dataVerificationResult}" "unresolvedProjectsCount"; then
81+
# There are Typescript projects and the unresolvedProjectsCount is greater than zero
82+
echo -e "${COLOR_RED}prepareAnalysis: Error: Data verification failed. There are Typescript projects without a linked npm package:${COLOR_DEFAULT}"
83+
echo -e "${COLOR_RED}${dataVerificationResult}${COLOR_DEFAULT}"
84+
exit 1
85+
fi
7486

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

0 commit comments

Comments
 (0)