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

How does husky manage shared folder configuration #1248

Open
laterdayi opened this issue Mar 17, 2023 · 6 comments
Open

How does husky manage shared folder configuration #1248

laterdayi opened this issue Mar 17, 2023 · 6 comments

Comments

@laterdayi
Copy link

Currently husky is one in each project.husky directory,

With more and more projects, copying directories can cause a lot of trouble. Is there a way to share.husky directories

@laterdayi
Copy link
Author

@typicode Looking forward to your help

@typicode
Copy link
Owner

typicode commented Mar 18, 2023

Git only has one hooks directory so you can't have natively multiple places where hooks are stored. The recommended approach is to have husky in root and let monorepo tools run scripts.

So for example, in A/package.json, B/package.json you would have a pre-commit script that would be run with your monorepo tool.

https://typicode.github.io/husky/#/?id=monorepo

@laterdayi
Copy link
Author

@typicode 但是在package.json中无法直接使用 pre-commit,好像还是需要在.husky中创建对应的hooks文件

@laterdayi
Copy link
Author

Is there a way to put the SH file on NPM and use it in the project, can you give a DEMO?

@typicode
Copy link
Owner

Sorry I probably won't have time right now to go into details, but I hope to be able to make a blog post or add docs at some points.
Meanwhile, you can script husky and do something like that:

// my-script.js
const yourHooks = require('your-hooks') // your hooks is a published package on npm
const husky = require('husky')

husky.install()
// loop through your hooks and do something like run husky.set('.husky/pre-commit', yourHooks.preCommit)

In your package.json

"scripts": {
  "prepare": "node my-script"
}

@laterdayi
Copy link
Author

@typicode
in npm scripts prepare, is ok
However, post-merge requires creating a post-merge file in the.husky of the local project to implement the post-merge directive

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

No branches or pull requests

2 participants