0

Is there a way to manage/sync the version property in package-lock.json file? my situation is as follow:

  1. When I have a new release, I manually update the version property in package.json, commit and push.
  2. On the build server, npm install to get all the deps needed by the build server, etc..
  3. However, npm install also update the version property in package-lock.json to match the one in package.json (which is good but too late).

I could have made an npm install in the first step to get the version property in package-lock.json in-sync with the one in package.json then commit and push, but for me this does not make sense (not the purpose of npm install, someone can simply forget, etc..) . I also know that I should not be manually updating the package-lock.json file.

  • Is there a better way to handle this ?
  • I'm using NPM version 5.6 and I know in version 5.7 there is a new command npm ci which does not alter package-lock.json file but also does not solve the fact that the version needs to be synced, and anyway for now I would like to know if there is a way to handle this in version 5.6.
mkhayata
  • 327
  • 1
  • 3
  • 11
  • Does `npm install --package-lock-only` before commit makes more sense? P.s. https://docs.npmjs.com/cli/version – wanjas Oct 25 '18 at 02:49
  • if you change the version number to '*' in the package.json file means automatically it take the latest version. but evertime you need to install the package manually – Vinoth Oct 25 '18 at 07:07
  • @Vinoth I cannot change the version number to '*' I use the version to display it on the UI. – mkhayata Oct 26 '18 at 01:40
  • @wanjas what does --package-lock-only do exactly ? but still does not make sense since you have to do an ```npm install``` anyway. – mkhayata Oct 26 '18 at 01:44
  • @mkhayata Generally editing package.json manually should be discouraged. You can make use of npm commands which will update both package.json and package-lock.json. `npm install --save` and `npm uninstall --save` – Sreeragh A R May 27 '19 at 12:24
  • @SreeraghAR this does not address the issue I have, this will update particular packages' version, not the app version. Please read the question carefully. – mkhayata Jun 09 '19 at 19:03

1 Answers1

0

Old question, but the answer is "npm version [new version]". Which will update package.json, package-lock.json and npm-shrinkwrap.json.

https://docs.npmjs.com/cli/v8/commands/npm-version