Home > front end >  Make pre-commit check in subdirectory of repository?
Make pre-commit check in subdirectory of repository?

Time:10-28

I'm trying to get a pre-commit check to run a command (in npm) not in the root of the git repository (I have a folder "frontend" that contains the npm installation). This sounds trivial, but so far I have found no pre-commit package that supports this directly. I came up with a workaround, where pre-commit launches a script, then the script makes a change of directory and then it runs the command, but I would like something more direct. Pre-commit packages I have tried:

None of these seem to support this directly

Any alternative packages to these would be welcome, or perhaps if I missed a setting in these somewhere.

A similar question was asked here for husky, but the answer again relied on a shell script: Husky npm package Pre-Commit hook not working in sub directory repository

UPDATE: Following comments, I will revise the emphasis of this question. I would really like to find out how to do this in one the three options I specified, although other solutions are welcome.

CodePudding user response:

I solved this by making a symlink to the package.json and node_modules folder in the root of repository.

ln -s frontend/package.json package.json

ln -s frontend/node_modules node_modules

CodePudding user response:

I found in the documentation of Husky a real solution to this problem - please see here: https://typicode.github.io/husky/#/?id=custom-directory

  • Related