Is there a way to check if a package-lock.json
file is compatible with package.json
without running npm install
? Compatible means the versions specified package.json
can be fulfilled by package-lock.json
.
Current approach
I'm currently checking this by running npm install
and checking if package-lock.json
changed like so:
git clone https://github.com/my/codebase
cd codebase
npm install
if [[ git diff-index --quiet HEAD -- package-lock.json ]]; then
echo 'ERROR: npm install changed package-lock.json'
fi
Use-case
I want to add a test in continuous integration to ensure that if a developer modifies package.json
they also update package-lock.json
accordingly. The reason this is important is that our continuous integration uses npm ci
instead of npm install
. npm ci
only references package-lock.json
, so if the developer doesn't update the lock file, the continuous integration setup won't match what they expect.
npm ci
will fail if the package.json and the package-lock.json are not in sync, so your continuous integration is already testing your use case. Can you please provide more information about the difference you are finding between your developer's setup and the CI one? – Loam