@@ -79,7 +79,7 @@ scan_directory() {
7979 # Note: For later troubleshooting, the output is also copied to a dedicated log file using "tee".
8080 # Note: Don't worry about the hardcoded version number. It will be updated by Renovate using a custom Manager.
8181 # Note: NODE_OPTIONS --max-old-space-size=4096 increases the memory for scanning larger projects
82- NODE_OPTIONS=
" ${NODE_OPTIONS} --max-old-space-size=${TYPESCRIPT_SCAN_HEAP_MEMORY} " npx --yes @jqassistant/
[email protected] .
1 " ${1} " --extension React
2>&1 | tee
" ${LOG_DIRECTORY} /jqassistant-typescript-scan-${directory_name } .log" >&2 82+ NODE_OPTIONS=
" ${NODE_OPTIONS} --max-old-space-size=${TYPESCRIPT_SCAN_HEAP_MEMORY} " npx --yes @jqassistant/
[email protected] .
0 " ${1} " --extension React
2>&1 | tee
" ${LOG_DIRECTORY} /jqassistant-typescript-scan-${source_directory_name } .log" >&2 8383 else
8484 echo " scanTypescript: Skipping scan of ${source_directory_name} (${progress_information} ) -----------------" >&2
8585 fi
@@ -110,48 +110,62 @@ is_valid_scan_result() {
110110 fi
111111}
112112
113- # Scan and analyze Artifacts when they were changed
114- changeDetectionHashFilePath=" ./${SOURCE_DIRECTORY} /typescriptFileChangeDetectionHashFile.txt"
115- changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --readonly --hashfile " ${changeDetectionHashFilePath} " --paths " ./${SOURCE_DIRECTORY} " )
113+ is_change_detected () {
114+ # Scan and analyze Typescript sources only when they had been changed
115+ local source_directory_name; source_directory_name=$( basename " ${source_directory} " ) ;
116+ changeDetectionHashFilePath=" ./${SOURCE_DIRECTORY} /typescriptScanChangeDetection-${source_directory_name} .sha"
117+ changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --readonly --hashfile " ${changeDetectionHashFilePath} " --paths " ${source_directory} " )
116118
117- if [ " ${changeDetectionReturnCode} " == " 0" ] && [ " ${TYPESCRIPT_SCAN_CHANGE_DETECTION} " = true ]; then
118- echo " scanTypescript: Files unchanged. Scan skipped."
119- fi
120-
121- if [ " ${changeDetectionReturnCode} " != " 0" ] || [ " ${TYPESCRIPT_SCAN_CHANGE_DETECTION} " = false ]; then
122- echo " scanTypescript: Detected change (${changeDetectionReturnCode} ). Scanning Typescript source using @jqassistant/ts-lce."
123-
124- mkdir -p " ./runtime/logs"
125- LOG_DIRECTORY=" $( pwd) /runtime/logs"
126- echo " scanTypescript: LOG_DIRECTORY=${LOG_DIRECTORY} " >&2
127-
128- source_directories=$( find -L " ./${SOURCE_DIRECTORY} " -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r -I {} echo {} )
129- total_source_directories=$( echo " ${source_directories} " | wc -l | awk ' {print $1}' )
130- processed_source_directories=0
131-
132- for source_directory in ${source_directories} ; do
133- processed_source_directories=$(( processed_source_directories + 1 ))
134- progress_info_source_dirs=" ${processed_source_directories} /${total_source_directories} "
135- if scan_directory " ${source_directory} " " ${progress_info_source_dirs} " && is_valid_scan_result " ${source_directory} " ; then
136- continue # successful scan, proceed to next one.
137- fi
138-
139- echo " scanTypescript: Info: Unsuccessful source directory scan. Trying to scan all contained packages individually." >&2
140- contained_package_directories=$( find_directories_with_package_json_file " ${source_directory} " )
141- echo " scanTypescript: contained_package_directories:" >&2
142- echo " ${contained_package_directories} " >&2
143- total_package_directories=$( echo " ${contained_package_directories} " | wc -l | awk ' {print $1}' )
144- processed_package_directories=0
145-
146- for contained_package_directory in ${contained_package_directories} ; do
147- processed_package_directories=$(( processed_package_directories + 1 ))
148- progress_info_package_dirs=" ${progress_info_source_dirs} : ${processed_package_directories} /${total_package_directories} "
149- scan_directory " ${contained_package_directory} " " ${progress_info_package_dirs} "
150- done
151- done
119+ if [ " ${changeDetectionReturnCode} " == " 0" ] && [ " ${TYPESCRIPT_SCAN_CHANGE_DETECTION} " = true ]; then
120+ true
121+ else
122+ false
123+ fi
124+ }
152125
126+ write_change_detection_file () {
153127 # The dry-run shouldn't write anything. Therefore, writing the change detection file is skipped regardless of TYPESCRIPT_SCAN_CHANGE_DETECTION.
154128 if [ " ${TYPESCRIPT_SCAN_DRY_RUN} " = false ] ; then
155- changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --hashfile " ${changeDetectionHashFilePath} " --paths " ./${SOURCE_DIRECTORY} " )
129+ changeDetectionReturnCode=$( source " ${SCRIPTS_DIR} /detectChangedFiles.sh" --hashfile " ${changeDetectionHashFilePath} " --paths " ${source_directory} " )
130+ fi
131+ }
132+
133+ mkdir -p " ./runtime/logs"
134+ LOG_DIRECTORY=" $( pwd) /runtime/logs"
135+ echo " scanTypescript: LOG_DIRECTORY=${LOG_DIRECTORY} " >&2
136+
137+ source_directories=$( find -L " ./${SOURCE_DIRECTORY} " -mindepth 1 -maxdepth 1 -type d -print0 | xargs -0 -r -I {} echo {} )
138+ total_source_directories=$( echo " ${source_directories} " | wc -l | awk ' {print $1}' )
139+ processed_source_directories=0
140+
141+ for source_directory in ${source_directories} ; do
142+ if is_change_detected; then
143+ echo " scanTypescript: Files in ${source_directory} unchanged. Scan skipped."
144+ continue # skipping scan since it had already be done according to change detection.
156145 fi
157- fi
146+
147+ # Debugging log for change detection. "scan_directory" already logs scanning and the source directory.
148+ # echo "scanTypescript: Detected change (${changeDetectionReturnCode}) in ${source_directory}. Scanning Typescript source using @jqassistant/ts-lce."
149+
150+ processed_source_directories=$(( processed_source_directories + 1 ))
151+ progress_info_source_dirs=" ${processed_source_directories} /${total_source_directories} "
152+ if scan_directory " ${source_directory} " " ${progress_info_source_dirs} " && is_valid_scan_result " ${source_directory} " ; then
153+ write_change_detection_file
154+ continue # successful scan, proceed to next one.
155+ fi
156+
157+ echo " scanTypescript: Info: Unsuccessful or skipped source directory scan. Scan all contained packages individually." >&2
158+ contained_package_directories=$( find_directories_with_package_json_file " ${source_directory} " )
159+ echo " scanTypescript: contained_package_directories:" >&2
160+ echo " ${contained_package_directories} " >&2
161+ total_package_directories=$( echo " ${contained_package_directories} " | wc -l | awk ' {print $1}' )
162+ processed_package_directories=0
163+
164+ for contained_package_directory in ${contained_package_directories} ; do
165+ processed_package_directories=$(( processed_package_directories + 1 ))
166+ progress_info_package_dirs=" ${progress_info_source_dirs} : ${processed_package_directories} /${total_package_directories} "
167+ scan_directory " ${contained_package_directory} " " ${progress_info_package_dirs} "
168+ done
169+
170+ write_change_detection_file
171+ done
0 commit comments