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

husky and monorepo #1510

Open
Byron2016 opened this issue Sep 8, 2024 · 0 comments
Open

husky and monorepo #1510

Byron2016 opened this issue Sep 8, 2024 · 0 comments

Comments

@Byron2016
Copy link
Contributor

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.

  • My project structure is :

. # 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

        • 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"

Thank you!

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

1 participant