default_install_hook_types: [pre-commit, post-checkout, post-merge]

repos:
  - repo: local
    hooks:
      - id: biome-format-js
        name: Biome format (JS/TS)
        language: system
        entry: pnpm biome format --write --no-errors-on-unmatched
        files: '\.(js|jsx|ts|tsx|cjs|mjs|cts|mts)$'
        pass_filenames: true

      - id: eslint-fix
        name: ESLint fix
        language: system
        entry: pnpm eslint --fix
        files: '\.(js|jsx|ts|tsx|cjs|mjs|cts|mts)$'
        pass_filenames: true

      - id: biome-format-other
        name: Biome format (JSON/YAML/CSS/HTML)
        language: system
        entry: pnpm biome format --write --no-errors-on-unmatched
        files: '\.(json|yml|yaml|css|html)$'
        pass_filenames: true

      - id: post-checkout-install
        name: pnpm install after checkout
        language: system
        entry: bash -c 'if [ "$PRE_COMMIT_FROM_REF" != "$PRE_COMMIT_TO_REF" ] && git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF" -- "**/package.json" pnpm-lock.yaml | grep -q .; then echo "Dependencies changed, running pnpm install..."; pnpm install; else echo "No dependency changes, skipping pnpm install."; fi'
        stages: [post-checkout]
        always_run: true
        pass_filenames: false

      - id: post-merge-install
        name: pnpm install after merge/pull
        language: system
        entry: bash -c 'PREV_HEAD=$(git rev-parse --short HEAD@{1} 2>/dev/null); if [ -n "$PREV_HEAD" ] && git diff --name-only "$PREV_HEAD" HEAD -- "**/package.json" pnpm-lock.yaml | grep -q .; then echo "Dependencies changed, running pnpm install..."; pnpm install; else echo "No dependency changes, skipping pnpm install."; fi'
        stages: [post-merge]
        always_run: true
        pass_filenames: false