Maybe this could be a miss understandig of how husky works and wrong expectation about it, I suposed that with a monorepo, husky is going to ejecute scripts from each workspace in concordance with the changes that occurs in that workspace.
My project structure is :
. # Package.json with husky
├── .git/
├── apps/
├──┼── a/ # Package.json with husky
└──┴── b/ # Package.json with husky
Add pre-commit script to ./.husky/pre-commit
echo "============================================="
echo "in the root"
echo "============================================="
commit
commit is ok and a "pre-commit" is executed and show on console "in the root"
Add husky to "apps/a" workspace
cd apps/a
npm pkg set scripts.prepare="cd ../.. && husky apps/a/.husky"
npm run prepare
touch .husky/pre-commit
Add pre-commit script to ./apps/a/.husky/pre-commit
cd apps/a
echo "**"
echo "in the a app"
echo "**"
commit
commit is ok and a "apps/a/.husky/pre-commit" is executed and show on console "in the a app"
Add husky to "apps/b" workspace
cd apps/b
npm pkg set scripts.prepare="cd ../.. && husky apps/b/.husky"
npm run prepare
touch .husky/pre-commit
Add pre-commit script to ./apps/a/.husky/pre-commit
cd apps/b
echo "**"
echo "in the b app"
echo "**"
commit
commit is ok and a "apps/b/.husky/pre-commit" is executed and show on console "in the b app"
Please describe your issue and provide some context:
issue 1
update ./apps/a/index.js from console.log(" from a app"); to console.log(" from a1 app");
generate a new commit
Result:
expectect
commit is ok and a "apps/a/.husky/pre-commit" is executed and show on console "in the a app"
obtained
commit is ok but it is executed "apps/b/.husky/pre-commit" and show on console "in the b app"
issue 2
Update
update ./apps/a/index.js from console.log(" from a app"); to console.log(" from a1 app");
update ./apps/b/index.js from console.log(" from b app"); to console.log(" from b1 app");
generate a new commit
Result:
expectect
commit is ok and
a "apps/a/.husky/pre-commit" is executed for ./apps/a/index.js and show on console "in the a app"
a "apps/b/.husky/pre-commit" is executed for ./apps/b/index.js and show on console "in the b app"
obtained
commit is ok but it is executed "apps/b/.husky/pre-commit" and show on console "in the b app"
Troubleshoot
Context
Maybe this could be a miss understandig of how husky works and wrong expectation about it, I suposed that with a monorepo, husky is going to ejecute scripts from each workspace in concordance with the changes that occurs in that workspace.
. # Package.json with husky ├── .git/ ├── apps/ ├──┼── a/ # Package.json with husky └──┴── b/ # Package.json with husky
Minimal reproduction code
steps
Add husky to root
npm install --save-dev husky
npx husky init
Add pre-commit script to ./.husky/pre-commit echo "=============================================" echo "in the root" echo "============================================="
commit
Add husky to "apps/a" workspace
cd apps/a
npm pkg set scripts.prepare="cd ../.. && husky apps/a/.husky"
npm run prepare
touch .husky/pre-commit
Add pre-commit script to ./apps/a/.husky/pre-commit cd apps/a echo "**" echo "in the a app" echo "**"
commit
Add husky to "apps/b" workspace
cd apps/b
npm pkg set scripts.prepare="cd ../.. && husky apps/b/.husky"
npm run prepare
touch .husky/pre-commit
Add pre-commit script to ./apps/a/.husky/pre-commit cd apps/b echo "**" echo "in the b app" echo "**"
commit
Please describe your issue and provide some context:
issue 1
update
./apps/a/index.js
fromconsole.log(" from a app");
toconsole.log(" from a1 app");
generate a new commit
Result:
issue 2
Update
./apps/a/index.js
fromconsole.log(" from a app");
toconsole.log(" from a1 app");
./apps/b/index.js
fromconsole.log(" from b app");
toconsole.log(" from b1 app");
generate a new commit
Result:
./apps/a/index.js
and show on console "in the a app"./apps/b/index.js
and show on console "in the b app"Thank you!