Avoid `prexxx` `postxxx` names for hooks

See original GitHub issue

When you run your npm script called xxx, npm will automatically execute the scripts prexxx before and postxxx after the target script if available. husky uses the names with pre and post for the hook scripts a lot , this introduces the limitation for the names of your npm scripts, e.g. https://github.com/typicode/husky/issues/94#issuecomment-279703998

Can we use names like pre-xxx and post-xxx for the hooks instead?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
ducletcommented, Mar 8, 2017

I’m not sure if that will fully resolve the issue. There is nothing stopping it for whatever reason executing prepre-commit for example. Also, it takes away the ability to name certain scripts because git has a commit hook for that. One of the ones I see is update. Also, what if git decides to add a new hook in the future? So currently I have a script called foo, I upgrade git and now it has a hook called foo as well. All of a sudden, my script will automatically run when it shouldn’t. Personally, I like the idea of the hooks being in there separate configuration much like how ghooks had it (that was one of the main reason why I switched from husky to ghooks). While the maintainer have essentially given up and recommend people to using this, I still find the git hooks being in the scripts block rather dangerous. I do want to make this work though so my recommendation is this: Add support for users of this module to specify where they want the hooks to be read from via a configuration in package.json. It can continue to support what it is currently doing as the default. Otherwise, users of the configure it to be in a separate config such as:

{
    ...
    "config": {
        "husky": {
            "hooksInConfig": true,
            "hooks": {
                "commit": "..."
            }
        }
    }
    ...
}
4reactions
vovacodescommented, Mar 1, 2017

@typicode It is definitely possible to rename your scripts to avoid the clashes, but I believe it’s still a limitation. In our project the script that caused the problem was commit. We use commitizen for maintaining the format of our commit messages and the script looks like: "commit": "git-cz". We renamed that to cz eventually, but the name commit makes more sense to me still.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The How To Of HBase Coprocessors - 3Pillar Global
Region Server Observer: Provides hook for the events related to the RegionServer, such as stopping the RegionServer and performing ...
Read more >
LOINC Users' Guide Version 2.67 (Published December 2019)
Logical Observation Identifiers Names and Codes (LOINC®). Users' Guide ... 2.1.2.19 Avoid use of the word “total” in laboratory test names, ...
Read more >
npm命令及npm scripts的简单总结- 前端小丑- 博客园
pre 和post hooks. 双重的pre和post无效,比如prepretest和postposttest是无效的。 { "scripts":{ 'prexxx':, 'xxx':, 'postxxx':, } }.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Hashnode Post

No results found