You can test out the npm package git-hooks
, which allows to install pre-commit or pre-push hooks (that is client-side hooks)
Such hooks (like this pre-commit one) can be used to check the consistency of source files like npm-shrinkwrap.json
.
See also for instance turadg/npm-shrinkwrap-git-hooks
A set of scripts to automatically npm shrinkwrap
and npm install
as needed.
If you stage a change to package.json
, the pre-commit
hook will run npm shrinkwrap
to update npm-shrinkwrap.json
.
#!/usr/bin/env bash
# This ensures that dependencies are installed locally whenever merging a commit
# that changed the shrinkwrap.
function package_changes_staged {
! git diff --cached --quiet -- package.json
}
# update shrinkwrap when spec changes
if package_changes_staged; then
echo "Running 'npm shrinkwrap' to match new package spec..." >&2
npm shrinkwrap
git add npm-shrinkwrap.json
fi
UPDATE by galk-in
I chose pre-commit with this updates in package.json
...
"scripts": {
"check-shrinkwrap": "if (! git diff --cached --quiet -- package.json); then echo 'Running `npm shrinkwrap` to match new package spec...' >&2; npm shrinkwrap; git add npm-shrinkwrap.json; fi"
},
...
"pre-commit": [
"check-shrinkwrap",
"test"
]
...