如何检查一致性npm-shrinkwrap.json和package.json
有时我的团队成员忘记更新package.json之后更新npm-shrinkwrap.json。 我从uber知道这个软件包 ,但不能用于npm v3。 所以现在它不是解决scheme。
我有可能自动检查npm-shrinkwrap.json和package.json的一致性吗? 我想在git-hook或/和连续做这个。
您可以testingnpm包git-hooks
,它允许安装预先提交或预先推送的钩子 (即客户端钩子 )
这样的钩子(像这个预先提交的 )可以用来检查源文件的一致性,如npm-shrinkwrap.json
。
另请参阅turadg/npm-shrinkwrap-git-hooks
一组脚本可以根据需要自动
npm install
npm shrinkwrap
和npm install
。如果您对
package.json
进行更改,pre-commit
钩子将run npm shrinkwrap
来更新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
更新由galk-in
我select了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" ] ...
从2017年6月24日更新现在的答案是使用npm 5和package-lock.json