File tree Expand file tree Collapse file tree 1 file changed +21
-13
lines changed Expand file tree Collapse file tree 1 file changed +21
-13
lines changed Original file line number Diff line number Diff line change 11#! /usr/bin/env bash
22set -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
1625else
17- echo " npm audit reported vulnerabilities. Fix all vulnerabilities before committing."
26+ echo " npm audit passed: no vulnerabilities detected"
27+ exit 0
1828fi
19-
20- exit " $errors "
You can’t perform that action at this time.
0 commit comments