Skip to content

Commit f5e24f2

Browse files
authored
Merge pull request #462 from JohT/feature/ignore-private-package-json-typescript-projects
Skip TypeScript packages with a package.json marked as private.
2 parents 38f4c2e + 38e27b5 commit f5e24f2

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

scripts/scanTypescript.sh

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ if [ ! -d "./${SOURCE_DIRECTORY}" ] ; then
4444
fi
4545

4646
if ! command -v "npx" &> /dev/null ; then
47-
echo "scanTypescript Error: Command npx not found. It's needed to execute @jqassistant/ts-lce to scan Typescript projects." >&2
47+
echo "scanTypescript Error: Command npx not found. It's needed to execute @jqassistant/ts-lce to scan Typescript projects. Please install Node.js." >&2
4848
exit 1
4949
fi
5050

@@ -89,6 +89,13 @@ scan_directory() {
8989
fi
9090
}
9191

92+
# Returns 0 (success) if "private": true is set in package.json, otherwise 1 (false).
93+
# Pass the directory of the package.json file as first argument (default=.=current directory).
94+
is_private_package_json() {
95+
directory=${1:-.}
96+
node -e "process.exit(require(require('path').resolve('${directory}/package.json')).private ? 0 : 1)"
97+
}
98+
9299
# Takes one parameter containing the directory to scan for Typescript projects.
93100
# Returns true (=0) when the given directory contains a valid (existing and reasonable size) scan result file.
94101
# Otherwise returns false
@@ -156,14 +163,15 @@ for source_directory in ${source_directories}; do
156163
#echo "scanTypescript: Detected change (${changeDetectionReturnCode}) in ${source_directory}. Scanning Typescript source using @jqassistant/ts-lce."
157164

158165
if [ -f "${source_directory}/tsconfig.json" ] \
166+
&& ! is_private_package_json "${source_directory}" \
159167
&& scan_directory "${source_directory}" "${progress_info_source_dirs}" \
160168
&& is_valid_scan_result "${source_directory}"
161169
then
162170
write_change_detection_file
163171
continue # successfully scanned a standard Typescript project (with tsconfig.json file). proceed with next one.
164172
fi
165173

166-
echo "scanTypescript: Info: Unsuccessful or skipped source directory scan. Scan all contained packages individually." >&2
174+
echo "scanTypescript: Info: Skipped source directory scan. Scan all contained packages individually." >&2
167175
contained_package_directories=$( find_directories_with_package_json_file "${source_directory}" )
168176
#Debugging: List all package directories.
169177
#echo "scanTypescript: contained_package_directories:" >&2
@@ -176,7 +184,11 @@ for source_directory in ${source_directories}; do
176184
for contained_package_directory in ${contained_package_directories}; do
177185
processed_package_directories=$((processed_package_directories + 1))
178186
progress_info_package_dirs="${main_source_directory_name} ${progress_info_source_dirs}: ${processed_package_directories}/${total_package_directories}"
179-
scan_directory "${contained_package_directory}" "${progress_info_package_dirs}"
187+
if is_private_package_json "${contained_package_directory}"; then
188+
echo "scanTypescript: Info: Skipping private package ${contained_package_directory}. The contained package.json is marked as private so that it won't be published." >&2
189+
else
190+
scan_directory "${contained_package_directory}" "${progress_info_package_dirs}"
191+
fi
180192
done
181193

182194
write_change_detection_file

0 commit comments

Comments
 (0)