Repository: conventional-changelog/standard-version
Pull request #185 (2017-06-02 13:04:05)

feat: add support for `npm-shrinkwrap.json`
Hi, I use your module since a few weeks, and as I missed this little feature, here it is.
By the way, I fixed the bower test since it didn't check the `bower.json` file. :smile: 
Thank for your great work.
Aurélien

coveralls: 
[![Coverage Status](https://coveralls.io/builds/11801308/badge)](https://coveralls.io/builds/11801308)

Coverage remained the same at 100.0% when pulling **2a9c0c2f0e159b7dac014bb4ab995be7b0c17198 on noreiller:master** into **13eb9cd47d780f90938c1c447a31149d2f02baea on conventional-changelog:master**.

stevemao: Could you also add support for `package-lock`? Thanks :)
bcoe: @stevemao the CLI team at npm tells me that you shouldn't publish the package-lock.json to the registry; and it looks like `npm version` (according to the docs) doesn't implement the version in `package-lock.json`

I say we land this feature, and I'll talk to my coworkers Monday to see if we would want to increment the version in `package-lock.json`.

Patch:
diff --git a/index.js b/index.js
index e6a7870..b4b698e 100755
--- a/index.js
+++ b/index.js
@@ -58,6 +58,7 @@ module.exports = function standardVersion (argv, done) {
 var configsToUpdate = {}
 function updateConfigs (args, newVersion) {
   configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
+  configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
   configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false
   Object.keys(configsToUpdate).forEach(function (configPath) {
     try {


Test patch:
diff --git a/test.js b/test.js
index 995868b..9547d58 100644
--- a/test.js
+++ b/test.js
@@ -55,6 +55,12 @@ function writeBowerJson (version, option) {
   fs.writeFileSync('bower.json', JSON.stringify(bower), 'utf-8')
 }
 
+function writeNpmShrinkwrapJson (version, option) {
+  option = option || {}
+  var shrinkwrap = objectAssign(option, { version: version })
+  fs.writeFileSync('npm-shrinkwrap.json', JSON.stringify(shrinkwrap), 'utf-8')
+}
+
 function writeGitPreCommitHook () {
   fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8')
   fs.chmodSync('.git/hooks/pre-commit', '755')
@@ -520,13 +526,31 @@ describe('standard-version', function () {
       writeBowerJson('1.0.0')
     })
 
-    it('bumps verson # in bower.json', function (done) {
+    it('bumps version # in bower.json', function (done) {
+      commit('feat: first commit')
+      shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
+      commit('feat: new feature!')
+      require('./index')({silent: true}, function (err) {
+        if (err) return done(err)
+        JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0')
+        getPackageVersion().should.equal('1.1.0')
+        done()
+      })
+    })
+  })
+
+  describe('npm-shrinkwrap.json support', function () {
+    beforeEach(function () {
+      writeNpmShrinkwrapJson('1.0.0')
+    })
+
+    it('bumps version # in npm-shrinkwrap.json', function (done) {
       commit('feat: first commit')
       shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
       commit('feat: new feature!')
       require('./index')({silent: true}, function (err) {
         if (err) return done(err)
-        JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal('1.1.0')
+        JSON.parse(fs.readFileSync('npm-shrinkwrap.json', 'utf-8')).version.should.equal('1.1.0')
         getPackageVersion().should.equal('1.1.0')
         done()
       })