package-revision
v1.0.5
Published
Updates package.json version number with current git tag
Downloads
592
Readme
Patches the package.json version
field with the latest tag from the current git commit.
Why?
We got sick of having to add a commit to our JavaScript projects to update the version
field in package.json before tagging for releases, so we came up with a solution to do it automatically.
How to use
You can use it however you want. Best used with npx
in a build script.
Example (package.json)
{
"scripts": {
"build": "npx package-revision && make build"
}
}
You can also add a hashVersion
property to your package.json by supplying -h
or --head
arguments:
npx package-revision --head
This will add the current commit ID. Note that this may already be available when running your application via the npm_package_gitHead
environment variable, so you may not need this.
Caveats
- Lightweight tags may cause issues where multiple tags are based on the same commit. Usually the first tag is used in this case. Recommended to use annotated tags instead, which contain date information and will always return the latest tag information.
- Modifies the package.json file which may end up being committed by people who tend to do
git add .
. This may or may not be desired in your project. Proceed with caution :)