sudo-suhas / lint-staged-multi-pkg

Example repo to demonstrate use of `lint-staged` with multi-pkg projects
MIT License
188 stars 19 forks source link

Execute lint-staged only in package where there are staged changes #4

Closed jogold closed 4 years ago

jogold commented 5 years ago

Hi,

It seems that with the proposed structure precommit is run in each package even those that don't have staged changes. Any idea on how to improve this?

sudo-suhas commented 5 years ago

You could try installing lint-staged at the package root.

sudo-suhas commented 5 years ago

The precommit call to package which does not have any staged file would be effectively a no-op via lint-staged if I am not wrong.

jogold commented 5 years ago

The precommit call to package which does not have any staged file would be effectively a no-op via lint-staged if I am not wrong.

It is a no-op but for a monorepo with let's say 30 packages it's a very slow process...

sudo-suhas commented 5 years ago

Go through these:

You should be able to tweak lerna run to pick only the packages which have been modified.

sudo-suhas commented 5 years ago

If you are arrive at a solution, would you be interested in contributing to the readme by adding a FAQ section? I think the question your question is worth documenting.

jogold commented 5 years ago

would you be interested in contributing to the readme by adding a FAQ section?

of course

jogold commented 5 years ago

https://github.com/lerna/lerna/issues/1955

jogold commented 5 years ago

Ever tried this https://github.com/wix-incubator/monorepo-staged-precommit?

sudo-suhas commented 5 years ago

No, I haven't tried that. To be completely honest, I have never used a monorepo myself. I originally authored this as an example for usage of lint-staged.

sudo-suhas commented 5 years ago

@jogold Could you try adding --since HEAD to your pre-commit command? I think this might do the trick.

Edit: This will run the pre-commit hook for a package if it has any changes. Even if they haven't been staged. It's still better than the current behavior though.

jogold commented 5 years ago

@sudo-suhas I ended up doing this: https://github.com/goldwasserexchange/public/blob/chore/global/monorepo/precommit.js

with this:

{
 "husky": {
    "hooks": {
      "pre-commit": "node precommit.js"
    }
  }
}
dialex commented 5 years ago

@jogold that precommit.js file returns a 404

jogold commented 5 years ago

@dialex have a look here https://github.com/goldwasserexchange/public/blob/master/precommit.js