Skip to content

Commit 7f76ea9

Browse files
Merge pull request #23 from browniebroke/package-lock
Add `--lock` option to update the `package-lock.json` file in addition to manifest files
2 parents 94beef0 + 2f21cae commit 7f76ea9

5 files changed

Lines changed: 49 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
All notable changes will be documented in this file.
33
`version-bump-prompt` adheres to [Semantic Versioning](http://semver.org/).
44

5+
## Unreleased
6+
7+
- Added `--lock` option to update the package-json.lock file
58

69
## [v4.0.0](https://github.com/BigstickCarpet/version-bump-prompt/tree/v4.0.0) (2017-11-15)
710

bin/bump.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ program
2323
.option('--push', 'Push the Git commit')
2424
.option('--all', 'Commit/tag/push ALL pending files, not just the ones changed by bump')
2525
.option('--grep <filespec...>', 'Files and/or globs to do a text-replace of the old version number with the new one')
26+
.option('--lock', 'Also update the package-lock.json')
2627
.on('--help', () => {
2728
console.log(
2829
' Examples:\n' +
@@ -52,7 +53,7 @@ else {
5253
options.commit = true;
5354
}
5455

55-
let manifests = api.manifests();
56+
let manifests = api.manifests(options.lock);
5657
bumpManifests(manifests, options)
5758
.then(() => {
5859
api.grep(manifests, options);

lib/index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ module.exports = {
2727
*
2828
* @returns {string[]}
2929
*/
30-
function getManifests () {
31-
return ['package.json', 'bower.json', 'component.json'].filter((manifest) => {
30+
function getManifests (withLockfile) {
31+
let candidates = ['package.json', 'bower.json', 'component.json'];
32+
if (withLockfile) {
33+
candidates.push('package-lock.json');
34+
}
35+
return candidates.filter((manifest) => {
3236
let pkgPath = path.join(cwd, manifest);
3337
try {
3438
const pkg = require(pkgPath);

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Options:
6363
--push Push the Git commit
6464
--all Commit/tag/push ALL pending files, not just the ones changed by bump
6565
--grep <filespec...> Files and/or globs to do a text-replace of the old version number with the new one
66+
--lock Update the package-lock.json file as well
6667

6768
Examples:
6869

test/specs/lock.spec.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
3+
const cli = require('../fixtures/cli');
4+
const files = require('../fixtures/files');
5+
const check = require('../fixtures/check');
6+
const chai = require('chai');
7+
8+
chai.should();
9+
10+
describe('bump --lock', () => {
11+
it('should not increment lock file by default', () => {
12+
files.create('package-lock.json', { version: '1.0.0' });
13+
14+
let output = cli.exec('--patch');
15+
16+
output.stderr.should.be.empty;
17+
output.stdout.should.be.empty;
18+
output.status.should.equal(0);
19+
20+
files.json('package-lock.json').should.deep.equal({ version: '1.0.0' });
21+
});
22+
23+
it('should increment version when lock option is provided', () => {
24+
files.create('package-lock.json', { version: '0.0.0' });
25+
26+
let output = cli.exec('--patch --lock');
27+
28+
output.stderr.should.be.empty;
29+
output.status.should.equal(0);
30+
31+
output.lines.should.deep.equal([
32+
`${check} Updated package-lock.json to 0.0.1`,
33+
]);
34+
35+
files.json('package-lock.json').should.deep.equal({ version: '0.0.1' });
36+
});
37+
});

0 commit comments

Comments
 (0)