Skip to content

Commit 0f774fc

Browse files
committed
feat: update version in package-lock.json
1 parent da718a3 commit 0f774fc

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/update-package-version.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ module.exports = async (version, basePath, logger) => {
1616
logger.log('Wrote version %s to %s', version, shrinkwrapPath);
1717
}
1818

19+
if (await pathExists(packageLockPath)) {
20+
const packageLock = await readJson(packageLockPath);
21+
await writeJson(packageLockPath, {...packageLock, ...{version}}, {spaces: 2});
22+
logger.log('Wrote version %s to %s', version, packageLockPath);
23+
}
1924
};

test/update-package-version.test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ test.serial('Updade package.json and npm-shrinkwrap.json', async t => {
4949
t.deepEqual(t.context.log.args[1], ['Wrote version %s to %s', '1.0.0', 'npm-shrinkwrap.json']);
5050
});
5151

52+
test.serial('Updade package.json and package-lock.json', async t => {
53+
// Create package.json in repository root
54+
await outputJson('./package.json', {version: '0.0.0-dev'});
55+
// Create a npm-shrinkwrap.json file
56+
await execa('npm', ['install']);
57+
58+
await updatePackageVersion('1.0.0', '.', t.context.logger);
59+
60+
// Verify package.json and npm-shrinkwrap.json have been updated
61+
t.is((await readJson('./package.json')).version, '1.0.0');
62+
t.is((await readJson('./package-lock.json')).version, '1.0.0');
63+
// Verify the logger has been called with the version updated
64+
t.deepEqual(t.context.log.args[0], ['Wrote version %s to %s', '1.0.0', 'package.json']);
65+
t.deepEqual(t.context.log.args[1], ['Wrote version %s to %s', '1.0.0', 'package-lock.json']);
66+
});
5267

5368
test.serial('Updade package.json and npm-shrinkwrap.json in a sub-directory', async t => {
5469
// Create package.json in repository root

0 commit comments

Comments
 (0)