Pnpm: Does not install `pre-commit` module correctly

Created on 23 Feb 2018  路  4Comments  路  Source: pnpm/pnpm

pnpm version: 1.33.2

Code to reproduce the issue:

  1. mkdir foo
  2. cd foo
  3. git init
  4. echo '{"precommit": ["echo hello"], "devDependencies": { "pre-commit": "^1.2.2" }}' > package.json
  5. pnpm i
  6. git add package.json && git commit -m 'testing'

Expected behavior:

The word "hello" will be echoed to stdout after issuing git commit -m 'testing'.

Actual behavior:

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.

Additional information:

  • node -v prints: v8.9.4
  • Windows, OS X, or Linux?: macOS
buecosystem

Most helpful comment

also, husky@next works fine with pnpm. They even added a test to maintain compatibility with our node_modules structure :heart:.

All 4 comments

Thanks 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.

  1. npm set pnpmfile ~/.pnpmfile.js
  2. Add the following to ~/.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.

also, husky@next works fine with pnpm. They even added a test to maintain compatibility with our node_modules structure :heart:.

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.

Was this page helpful?
0 / 5 - 0 ratings