Is there a way to run a script during npm version
, that is running after the release number was increased but before creating and pushing the git tag?
You can create a version
script that will be called once the package version is increased but before the commit and tag.
"scripts": {
"version": "./your_script"
}
Check the order of execution according to the npm version documentation. Below you can see the interesting excerpt, in particular point 4:
- Check to make sure the git working directory is clean before we get started. Your scripts may add files to the commit in future steps. This step is skipped if the --force flag is set.
- Run the preversion script. These scripts have access to the old version in package.json. A typical use would be running your full test suite before deploying. Any files you want added to the commit should be explicitly added using git add.
- Bump version in package.json as requested (patch, minor, major, etc).
- Run the version script. These scripts have access to the new version in package.json (so they can incorporate it into file headers in generated files for example). Again, scripts should explicitly add generated files to the commit using git add.
- Commit and tag.
- Run the postversion script. Use it to clean up the file system or automatically push the commit and/or tag.
This functionality was introduced in npm v2.13.0. See version: allow scripts to add files to the commit for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With