Skip to content

Commit 093eeb0

Browse files
authored
Merge pull request #229 from JohT/fix/scan-large-typscript-code-bases
Support scanning large code bases
2 parents 6bc7585 + 171bea3 commit 093eeb0

File tree

5 files changed

+30
-15
lines changed

5 files changed

+30
-15
lines changed

cypher/Typescript_Enrichment/Link_projects_to_npm_packages.cypher

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ MATCH (npmPackage:NPM:Package)
1717
,collect(DISTINCT project) AS projects
1818
,collect(DISTINCT projectConfigDir) AS projectConfigDirs
1919
// Assure that the found connection is unique and not ambiguous
20-
WHERE size(projects) = 1
20+
WHERE size(projects) >= 1 // might appear more than once when there are multiple tsconfig files
2121
AND size(projectConfigDirs) = 1
2222
UNWIND projects AS project
2323
// Create a HAS_NPM_PACKAGE relationship between the Typescript project and the npm package
@@ -29,4 +29,4 @@ MATCH (npmPackage:NPM:Package)
2929
// Detailed results for debugging
3030
//RETURN npmPackage.fileName AS npmPackageFileName
3131
// ,projectConfigDirs[0].absoluteFileName AS projectConfigDirectory
32-
// ,relativeNpmPackageDirectory
32+
// ,relativeNpmPackageDirectory

scripts/copyPackageJsonFiles.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ if [ ! -d "${SOURCE_DIRECTORY}" ]; then
1919
return 0
2020
fi
2121

22+
# Returns all relevant package.json files for the source directory given as first and only parameter.
23+
find_package_json_files() {
24+
find -L "${1}" \
25+
-type d -name "node_modules" -prune -o \
26+
-type d -name "dist" -prune -o \
27+
-type d -name ".yalc" -prune -o \
28+
-type d -name "target" -prune -o \
29+
-type d -name "temp" -prune -o \
30+
-type d -name "lib" -prune -o \
31+
-type d -name "libs" -prune -o \
32+
-name 'package.json' \
33+
-print0 | \
34+
xargs -0 -r -I {} echo {}
35+
}
36+
2237
(
2338
cd "./${SOURCE_DIRECTORY}"
2439

@@ -27,8 +42,7 @@ fi
2742

2843
copied_package_json_files=0
2944

30-
#for file in $( find -L . -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {}); do
31-
for file in $( find -L . -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} echo {}); do
45+
for file in $( find_package_json_files . ); do
3246
fileDirectory=$(dirname "${file}")
3347
targetDirectory="../${ARTIFACTS_DIRECTORY}/${NPM_PACKAGE_JSON_ARTIFACTS_DIRECTORY}/${fileDirectory}"
3448
# echo "copyPackageJsonFiles: Debug: Copying ${file} to ${targetDirectory}" # debug logging

scripts/findPathsToScan.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ fi
4040

4141
if [ -d "./${SOURCE_DIRECTORY}" ] ; then
4242
# Scan Typescript analysis json data files in the source directory
43-
typescriptAnalysisFiles="$(find "./${SOURCE_DIRECTORY}" \
43+
typescriptAnalysisFiles="$(find -L "./${SOURCE_DIRECTORY}" \
4444
-type d -name "node_modules" -prune -o \
45+
-type d -name "dist" -prune -o \
4546
-type d -name "target" -prune -o \
4647
-type d -name "temp" -prune -o \
4748
-type f -path "*/.reports/jqa/ts-output.json" \
@@ -54,15 +55,16 @@ if [ -d "./${SOURCE_DIRECTORY}" ] ; then
5455
# Scan package.json files for npm (nodes package manager) in the source directory
5556
# # TODO The following lines can be reactivated when the following issue is resolved:
5657
# https://github.com/jqassistant-plugin/jqassistant-npm-plugin/issues/5
57-
#npmPackageJsonFiles="$(find "${SOURCE_DIRECTORY}" -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} | tr '\n' ',' | sed 's/,$/\n/')"
58+
#npmPackageJsonFiles="$(find -L "${SOURCE_DIRECTORY}" -type d -name node_modules -prune -o -name 'package.json' -print0 | xargs -0 -r -I {} | tr '\n' ',' | sed 's/,$/\n/')"
5859
#if [ -n "${npmPackageJsonFiles}" ]; then
5960
# directoriesAndFilesToScan="$(appendNonEmpty "${directoriesAndFilesToScan}")${npmPackageJsonFiles}"
6061
#fi
6162

