Advancing a package version before committing
You can use a simple NPM command to automatically advance the version of your package.
I was yesterday years old when I found out about a cool trick to programmatically advance the version number of a package I was working on, before actually pushing the changes to the repository.
The command I'm referring to is npm version
(documentation): depending on the first parameter you pass to the command, it will automatically look for the current version number in your package.json
file and update according to your preference.
In my case, since I was mainly iterating over bug fixes here and there, a simple npm version patch
did in fact the trick.
There's an extra not-so-obvious note to be made: if you're working within a Git repository, the above command will fail if you have uncommitted changes. Again, in my case, I wanted the version number to be updated before actually pushing the code back to the repo, so I had to add a special flag to the command, which allowed me to bypass this limitation:
npm version patch --no-git-tag-version
Hope you find this useful!