I'm trying to run the yarn prettier
command at each pre-commit.
I found out that I should use Husky in order to create a git hook.
And it works but since I'm a monorepo it pushed my working directory and erased the parent.
Here are the steps that I took:
since the
.git
directory is at the root of the project, I've created a symlink in my working directory (and I think the issue is here)yarn add -D husky lint-staged
npx husky-init && yarn
Added
"prepare": "husky install"
to the package.json scriptsAdded the following configuration to package.json:
"lint-staged": { "*.{js,ts,tsx}": [ "eslint --quiet --cache --fix" ], "*.{json,js,ts,jsx,tsx,html}": [ "prettier --write" ] },
Added my action to the pre-commit file :
npx husky add .husky/pre-commit "yarn prettier"
prettier
runs when I commit, but everything outside my directory is erased and does not appear anymore on my repo.
How should I handle this?