How can I put expression inside package.json string?


How to increment version in script message? Because my release message should be always bigger to one version.

Goal: If I have already** 0.1.2 version**, I want to increment my commit message to 0.1.3 and then release.
Of course I can always update it manually, but maybe some advices how to automate this process?

  "version": "0.1.2",
  "scripts": {
    "release": "git commit --allow-empty  -m \\\"chore: release 0.1.2\\\"",

So I need to take my current version, increment it and pass into release script, what I need to use to receive this result as I expect?

"scripts": {
    "release": "git commit --allow-empty  -m {expression}",

>Solution :

You can use semver in combination with a shell script to achieve your goal.

npm install -g semver

Create a shell script that will handle version incrementation and the Git commit.

you can try below Example script for testing (


current_version=$(cat package.json | grep -o '"version": "[0-9.]\+"' | grep -o '[0-9.]\+')

new_version=$(semver bump patch $current_version)

git commit --allow-empty -m "chore: release $new_version"

Make sure the script is executable:

chmod +x

Update your "release" script in your package.json to call this shell script:

"scripts": {
  "release": "./"

Hope this helps and customize as needed.

Leave a ReplyCancel reply