Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npx husky init generates invalid pre-commit script #1506

Open
1 task done
dexmlee opened this issue Sep 6, 2024 · 3 comments
Open
1 task done

npx husky init generates invalid pre-commit script #1506

dexmlee opened this issue Sep 6, 2024 · 3 comments

Comments

@dexmlee
Copy link
Contributor

dexmlee commented Sep 6, 2024

npx husky init is generating this invalid pre-commit script:

npm

See bin.js:
w('.husky/pre-commit', p.env.npm_config_user_agent?.split('/')[0] ?? 'npm' + ' test\n')

So possible values are either:

  • npm
  • npm test

On my mac:
p.env.npm_config_user_agent == 'npm/10.2.4 node/v20.11.1 darwin arm64 workspaces/false'
Order of operations error: + is higher than null coalesce. Looks like ?? was introduced in v9.1.0. Needs parens.

Easy problem to fix on new scripts, but confuses people following the documentation.

Troubleshoot

If you're migrating from husky 4, see:
https://typicode.github.io/husky/migrate-from-v4.html

Context
Please describe your issue and provide some context:

  • Terminal or GUI client (PowerShell, Git Bash, GitHub Desktop, ...)
  • If applicable, content of the failing hook
  • If possible, minimal steps to reproduce the issue

Thank you!

@typicode
Copy link
Owner

Thanks for spotting it! Feel free to make the PR if you want. Otherwise let me know, I'll do it.

@dexmlee
Copy link
Contributor Author

dexmlee commented Sep 11, 2024

@typicode PR sent.

@Munaf-Divan
Copy link

@typicode, out of curiosity, do we have a system in place where we label the issue, or it occurs automatically when a PR is created?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants