-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Don't pollute enclosing project hooks #36
Comments
Hi @ericsoco, Not sure to understand why you want to run |
I was debugging a package and needed to rebuild it to pick up my changes. My apologies, I don't know how husky does what it does, so I don't know if On Friday, December 4, 2015, typicode notifications@github.com wrote:
ditditdit on my mobile phone |
cant wrap my head about this problem. @ericsoco can you elaborate a bit? |
It's been a long time @iamstarkov, but best as I remember, my initial comment describes it well -- I If possible, |
I had the same problem (with Automatically injecting git hooks on install (as opposed to requiring the package consumer to explicitly add a command in a postinstall script, which would be far safer) is dangerous enough - it should certainly not traverse above the folder the closest |
@ericsoco next version of Husky will prevent this case. There's already a test and code for this in So, Husky won't install git hooks if it detects that it's in a sub-node_module directory. For example: project$ cd node_modules/json-server
project/node_modules/json-server$ npm install won't install hooks in |
@ljharb thanks for the feedback. At first, this was the behaviour, Husky was supposing that But actually, there's many people that seem to have a different layout, for example:
That's why Husky looks for the first That said, I would be interesting in better understanding your use case. This way Husky could be improved. Do you have a workflow example? Because, except for the edge case described by @ericsoco, I can't see a case where Husky is defined in
Actually, I don't really see how it would differ in the end? That said, adding a command in postinstall script may be the recommended way for the next version, as |
All I know is that I've never done any development on I think doing anything like this automatically on install is HIGHLY dangerous. Users should have to opt-in by running an explicit command first. |
Our project has multiple submodules placed in a root |
@ljharb, fair concerns. although it's unconventional for non- @typicode, what i'd be interested in seeing is some indexing into the that is, with the following structure: /.git
/packages/A/...
/packages/B/... execute the following psuedocode:
in this fashion:
and everybody is happy! 🎉 thoughts? |
@cdaringe What would be explicit opt-in is if the requirement was to add |
I just discovered this behavior when I realized that I had husky hooks installed in a repo that doesn't use husky. I'd like to use husky in a project that will be distributed as a tarball. I don't want husky to install hooks when users build the project. Would it be possible to default to the old behavior of assuming that the git directory is at the same level as package.json, install no hooks if it's not found, and add a configuration switch for setting an explicit root? That would make the default safer while allowing those with different layouts the ability to still use husky. |
This would also handle the case of node_modules, as described at the top of this issue and in #304. Without this, I'm afraid I might have to remove husky from my project. |
I even tried seeing if I could get husky to skip installing the hook scripts by having an empty config: // husky.config.js
const fs = require('fs');
const path = require('path');
if (fs.existsSync(path.join(__dirname, '.git'))) {
module.exports = {
hooks: {
'pre-commit': 'lint-staged',
},
};
} else {
module.exports = {};
} |
Closing as husky 5 doesn't automatically install hooks anymore. Unless explicitly specified in |
I just ran
npm install
on a package within my project'snode_modules
. This package hashusky
listed as adevDependency
.husky
ended up writing hooks into my project's.git/hooks
, instead of the package withinnode_modules
. Now I can't commit code in my own project without removing the hooks /--no-verify
ing.The text was updated successfully, but these errors were encountered: