-
Notifications
You must be signed in to change notification settings - Fork 220
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
lefthook's location is ignored in the hooks in a monorepo #443
Comments
Hey! I guess the problem is - it doesn't look obvious that
lefthook.yml is supposed to locate in the git root directory. Your case looks like a feature request. Also things will become a bit more complicated if you have So, the main problem here is - for a monorepo with multiple projects we still have one set of git hooks, so we anyway need one reference for a lefthook executable. BTW, do you have git modules? In this case things might be different but unfortunately I haven't tested this setup for a long time. |
Thanks for responding! Yeah, your description is correct.
I assume the easiest and most performant solution is to support a custom location directive in Also aside from this stuff note point 2 above since if that worked correctly I probably never would've even noticed this. But it happened to install a bugged version of lefthook that got patched a while ago which was sitting in my
not using git modules |
Hey! Now when you have |
🔧 Summary
The lefthook.yml supports the
root:
directive in order to run the hooks from a separate monorepo folder. However it does not pass this information to the hooks at all. So the hooks end up doing this:git rev-parse --show-toplevel
only gets the root of the whole repository. nowhere do the hooks account for lefthook being installed in a deeper nested directory. this is a problem because lefthook can be part of a monorepo which is not just a top level javascript project. for example:No top level package.json is desirable here, and lefthook lives inside of
./js-project/
but tells the hooks to check./node_modules/
rather than/JS-project/node_modules
which is where it actually lives. as a fallback condition it tries to hack usingnpx lefthook
which is even worse because it retrieves some random cached version somewhere globally on the machine, which is even worse and causes version mismatches.Lefthook version
1.3.3
Possible Solution
The hooks generated need to know where to look for lefthook in a monorepo. Add a directive to point to where lefthook is installed in the monorepo and propagate it to the hooks. For example
lefthook_location: "my-js-dir/
. Then pass that to the generated hooks as a param.For the npx fallback, this is an unrelated bug but it also needs to be fixed. Change:
npx @evilmartians/lefthook $@
to:
npx @evilmartians/lefthook@latest $@
The former is incorrect and will always get a globally installed random version of lefthook that was cached on the user's machine at some random point in time. The latter will always get the latest released version with bugfixes.
The text was updated successfully, but these errors were encountered: