Skip to content

Commit 531792c

Browse files
author
AztecBot
committed
Merge branch 'next' into merge-train/avm
2 parents b176e77 + f9db009 commit 531792c

File tree

1 file changed

+67
-37
lines changed

1 file changed

+67
-37
lines changed

yarn-project/bootstrap.sh

Lines changed: 67 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,53 +28,83 @@ function get_projects {
2828

2929
function format {
3030
local arg="-w"
31-
local package=""
32-
local pattern="./*/src"
33-
34-
# Check if first arg is a format option
35-
if [ "${1:-}" == "--check" ]; then
36-
arg="--check"
37-
shift 1
38-
elif [ "${1:-}" == "-w" ] || [ "${1:-}" == "--write" ]; then
39-
arg="-w"
40-
shift 1
41-
fi
31+
local packages=()
32+
33+
# Parse all arguments
34+
while [ $# -gt 0 ]; do
35+
case "$1" in
36+
--check)
37+
arg="--check"
38+
;;
39+
-w|--write)
40+
arg="-w"
41+
;;
42+
-*)
43+
echo "Unknown flag: $1" >&2
44+
return 1
45+
;;
46+
*)
47+
packages+=("$1")
48+
;;
49+
esac
50+
shift
51+
done
4252

43-
# Check if next arg is a package name (doesn't start with -)
44-
if [ -n "${1:-}" ] && [[ ! "$1" =~ ^- ]]; then
45-
package="$1"
46-
pattern="./$package/src"
53+
# Build the paths array to search
54+
local paths=()
55+
if [ ${#packages[@]} -eq 0 ]; then
56+
paths=("./*/src")
57+
else
58+
for pkg in "${packages[@]}"; do
59+
if [ ! -d "./$pkg/src" ]; then
60+
echo "Error: Package '$pkg' not found or has no src directory" >&2
61+
return 1
62+
fi
63+
paths+=("./$pkg/src")
64+
done
4765
fi
4866

49-
find $pattern -type f -regex '.*\.\(json\|js\|mjs\|cjs\|ts\)$' 2>/dev/null | \
67+
find "${paths[@]}" -type f -regex '.*\.\(json\|js\|mjs\|cjs\|ts\)$' | \
5068
parallel -N30 ./node_modules/.bin/prettier --log-level warn "$arg"
5169
}
5270

5371
function lint {
5472
local arg="--fix"
55-
local package=""
56-
57-
# Check if first arg is a lint option
58-
if [ "${1-}" == "--check" ]; then
59-
arg=""
60-
shift 1
61-
elif [ "${1-}" == "--fix" ]; then
62-
arg="--fix"
63-
shift 1
64-
fi
65-
66-
# Check if next arg is a package name (and not empty)
67-
if [ -n "${1:-}" ] && [[ ! "$1" =~ ^- ]]; then
68-
package="$1"
69-
shift 1
70-
fi
73+
local packages=()
74+
75+
# Parse all arguments
76+
while [ $# -gt 0 ]; do
77+
case "$1" in
78+
--check)
79+
arg=""
80+
;;
81+
--fix)
82+
arg="--fix"
83+
;;
84+
-*)
85+
echo "Unknown flag: $1" >&2
86+
return 1
87+
;;
88+
*)
89+
packages+=("$1")
90+
;;
91+
esac
92+
shift
93+
done
7194

72-
if [ -n "$package" ]; then
73-
# Lint single package
74-
cd "$package" && ../node_modules/.bin/eslint "$@" --cache $arg ./src
95+
if [ ${#packages[@]} -gt 0 ]; then
96+
# Validate packages exist
97+
for pkg in "${packages[@]}"; do
98+
if [ ! -d "./$pkg/src" ]; then
99+
echo "Error: Package '$pkg' not found or has no src directory" >&2
100+
return 1
101+
fi
102+
done
103+
# Lint specified packages in parallel (use at most half of CPU cores)
104+
printf '%s\n' "${packages[@]}" | parallel -j 50% "cd {} && ../node_modules/.bin/eslint --cache $arg ./src"
75105
else
76-
# Lint all packages
77-
get_projects | parallel "cd {} && ../node_modules/.bin/eslint $@ --cache $arg ./src"
106+
# Lint all packages in parallel (use at most half of CPU cores)
107+
get_projects | parallel -j 50% "cd {} && ../node_modules/.bin/eslint --cache $arg ./src"
78108
fi
79109
}
80110

0 commit comments

Comments
 (0)