Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does npm version work?

I'm a little hazy on how npm version works. The documentation says:

If run in a git repo, it will also create a version commit and tag.

Does that mean I don't have to run git commit or git tag or does it just take the place of git tag -a <version>? If I did something like this would I be creating a double commit?

git add . -A
git commit -m "<commit message>"
git push origin master
npm version <patch|minor|major> -m "<version description>" ## instead of git tag -a <version> ##
git push --tags
like image 939
jwerre Avatar asked Jun 13 '17 23:06

jwerre


1 Answers

Your understanding is mostly correct

When you execute the npm version command the following is done:

  1. bump package version as directed in package.json
  2. create a commit containing only the update to package.json with the message specified when invoking npm version.
  3. create a git tag

You can then execute npm publish to publish to the npm registry, and git push your tag to your remote repository when you see fit


The long answer

As for the exact commands that our executed as you expressed interest in this via comments:

adding the files to staging:

git add /path/to/package.json

See source.

If lock and shrinkwrap package files are also present they are also added as above!

creation of the commit:

git commit -m {version message}

See source.

as for creation of the tag:

git tag {version no.} -am {version message}

or if signing is turned on:

git tag {version no.} -sm {version message}

See source.

For reference the version message is optional, if it is excluded from the CLI input then it will default to have the value of version no..

like image 183
Peter Reid Avatar answered Sep 30 '22 02:09

Peter Reid