Skip to content

Commit ac55540

Browse files
committed
NO-ISSUE --audit-level moderate
1 parent 718a4bd commit ac55540

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

scripts/npm-audit.sh

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,28 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4-
errors=0
4+
IFS=$'\n'
5+
locks=($(find . -path '*/node_modules' -prune -o -name package-lock.json -print))
6+
unset IFS
57

6-
find . -name package-lock.json -not -path "./node_modules/*" -print0 |
7-
xargs -0 -n1 dirname | sort -u |
8-
while IFS= read -r dir; do
9-
printf '\n\n\n'
10-
printf '\033[1;34m==> %s\033[0m\n' "$dir"
11-
(cd "$dir" && npm audit) || errors=1
12-
done
8+
declare -a failed=()
139

14-
if [ "$errors" -eq 0 ]; then
15-
echo "npm audit passed: no vulnerabilities detected"
10+
for lock in "${locks[@]}"; do
11+
dir=$(dirname "$lock")
12+
printf '\n\n\033[1;34m==> %s\033[0m\n' "$dir"
13+
14+
pushd "$dir" >/dev/null
15+
if ! npm audit --audit-level moderate; then
16+
failed+=("$dir")
17+
fi
18+
popd >/dev/null
19+
done
20+
21+
if ((${#failed[@]})); then
22+
echo -e "\n\033[0;31mnpm audit reported vulnerabilities in:\033[0m"
23+
printf ' - %s\n' "${failed[@]}"
24+
exit 1
1625
else
17-
echo "npm audit reported vulnerabilities. Fix all vulnerabilities before committing."
26+
echo "npm audit passed: no vulnerabilities detected"
27+
exit 0
1828
fi
19-
20-
exit "$errors"

0 commit comments

Comments
 (0)