Skip to content

Commit 86af7fc

Browse files
noreillerbcoe
authored andcommitted
feat: add support for npm-shrinkwrap.json (#185)
1 parent 13eb9cd commit 86af7fc

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

index.js

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ module.exports = function standardVersion (argv, done) {
5858
var configsToUpdate = {}
5959
function updateConfigs (args, newVersion) {
6060
configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
61+
configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
6162
configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false
6263
Object.keys(configsToUpdate).forEach(function (configPath) {
6364
try {

test.js

+26-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ function writeBowerJson (version, option) {
5555
fs.writeFileSync('bower.json', JSON.stringify(bower), 'utf-8')
5656
}
5757

58+
function writeNpmShrinkwrapJson (version, option) {
59+
option = option || {}
60+
var shrinkwrap = objectAssign(option, { version: version })
61+
fs.writeFileSync('npm-shrinkwrap.json', JSON.stringify(shrinkwrap), 'utf-8')
62+
}
63+
5864
function writeGitPreCommitHook () {
5965
fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8')
6066
fs.chmodSync('.git/hooks/pre-commit', '755')
@@ -520,13 +526,31 @@ describe('standard-version', function () {
520526
writeBowerJson('1.0.0')
521527
})
522528

523-
it('bumps verson # in bower.json', function (done) {
529+
it('bumps version # in bower.json', function (done) {
530+
commit('feat: first commit')
531+
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
532+
commit('feat: new feature!')
533+
require('./index')({silent: true}, function (err) {
534+
if (err) return done(err)
535+
JSON.parse(fs.readFileSync('bower.json', 'utf-8')).version.should.equal('1.1.0')
536+
getPackageVersion().should.equal('1.1.0')
537+
done()
538+
})
539+
})
540+
})
541+
542+
describe('npm-shrinkwrap.json support', function () {
543+
beforeEach(function () {
544+
writeNpmShrinkwrapJson('1.0.0')
545+
})
546+
547+
it('bumps version # in npm-shrinkwrap.json', function (done) {
524548
commit('feat: first commit')
525549
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
526550
commit('feat: new feature!')
527551
require('./index')({silent: true}, function (err) {
528552
if (err) return done(err)
529-
JSON.parse(fs.readFileSync('package.json', 'utf-8')).version.should.equal('1.1.0')
553+
JSON.parse(fs.readFileSync('npm-shrinkwrap.json', 'utf-8')).version.should.equal('1.1.0')
530554
getPackageVersion().should.equal('1.1.0')
531555
done()
532556
})

0 commit comments

Comments
 (0)