mkdir foocd foogit initecho '{"precommit": ["echo hello"], "devDependencies": { "pre-commit": "^1.2.2" }}' > package.jsonpnpm igit add package.json && git commit -m 'testing'The word "hello" will be echoed to stdout after issuing git commit -m 'testing'.
The pre-commit hook is not run because pnpm doesn't seem to run, at least run correctly, the install script from the pre-commit package.
node -v prints: v8.9.4Thanks for reporting! I've checked the source code of pre-commit, and it expects the "root" to be two directories above the directory in which pre-commit is installed. Unfortunately, in the case of pnpm, this does not happen, because pnpm has a different node_modules structure.
I'll open an issue in the pre-commit repo to see if they can fix it.
EDIT: opened https://github.com/observing/pre-commit
Until this issue is fixed upstream, you can use the feature introduced in #1106 to solve this.
npm set pnpmfile ~/.pnpmfile.js~/.pnpmfile.js'use strict'
module.exports = {
hooks: {readPackage}
}
function readPackage (pkg, context) {
if (pkg.name === 'pre-commit') {
delete pkg.dependencies['pre-commit']
pkg.dependencies['@jsumners/pre-commit'] = '1.2.2-fork.1'
context.log('pre-commit => @jsumners/pre-commit')
}
return pkg
}
It could be tweaked to check for a maximum (hopefully the currently published) pre-commit package. But given the lack of movement around the issue upstream, I don't think it's worth it.
I find myself working in some monorepos now and pre-commit does not work with them. I think husky would, so it's on my todo list to evaluate. It's good to hear it will support pnpm.
Most helpful comment
also, husky@next works fine with pnpm. They even added a test to maintain compatibility with our node_modules structure :heart:.