We want to add an automated check to our CI server that would prevent code from getting committed that updates a dependency in package.json but does not update the resolved dependency in package-lock.json.
This could happen if, for example, someone updated a dependency in package.json manually but ran npm install instead of npm update (npm install favors package-lock.json, if present). Or it could happen even if someone runs the correct npm command when updating a dependency but then forgets to commit the resulting changes to package-lock.json. We try to watch for these things in code review, but an automated check would definitely be better. Is there any npm command that does this?
Here's an example to illustrate.
Before:
// package.json
{
"lodash": "~3.1.0"
}
// package-lock.json
{
"dependencies": {
"lodash": {
"version": "3.1.3"
}
}
}
Someone updates package.json but forgets to commit the change to package-lock.json.
After:
// package.json
{
"lodash": "~3.2.0"
}
// package-lock.json (not changed)
{
"dependencies": {
"lodash": {
"version": "3.1.3"
}
}
}
Now package-lock.json no longer reflects a valid set of dependency resolutions for the package.json file.