当仅更改某个文件夹中的文件时,是否可以仅运行 git 挂钩?
我有后端和前端的 monorepo。我只想在前端的文件发生更改时运行 husky hook。否则它不应该被触发并且不运行 linting 测试等......这会激怒后端开发人员
通过 lint-staged 的组合,我设法仅对所需的文件夹更改运行 husky hooks 检查。
module.exports = {
'*': (files) => {
const isAppFolderChanges = files.some((fileName) =>
fileName.includes('/app/'),
)
const scripts = [
'npm run lint-fix',
'./node_modules/.bin/pretty-quick --staged',
'npm test',
]
return isAppFolderChanges ? scripts : []
},
}