diff --git a/bin/git-hooks/pre-commit b/bin/git-hooks/pre-commit index 1fba7d221f86..25b67606983a 100755 --- a/bin/git-hooks/pre-commit +++ b/bin/git-hooks/pre-commit @@ -7,11 +7,12 @@ if \git --no-pager diff-index -z --name-only --no-renames --cached HEAD | \ \grep -qzE '\.(json|scss|ts)$'; then # NOTE! grep must be kept in sync with lint-staged in package.json! - LINT_STAGED="$(dirname -- "$0")/../../node_modules/.bin/lint-staged" + BIN_DIR="$(dirname -- $0)/.." + LINT_STAGED="$BIN_DIR/../node_modules/.bin/lint-staged" # pnpm or npx adds .25s overhead. exec further reduces overhead. if [ -x "$LINT_STAGED" ]; then - exec "$LINT_STAGED" + exec "$LINT_STAGED" --config "$BIN_DIR/lint-staged.config.mjs" else exec pnpm lint-staged fi diff --git a/bin/lint-staged.config.mjs b/bin/lint-staged.config.mjs index 074f27c0bc3f..108540013370 100644 --- a/bin/lint-staged.config.mjs +++ b/bin/lint-staged.config.mjs @@ -1,19 +1,8 @@ -import { lstat } from 'fs/promises'; - -async function filterSymlinks(files) { - const checks = await Promise.all( - files.map(async file => - lstat(file) - .then(s => s && !s.isSymbolicLink() && file) - .catch(() => null), - ), - ); - return checks.filter(Boolean); -} +import { lstatSync } from 'fs'; export default { - '*.{json,scss,ts}': async files => { - const regularFiles = await filterSymlinks(files); + '*.{json,scss,ts}': files => { + const regularFiles = files.filter(f => !lstatSync(f).isSymbolicLink()); return regularFiles.length ? `prettier --write ${regularFiles.join(' ')}` : 'true'; }, };