Skip to content

Commit 46a4645

Browse files
mhuisiclaude
andauthored
chore: also bump dependents in package version bump script (#729)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ab4ea5d commit 46a4645

File tree

1 file changed

+53
-40
lines changed

1 file changed

+53
-40
lines changed

bump-package-version.sh

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,65 @@ fi
99

1010
package_name="$1"
1111
new_version="$2"
12+
dir="lean4-$package_name"
13+
npm_name="@leanprover/$package_name"
1214

13-
case "$package_name" in
14-
infoview-api)
15-
dir="lean4-infoview-api"
16-
npm_name="@leanprover/infoview-api"
17-
;;
18-
infoview)
19-
dir="lean4-infoview"
20-
npm_name="@leanprover/infoview"
21-
;;
22-
unicode-input)
23-
dir="lean4-unicode-input"
24-
npm_name="@leanprover/unicode-input"
25-
;;
26-
unicode-input-component)
27-
dir="lean4-unicode-input-component"
28-
npm_name="@leanprover/unicode-input-component"
29-
;;
30-
*)
31-
echo "Unknown package: $package_name"
32-
echo "Valid names: infoview-api, infoview, unicode-input, unicode-input-component"
33-
exit 1
34-
;;
35-
esac
15+
if [ ! -d "$dir" ]; then
16+
echo "Unknown package: $package_name"
17+
echo "Valid names: infoview-api, infoview, unicode-input, unicode-input-component"
18+
exit 1
19+
fi
20+
21+
# Maps directory names to npm package names
22+
npm_name_of() {
23+
echo "@leanprover/$(echo "$1" | sed 's/^lean4-//')"
24+
}
3625

37-
# Update version in the package's own package.json
38-
echo "Updating $dir/package.json version to $new_version"
39-
sed -i 's/"version": ".*"/"version": "'$new_version'"/' "$dir/package.json"
26+
# Process version bumps transitively using a queue.
27+
# Each entry is "dir:version" — the package whose version was bumped and needs its
28+
# dependents updated. Dependents (excluding vscode-lean4) get patch-bumped and are
29+
# added to the queue so their own dependents are updated in turn.
30+
bumped="" # Track already-bumped packages to handle diamonds in the dependency graph
31+
queue="$dir:$new_version"
32+
while [ -n "$queue" ]; do
33+
entry="${queue%%
34+
*}"
35+
queue="${queue#"$entry"}"
36+
queue="${queue#
37+
}"
4038

41-
# Update dependency version in all other package.json files, preserving range prefix.
42-
# Also patch-bump dependent NPM packages (excluding vscode-lean4 which has its own release cycle).
43-
echo "Updating dependents of $npm_name"
44-
for pkg_json in */package.json; do
45-
if grep -q "\"$npm_name\"" "$pkg_json"; then
46-
echo " Updating dependency in $pkg_json"
47-
sed -i 's|"'"$npm_name"'": "\([~^]*\)[^"]*"|"'"$npm_name"'": "\1'"$new_version"'"|' "$pkg_json"
39+
bump_dir="${entry%%:*}"
40+
bump_version="${entry#*:}"
41+
bump_npm_name="$(npm_name_of "$bump_dir")"
42+
bumped="$bumped $bump_dir"
4843

44+
echo "Updating $bump_dir/package.json version to $bump_version"
45+
sed -i 's/"version": ".*"/"version": "'$bump_version'"/' "$bump_dir/package.json"
46+
47+
echo "Updating dependents of $bump_npm_name"
48+
for pkg_json in */package.json; do
4949
dep_dir="$(dirname "$pkg_json")"
50-
if [ "$dep_dir" != "vscode-lean4" ] && [ "$dep_dir" != "$dir" ]; then
51-
old_ver="$(node -p "require('./$pkg_json').version")"
52-
# Patch bump: increment the last numeric component
53-
new_dep_ver="$(echo "$old_ver" | awk -F. '{$NF=$NF+1; print}' OFS=.)"
54-
echo " Bumping $dep_dir version: $old_ver -> $new_dep_ver"
55-
sed -i 's/"version": ".*"/"version": "'$new_dep_ver'"/' "$pkg_json"
50+
[ "$dep_dir" = "$bump_dir" ] && continue
51+
if grep -q "\"$bump_npm_name\"" "$pkg_json"; then
52+
echo " Updating dependency in $pkg_json"
53+
sed -i 's|"'"$bump_npm_name"'": "\([~^]*\)[^"]*"|"'"$bump_npm_name"'": "\1'"$bump_version"'"|' "$pkg_json"
54+
55+
# Patch-bump the dependent (excluding vscode-lean4 and already-bumped packages)
56+
case " $bumped " in *" $dep_dir "*) continue ;; esac
57+
if [ "$dep_dir" != "vscode-lean4" ]; then
58+
old_ver="$(node -p "require('./$pkg_json').version")"
59+
dep_new_ver="$(echo "$old_ver" | awk -F. '{$NF=$NF+1; print}' OFS=.)"
60+
echo " Patch-bumping $dep_dir: $old_ver -> $dep_new_ver"
61+
# Add to queue so its dependents are updated too
62+
if [ -n "$queue" ]; then
63+
queue="$queue
64+
$dep_dir:$dep_new_ver"
65+
else
66+
queue="$dep_dir:$dep_new_ver"
67+
fi
68+
fi
5669
fi
57-
fi
70+
done
5871
done
5972

6073
# Update package-lock.json

0 commit comments

Comments
 (0)