Skip to content

Commit bc0fc53

Browse files
noreillerstevemao
authored andcommitted
feat: add support for package-lock.json (#190)
1 parent 4b6d6db commit bc0fc53

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

lib/lifecycles/bump.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ function bumpVersion (releaseAs, callback) {
135135
*/
136136
function updateConfigs (args, newVersion) {
137137
configsToUpdate[path.resolve(process.cwd(), './package.json')] = false
138+
configsToUpdate[path.resolve(process.cwd(), './package-lock.json')] = false
138139
configsToUpdate[path.resolve(process.cwd(), './npm-shrinkwrap.json')] = false
139140
configsToUpdate[path.resolve(process.cwd(), './bower.json')] = false
140141
Object.keys(configsToUpdate).forEach(function (configPath) {

test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ function writeNpmShrinkwrapJson (version, option) {
5959
fs.writeFileSync('npm-shrinkwrap.json', JSON.stringify(shrinkwrap), 'utf-8')
6060
}
6161

62+
function writePackageLockJson (version, option) {
63+
option = option || {}
64+
var pkgLock = Object.assign(option, { version: version })
65+
fs.writeFileSync('package-lock.json', JSON.stringify(pkgLock), 'utf-8')
66+
}
67+
6268
function writeGitPreCommitHook () {
6369
fs.writeFileSync('.git/hooks/pre-commit', '#!/bin/sh\necho "precommit ran"\nexit 1', 'utf-8')
6470
fs.chmodSync('.git/hooks/pre-commit', '755')
@@ -676,6 +682,24 @@ describe('standard-version', function () {
676682
})
677683
})
678684

685+
describe('package-lock.json support', function () {
686+
beforeEach(function () {
687+
writePackageLockJson('1.0.0')
688+
})
689+
690+
it('bumps version # in package-lock.json', function (done) {
691+
commit('feat: first commit')
692+
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
693+
commit('feat: new feature!')
694+
require('./index')({silent: true})
695+
.then(() => {
696+
JSON.parse(fs.readFileSync('package-lock.json', 'utf-8')).version.should.equal('1.1.0')
697+
getPackageVersion().should.equal('1.1.0')
698+
return done()
699+
})
700+
})
701+
})
702+
679703
describe('dry-run', function () {
680704
it('skips all non-idempotent steps', function (done) {
681705
commit('feat: first commit')

0 commit comments

Comments
 (0)