I added Husky to my Angular project which does not reside in the root folder. (Not my decision.) It is in the "frontend" subfolder. And the husky/git pre-commit hook is in frontend/.husky/pre-commit.
It looks like this:
#!/bin/sh
changed_files=$(git diff --cached --diff-filter=d --name-only | grep .ts$ | grep ^frontend | sed "s%^frontend/%%g")
if [ -n "$changed_files" ]; then
. "$(dirname "$0")/_/husky.sh"
cd frontend && npx ng lint --files $changed_files
fi
But for some reason it fails saying that the ts file cannot be found:
An unhandled exception occurred: Project 'C:/proj/frontend/src/app/my.component.spec.ts' does not exist.
See "C:\Users\XXX\AppData\Local\Temp\ng-u1G22D\angular-errors.log" for further details.
husky - pre-commit hook exited with code 127 (error)
But this doesn't make any sense. The file exists.
What am I missing? How to I fix this?
edit It works when I call the linter per file:
cd frontend || exit 1
for f in $changed_files
do
npx ng lint --files "$f"
done