6263
# Scan git repositories in the artifacts directory
6364
if [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "" ] || [ "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "plugin" ] ; then
64-
gitDirectories="$(find "./${SOURCE_DIRECTORY}" \
65+
gitDirectories="$(find -L "./${SOURCE_DIRECTORY}" \
6566
-type d -name "node_modules" -prune -o \
67+
-type d -name "dist" -prune -o \
6668
-type d -name "target" -prune -o \
6769
-type d -name "temp" -prune -o \
6870
-type d -name ".git" -exec echo {} \; | tr '\n' ',' | sed 's/,$/\n/')"

scripts/importGit.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ if [ ! "${IMPORT_GIT_LOG_DATA_IF_SOURCE_IS_PRESENT}" = "none" ] && [ ! "${IMPORT
175175

176176
existing_data_has_been_deleted=false
177177

178-
for repository in $(find "${source}" -type d -name ".git" -print0 | xargs -0 -r -I {} dirname {}); do
178+
for repository in $(find -L "${source}" -type d -name ".git" -print0 | xargs -0 -r -I {} dirname {}); do
179179
# Prepare import by cleaning existing data first
180180
if [ "${existing_data_has_been_deleted}" = false ] ; then
181181
deleteExistingGitData

scripts/scanTypescript.sh

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,24 @@ else
3737
echo "scanTypescript: Detected change (${changeDetectionReturnCode}). Scanning Typescript source using @jqassistant/ts-lce."
3838

3939
mkdir -p "./runtime/logs"
40+
LOG_DIRECTORY="$(pwd)/runtime/logs"
41+
echo "scanTypescript: LOG_DIRECTORY=${LOG_DIRECTORY}" >&2
4042

4143
source_directories=$( find -L "./${SOURCE_DIRECTORY}" -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r -I {} echo {} )
4244
total_directories=$(echo "${source_directories}" | wc -l | awk '{print $1}')
4345
processed_directories=0
4446

4547
for directory in ${source_directories}; do
4648
directory_name=$(basename "${directory}");
47-
# Note: The npx command will be executed in the source directory using a subshell by putting parentheses around it.
48-
# The subshell is the reason why it isn't needed to change back to the main directory after execution.
49+
processed_directories=$((processed_directories + 1))
50+
echo "" >&2
51+
echo "scanTypescript: $(date +'%Y-%m-%dT%H:%M:%S%z') Scanning ${directory_name} (${processed_directories}/${total_directories}) -----------------" >&2
4952
# Note: This script must not output anything except for the return code to stdout,
5053
# all output of the scanning needs to be redirected to stderr using ">&2".
5154
# For later troubleshooting, the output is also copied to a dedicated log file using "tee".
5255
# Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
5356
# Note: NODE_OPTIONS --max-old-space-size=4096 increases the memory for larger projects to scan
54-
( cd "${directory}" && NODE_OPTIONS="${NODE_OPTIONS} --max-old-space-size=4096" npx --yes @jqassistant/[email protected] --extension React 2>&1 | tee "./../../runtime/logs/jqassistant-typescript-scan-${directory_name}.log" >&2 || exit )
55-
processed_directories=$((processed_directories + 1))
56-
echo "" >&2
57-
echo "scanTypescript: Scanned ${directory_name} (${processed_directories}/${total_directories}) ----------------------" >&2
58-
echo "" >&2
57+
NODE_OPTIONS="${NODE_OPTIONS} --max-old-space-size=4096" npx --yes @jqassistant/[email protected] "${directory}" --extension React 2>&1 | tee "${LOG_DIRECTORY}/jqassistant-typescript-scan-${directory_name}.log" >&2
5958
done
6059

6160
changeDetectionReturnCode=$( source "${SCRIPTS_DIR}/detectChangedFiles.sh" --hashfile "${changeDetectionHashFilePath}" --paths "./${SOURCE_DIRECTORY}")

0 commit comments

Comments
 (0)