webpro-nl/knip

New husky format does not work for binaries without 'npx'

Closed this issue · 4 comments

Reproduction url

https://stackblitz.com/edit/github-jt9pwf?file=package.json,.husky%2Fpre-commit

Description of the issue

husky released a new version 9.1. In that release they removed the necessity to call binaries with npx.
When removing npx, knip does not recognize these binaries anymore and flags them as not used.

Release Notes for husky: https://github.com/typicode/husky/releases/tag/v9.1.1

The reproduction url shows the problem:

  • lint-staged with the 'new' format produces an error, because knip thinks it's not used
  • if we add npx lint-staged knip is happy and runs without an error

I'm guessing knip does search for some form of npx, so removing is does currently not work with the new version.

The issue is that only scripts in package.json#scripts are supposed to reference binaries installed in node_modules. Package managers add node_modules/.bin to the PATH.

My I guess is that husky is doing something similar, but Knip is unaware of that "magic".

For now the best option is to add lint-staged to ignoreDependencies. We might consider treating husky scripts the same as package.json#scripts.

Yep, fine for me to add it to ignored dependencies for now.

Just wanted to mention it here, since it's new behavior 🙂

🚀 This issue has been resolved in v5.36.5. See Release 5.36.5 for release notes.

Using Knip in a commercial project? Please consider becoming a sponsor.

Sorry it took a while, but should be good now!