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

Add per-project global hook #747

Closed
wants to merge 4 commits into from

Conversation

castarco
Copy link

@castarco castarco commented Jul 28, 2020

Description

This PR adds a mechanism to source project-specific scripts before executing any of the git hook scripts managed by Husky.

Rationale

As stated in this comment ( #385 (comment) ), some times is necessary to apply the exec < /dev/tty trick before reaching the point where we execute any NodeJS-related tool (in my specific case, because those tools are containerized).

Although it's possible to achieve that by using the ~/.huskyrc file, using this solution forces all developers in a project to customize their development environments, when, precisely, tools such as nvm, or in my specific case avatar-cli, are designed to ease the creation of more homogeneous development environments.

Regarding why the file .huskyhook file is loaded before ~/.huskyrc, I assumed that, whatever customization the developer has in its environment, it's probably there because she wants to override something, so I tried to preserve that.

Regarding the name of the file, I'm not attached to it, we could pick something else. I just wanted to use a name different than .huskyrc because that name has a different meaning when it's inside a project (Actually I find quite unfortunate that the same name is used for so different concepts: script and configuration).

Related to issue #385 .

Allow Husky users to define a per-project script that will be triggered
for all Husky executions.
@castarco castarco changed the title Add per-project global hook [WIP] Add per-project global hook Jul 28, 2020
@castarco castarco marked this pull request as draft July 28, 2020 15:29
@castarco castarco changed the title [WIP] Add per-project global hook Add per-project global hook Jul 28, 2020
@castarco castarco marked this pull request as ready for review July 28, 2020 15:50
castarco added a commit to avatar-cli/avatar-cli that referenced this pull request Jul 28, 2020
The Husky NPM package was not able to deal with git hooks that called
containerized applications.

In this patch we temporary switch to @coderspirit/husky-fork, that
includes the PR typicode/husky#747, so we can
execute the git hooks from inside the Avatar-CLI subshell.
@rawc0der
Copy link

Nice job @castarco. This is going to be really handy.
Any progress about adopting this @typicode ??

@castarco
Copy link
Author

castarco commented Mar 10, 2021

@rawc0der it seems that @typicode opted for a simpler approach, in v5 my patch is not as necessary as before, but being honest, same can be said about husky, I don't use it anymore. This is what I type in my postinstall script:

{
  "scripts": { "postinstall": "if [ -d .git ]; then git config core.hooksPath .hooks; fi" }
}

Then I place my hook scripts in the .hooks directory, and I don't need the super-slow husky anymore.

@castarco castarco closed this Mar 10, 2021
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

Successfully merging this pull request may close these issues.

2 participants