Skip to content

Commit 82ac773

Browse files
committed
refactor(gitversion): ♻️ 🛠️ use git workspaces command
1 parent 6acab47 commit 82ac773

2 files changed

Lines changed: 2 additions & 89 deletions

File tree

src/gitversion/_bump-changelog.sh

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,39 +92,6 @@ list_changelog_range() {
9292
fi
9393
}
9494

95-
# ===== WORKSPACE MANAGEMENT FUNCTIONS =====
96-
97-
# Get workspace directories from package.json workspaces configuration
98-
# Returns list of workspace directories, falls back to all subdirectories if no workspaces config
99-
get_workspace_dirs() {
100-
if [ -f "package.json" ] && command -v jq > /dev/null 2>&1; then
101-
# Try to get workspaces array from package.json
102-
local workspaces=$(jq -r '.workspaces[]? // empty' package.json 2> /dev/null)
103-
104-
if [ -n "$workspaces" ]; then
105-
# Use configured workspaces
106-
echo "$workspaces" | while read -r workspace_pattern; do
107-
# Handle glob patterns by expanding them
108-
if echo "$workspace_pattern" | grep -q '\*'; then
109-
# Use find to expand glob patterns like "packages/*"
110-
find . -path "./$workspace_pattern" -type d -mindepth 1 -maxdepth 2 2> /dev/null || true
111-
else
112-
# Direct path
113-
if [ -d "$workspace_pattern" ]; then
114-
echo "$workspace_pattern"
115-
fi
116-
fi
117-
done
118-
else
119-
# Fallback to all subdirectories
120-
find . -type d -mindepth 1 -maxdepth 1
121-
fi
122-
else
123-
# Fallback to all subdirectories when package.json or jq not available
124-
find . -type d -mindepth 1 -maxdepth 1
125-
fi
126-
}
127-
12895

12996
# ===== CHANGELOG GENERATION FUNCTIONS =====
13097

src/gitversion/_bump-version.sh

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -21,60 +21,6 @@ help
2121
# Change to repository root to ensure we're working from the correct directory
2222
cd "$(git rev-parse --show-toplevel)" > /dev/null
2323

24-
# ===== WORKSPACE MANAGEMENT FUNCTIONS =====
25-
26-
# Get workspace directories from package.json workspaces configuration
27-
# Returns list of workspace directories, falls back to all subdirectories if no workspaces config
28-
get_workspace_dirs() {
29-
if [ -f "package.json" ] && command -v jq > /dev/null 2>&1; then
30-
# Try to get workspaces array from package.json
31-
local workspaces=$(jq -r '.workspaces[]? // empty' package.json 2> /dev/null)
32-
33-
if [ -n "$workspaces" ]; then
34-
# Use configured workspaces
35-
echo "$workspaces" | while read -r workspace_pattern; do
36-
# Handle glob patterns by expanding them
37-
if echo "$workspace_pattern" | grep -q '\*'; then
38-
# Use find to expand glob patterns like "packages/*"
39-
find . -path "./$workspace_pattern" -type d -mindepth 1 -maxdepth 2 2> /dev/null || true
40-
else
41-
# Direct path
42-
if [ -d "$workspace_pattern" ]; then
43-
echo "$workspace_pattern"
44-
fi
45-
fi
46-
done
47-
else
48-
# Fallback to all subdirectories
49-
find . -type d -mindepth 1 -maxdepth 1
50-
fi
51-
else
52-
# Fallback to all subdirectories when package.json or jq not available
53-
find . -type d -mindepth 1 -maxdepth 1
54-
fi
55-
}
56-
57-
# Get affected workspace names from commit history for a given range
58-
# Parameters: range (git range specification)
59-
# Returns list of workspace names that have commits with matching scopes
60-
get_affected_workspaces() {
61-
local range="$1"
62-
63-
# Extract scopes from commits and match against workspace names
64-
git log --oneline --format="%s" "$range" 2> /dev/null \
65-
| sed -n 's/^[^(]*(\([^)]*\)):.*/\1/p' \
66-
| sort -u \
67-
| while read -r commit_scope; do
68-
# Check if this scope matches any workspace directory
69-
get_workspace_dirs | while read -r workspace_dir; do
70-
local workspace_name=$(basename "$workspace_dir")
71-
if [ "$commit_scope" = "$workspace_name" ]; then
72-
echo "$workspace_dir"
73-
fi
74-
done
75-
done | sort -u
76-
}
77-
7824
# ===== VERSION DETERMINATION FUNCTIONS =====
7925

8026
# Get all git tags in reverse chronological order (newest first)
@@ -286,14 +232,14 @@ update_files() {
286232
return 1
287233
fi
288234
zz_log i "Minimal mode: only bumping workspaces with related commits"
289-
workspace_list=$(get_affected_workspaces "$range")
235+
workspace_list=$(git workspaces -r "$range")
290236

291237
if [ -z "$workspace_list" ]; then
292238
zz_log w "No workspaces affected by recent commits - skipping workspace updates"
293239
return
294240
fi
295241
else
296-
workspace_list=$(get_workspace_dirs)
242+
workspace_list=$(git workspaces)
297243
fi
298244

299245
zz_log i "Bumping version in $filename across workspaces to $version"

0 commit comments

Comments
 (0)