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

Support for relative roots/monorepos #72

Closed
ffloyd opened this issue Aug 30, 2019 · 11 comments
Closed

Support for relative roots/monorepos #72

ffloyd opened this issue Aug 30, 2019 · 11 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@ffloyd
Copy link

ffloyd commented Aug 30, 2019

For example, when you working with monorepo you may want to have config like this:

pre-commit:
  commands:
    elixir_format:
      root: "/backend"
      glob: "*.{ex,exs}"
      run: mix format --check-formatted {staged_files}
    ts_format:
      root: "/frontend"
      glob: "*.{ts,tsx}"
      run: npm run format_check {staged_files}

Possible root option behaviour:

  • helpers like {staged_files} should return paths relative to provided root path
  • option files should use root path as working dir
  • option run should use root path as working dir
@Arkweid Arkweid added the enhancement New feature or request label Aug 30, 2019
@Arkweid
Copy link
Collaborator

Arkweid commented Aug 30, 2019

#38 ref

@schibrikov
Copy link
Contributor

+1 for this issue. It's a huge pain to use eslint in monorepo now.
I guess I can work on this a bit later, if nobody will take care.

@Arkweid
Copy link
Collaborator

Arkweid commented Sep 27, 2019

I give it a try in followng week

@dflock
Copy link

dflock commented Nov 16, 2019

I'd really like to start using lefthook and this is a roadblock for us.

@Arkweid Arkweid added the help wanted Extra attention is needed label Nov 18, 2019
@Arkweid
Copy link
Collaborator

Arkweid commented Nov 18, 2019

@sHooKDT makes I few changes for monorepos(big thanks), also root path in 0.6.5 now always related to git top.
Probable not a big changes we need to do to make it works:

  1. Add new config key to the list (for root: "/backend")
    https://github.com/Arkweid/lefthook/blob/master/cmd/run.go#L42
  2. Grab it from config file like this:
    https://github.com/Arkweid/lefthook/blob/master/cmd/run.go#L469-L472
  3. Our runners now can be executed on some context(/backend, frontend)
    So we need to look at something like chdir https://golang.org/src/os/file.go?s=7660:7688#L251 or if you familiar with bash you can change sh -c i some way.
  4. Double the code for _windows.go postfix files

@jsmestad
Copy link
Contributor

jsmestad commented Dec 6, 2019

I used @Arkweid's guidance to implement this in #98.

  • {all_files} and {staged_files} will be relative to the root path specified
    • For example, root "api/" will change "api/spec/spec_helper.rb" to "./spec/spec_helper.rb"
    • Exclude files that do not fall inside of root (for example, "frontend/index.js" would be excluded from the task) - This functionality overlaps a little with glob, but I think that makes sense.
  • Change directory into root when executing command

@Arkweid
Copy link
Collaborator

Arkweid commented Dec 12, 2019

@sHooKDT @dflock @ffloyd
It would be great if someone will also check PR for existing project

@dflock
Copy link

dflock commented Dec 12, 2019 via email

Arkweid pushed a commit that referenced this issue Dec 17, 2019
Support relative roots for monorepos (#72)
@Arkweid
Copy link
Collaborator

Arkweid commented Dec 21, 2019

Supoprt for monorepos released in v0.7.0, thanks @jsmestad

@CxRes
Copy link

CxRes commented Dec 27, 2020

Is there some documentation on how how to use Lefthook in monorepos?

@trajano
Copy link

trajano commented Jan 4, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

7 participants