Skip to content

Commit 278a2de

Browse files
committed
Adjust the bump-version script
Change the script to use npm's built-in functionality for updating a package's version. This will ensure that any npm package files are updated to the new version. However, we do prevent npm from creating the commit and a tag.
1 parent 0cb6490 commit 278a2de

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

bump-version

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set -o pipefail
1010
# Stores the canonical version for the project.
1111
VERSION_FILE=package.json
1212
# Files that should be updated with the new version.
13-
VERSION_FILES=("$VERSION_FILE")
13+
VERSION_FILES=("$VERSION_FILE" package-lock.json)
1414

1515
USAGE=$(
1616
cat << END_OF_LINE
@@ -32,7 +32,9 @@ END_OF_LINE
3232
old_version=$(sed -n "s/^[[:blank:]]*\"version\": \"\(.*\)\",\{0,1\}$/\1/p" $VERSION_FILE)
3333
# Comment out periods so they are interpreted as periods and don't
3434
# just match any character
35-
old_version_regex="^\([[:blank:]]*\"version\": \)\"${old_version//\./\\\.}\""
35+
# We are not currently using this, but it will be necessary if we need to work with
36+
# non-npm files in the future.
37+
# old_version_regex="^\([[:blank:]]*\"version\": \)\"${old_version//\./\\\.}\""
3638
new_version="$old_version"
3739

3840
bump_part=""
@@ -154,15 +156,21 @@ if [ "$with_prerelease" = true ]; then
154156
new_version="$temp_version"
155157
fi
156158

157-
tmp_file=/tmp/version.$$
158-
for version_file in "${VERSION_FILES[@]}"; do
159-
if [ ! -f "$version_file" ]; then
160-
echo Missing expected file: "$version_file"
161-
exit 1
162-
fi
163-
sed "s/$old_version_regex/\1\"$new_version\"/" "$version_file" > $tmp_file
164-
mv $tmp_file "$version_file"
165-
done
159+
# We are not currently using this, but it will be necessary if we need to work with
160+
# non-npm files in the future.
161+
# tmp_file=/tmp/version.$$
162+
# for version_file in "${VERSION_FILES[@]}"; do
163+
# if [ ! -f "$version_file" ]; then
164+
# echo Missing expected file: "$version_file"
165+
# exit 1
166+
# fi
167+
# sed "s/$old_version_regex/\1\"$new_version\"/" "$version_file" > $tmp_file
168+
# mv $tmp_file "$version_file"
169+
# done
170+
171+
# Use npm's built-in functionality to update the version of the package. We use the
172+
# `--no-git-tag-version` option to prevent npm from committing and creating a tag.
173+
npm version --no-git-tag-version "$new_version"
166174

167175
git add "${VERSION_FILES[@]}"
168176
git commit --message "$commit_prefix version from $old_version to $new_version"

0 commit comments

Comments
 (0)