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

Monorepos and relative root #195

Closed
boojum opened this issue May 18, 2021 · 5 comments
Closed

Monorepos and relative root #195

boojum opened this issue May 18, 2021 · 5 comments
Labels
waiting for response We need more details or confirmation

Comments

@boojum
Copy link

boojum commented May 18, 2021

I'm trying to get lefthook to play with my monorepo as per #72. My project structure is as follows:

├── client
│   ├── const.config.js
│   ├── dist
│   ├── node_modules
│   ├── package.json
│   ├── package-lock.json
│   ├── postcss.config.js
│   ├── prettier.config.js
│   ├── README.md
│   ├── src
│   ├── stylelint.config.js
│   ├── svelte.config.js
│   ├── tsconfig.json
│   ├── webpack.config.js
│   └── webpack.parts.js
├── worker
|   ├── dist
|   ├── node_modules
|   ├── package.json
|   ├── package-lock.json
|   ├── src
|   ├── worker
|   └── wrangler.toml
├── lefthook.yml
├── node_modules
├── package.json
├── package-lock.json
├── README.md

The lefthook config at the root of the repo:

skip_output:
  - meta
  - success

pre-commit:
  parallel: true
  commands:
    svelte-check:
      root: 'client/'
      glob: 'src/**/*.{ts,svelte}'
      run: npm run validate {staged_files}
    eslint:
      root: 'client/'
      glob: 'src/**/*.{js,jsx,ts,tsx,json,svelte}'
      run: npm run lint:ts:check {staged_files}
    stylelint:
      root: 'client/'
      glob: 'src/**/*.{css,html,js,md,mjs,svelte,svg,ts}'
      run: npm run lint:css:check {staged_files}
    prettier:
      root: 'client/'
      glob: 'src/**/*.{js,ts,css,json,md,svelte,html}'
      run: npm run format:check {staged_files}

When I edit any of the listed files (js, ts, svelte, css etc etc), and then try to commit them lefthook is not kicking in. When I run npx lefthook run pre-commit - with staged relevant files - lefthook comes back to me with:

SUMMARY: (SKIP EMPTY)

Any idea what I might be missing here?

@skryukov
Copy link
Member

Hi, @boojum! Could you provide some additional output:

  1. npx lefthook version
  2. npx lefthook run pre-commit -v
  3. and maybe git status if this is appropriate =)

@skryukov skryukov added the waiting for response We need more details or confirmation label May 18, 2021
@smac89
Copy link

smac89 commented Dec 28, 2021

I also had the same problem. The only way to get it to work is to prefix any of the globs with **/.


IGNORE THE REST OF THIS:

Also if you change the run script to pwd >&2 && echo {} >&2, you will see that lefthook is adding the root path to the resulting file name, while the script is running inside the root path.

This causes problems, because scripts inside the root, cannot find the path given by lefthook. I now have to resort to hacky solutions to make this work, and I am not willing to share such disturbing content on the internets.

@smac89
Copy link

smac89 commented Dec 28, 2021

@skryukov

Hi, @boojum! Could you provide some additional output:

1. `npx lefthook version`

2. `npx lefthook run pre-commit -v`

3. and maybe `git status` if this is appropriate =)
➜ npx @arkweid/lefthook version
0.7.7
➜ npx @arkweid/lefthook run pre-commit -v

Lefthook v0.7.7
RUNNING HOOKS GROUP: pre-commit
⠋ waiting 
Files before filters: 
[project/package.json project/src/pages/Dashboard/pets/PetsManager.tsx project/yarn.lock lefthook.yml otherproject/package.json otherproject/yarn.lock]
Files after filters: 
[./src/pages/Dashboard/pets/PetsManager.tsx]
Files after escaping: 
[./src/pages/Dashboard/pets/PetsManager.tsx]

EXECUTE > format-project
/home/user/company/projects/project
project/src/pages/Dashboard/pets/PetsManager.tsx


SUMMARY: (done in 2.10 seconds)
✔️  format-project

This is my pre-commit:

pre-commit:
  parallel: true
  commands:
    format-project:
      root: "project/"
      glob: "**/{src,cypress}/**/*.{js,tsx,ts,jsx}"
      run: npx git-format-staged --formatter 'pwd >&2 && echo {} >&2' {staged_files}

I think an easy solution to this is to just replace {} with the full path to the file. No point trying to do relative path tricks

@smac89
Copy link

smac89 commented Dec 28, 2021

Whoops, I forgot {} is not part of lefthook. Ignore my comments about that

@mrexox
Copy link
Member

mrexox commented Nov 14, 2022

Please, open a new discussion if the issue is still relevant! I'll be glad to dig into your case.

@mrexox mrexox closed this as completed Nov 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting for response We need more details or confirmation
Projects
None yet
Development

No branches or pull requests

4 participants