Closed abdonrd closed 2 years ago
Husky seems broken, this link does not work as well
Correct link -> https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5
Hi @abdonrd,
It's not possible with husky v5, sorry. I can understand it's unconventional.
That said, personally, I don't think it's a bad trade-off. While a directory and some files are created here with v5, previously with v4 it was 47 packages and many files that were installed to support config via package.json and other functionalities.
Also it's how Git hooks work so there's not much that can be done without relying on JS code and abstractions again.
You can however group husky and other config files in a .config
directory, if you want to reduce clutter.
PS: link fixed, thanks :+1:
I'd also really prefer not to add new files for 5 lines of configuration.
cosmiconfig is already installed by other packages (lint-staged, postcss-loader, stylelint, etc.), so it shouldn't affect installation time or disk usage much.
I also don't love the idea of having to add a postinstall
script. If something is both recommended as well as used by the vast majority of users, then it should be the default (with an optional opt-out mechanism).
Thanks for the work that you do.
Fair enough.
Regarding postinstall
, recent versions of package managers (npm 7, yarn 2) now hide output from dependencies postinstall
(which is the script used by husky 4 to auto-install hooks).
So with husky 4 way of installing, users can't tell if it succeded or failed to install hooks. This has led to some complicated to debug issues.
On the other side, the output of postinstall
in package.json is shown.
Also having a postinstall
in a dependency for something else that compilation isn't recommended (https://docs.npmjs.com/cli/v6/using-npm/scripts#best-practices).
But in the end, I understand too, it makes more files and work to enable Git hooks.
Thanks for the feedback :+1:
Thanks for the answers @typecode!
Now that I understand that it was a deliberate decision, I would like to vote towards re-supporting configuration files (either with cosmiconfig
or otherwise).
Just a note of support for the old config, v5 is big step back (for us) in terms of workflow and usability. I don't want to think about about hooks at all, that was the benefit of husky, you added one package, and config in the package.json, it worked and i never had to think about this again. I can imagine that for more complicated flows this setup is better, but 99% of our husky usage was for running lint and prettier on files precommit, it's something that should be transparent. Thanks for all the hard work!
I have to agree that husky@5 is a regression, so I'm going to keep using husky@4. Hopefully husky@6 will add some backward compatibility. I shouldn't have to work this hard on tooling.
Adding support for reading config from package.json would be my preferred usage as well. The other benefits of Husky 5 sound nice, would be great to have them alongside package.json configuration
I would like to point out that, it is abstraction that is the powerful thing about npm tool ecosystem, with a conventional and centralized way of configuration across the various tools using a JSON/JS file or package.json.
I do understand that less dependency is good, but it's less important when it comes to developer tools like this. (like npm having 60+ dependencies)
I do understand that git hook, under the hood, whether or not it's a good design, is as simple as listing shell scripts in a folder. But at this point it's equivalent to not using husky and just adding "prepare": "git config core.hooksPath hooks"
by myself instead.
The reason husky has been so powerful and useful was exactly the abstraction it used to provide, and being able to "forget" that you're using git hooks.
About this topic, I just noticed that:
https://github.com/IBM/pwa-lit-template/pull/333
The adoption is 3% after 1 month? 😮 (and v5.0.0 was released 4 months ago)
It's also listed with a high confidence.
Updates are classified as High Confidence once we believe that their combination of Age, Adoption and Test Compatibility means that there's a very low chance that there are breaking changes.
very low chance that there are breaking changes.
Yeah, okay.
@typicode this is a right update to Husky v6, right?
https://github.com/IBM/pwa-lit-template/pull/406/files
Thanks in advance!
@abdonrd Could you please leave this issue open for those of us who still prefer using package.json
for simple configuration?
@glen-84 ok! But after the author's messages I understand that there is no going back.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Not stale.
Agree this is not stale. I went to add Husky to a project that wasn't currently using it only to discover that husky config files are now a requirement.
Honestly, it's a bit of a deal breaker, and we'll forego using Husky any further until this issue is resolved. Thank you kindly for your attention, I'm looking forward to the possibility of this being resolved!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Not stale. Please label.
prefer package.json, there had been so many config files in front end tools, don't want to add a folder just want precommit hook.
It is so clean like before, just add:
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
This maybe why vue choose to fork husky and create yorkie and keep old simple way. Good tools should not be too invasive.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Not stale. Please label.
Git requires to have separate files for each hook so there's not much that can be done. Personally I don't mind them, that said I thought about some ways to hide things a little.
If you have one or two hooks, you can install them in the root of your project (recommended)
husky install .
husky add ./pre-commit 'npm test'
You'll only have a pre-commit
file at the root of the project instead of in ./husky/
directory.
You may programmatically create them:
// husky.js
const husky = require('husky')
husky.install('.husky')
husky.set('.husky/pre-commit', 'npm test')
{
"scripts": {
"prepare": "node husky.js"
}
}
Then ignore .husky
completely in .gitignore
. However with this approach, you lose your source of truth and need to regenerate hooks each time their definition changes in husky.js
. This is the solution I'd least recommend, unless you're OK with manual updates.
Closing as there nothing else I can think of. Hope it'll help anyway.
How to setup Husky v5 without new files?
We don't want to create a
.husky
folder with files like.husky/pre-commit
, etc.We prefer to have a few lines in the
package.json
: