Repository navigation
fix: lefthook deps serialization - #16969
Conversation
Extract npm ci guard into web-deps job; use native deps for serialization instead of a mkdir mutex that could leave stale locks on interrupted commits. Also use single quotes in echo to work around lefthook v2.1.10 stripping double quotes on Windows. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Caution Review failedAn error occurred during the review process. Please try again later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lefthook.yml (1)
73-109: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick winRace condition:
depsis not a valid Lefthook job property.Lefthook does not natively support a
depsordepends_onproperty for jobs. Because thepre-commithook is configured withparallel: true(line 15),web-deps,web-prettier, andweb-eslintwill all start executing concurrently.Since
depswill be ignored,web-depsmay executerm -rf web/node_modulesat the exact momentweb-prettierandweb-eslintare attempting to invokenpx, causing the linting and formatting jobs to fail or hang.To enforce ordering without a file lock, you must group the dependency job and the linting jobs using Lefthook's
groupandpiped: truefeatures.🔒 Proposed fix to enforce sequential execution
By nesting a parallel group inside a piped group,
web-depsruns first, and upon success,web-prettierandweb-eslintrun in parallel.- - name: web-deps - glob: "web/**/*.{css,less,json,js,jsx,ts,tsx}" - run: | - # Ensure web/node_modules is populated. CI runners don't run `npm install` - # before lefthook, and `npx` without local node_modules fetches the - # latest packages from the registry - which breaks because the pinned - # prettier plugins (prettier-plugin-organize-imports, - # prettier-plugin-packagejson) aren't auto-resolved and ESLint 10 - # requires eslint.config.js. - # Serialized via lefthook 'deps' from web-prettier/web-eslint instead of - # a mkdir mutex, which left stale locks on interrupted commits and - # caused subsequent commits to hang forever in 'while ! mkdir'. - if [ ! -f web/node_modules/.package-lock.json ]; then - echo '==> web/node_modules missing or incomplete; running npm ci --prefix web' - rm -rf web/node_modules - npm ci --prefix web --no-audit --no-fund - fi - - name: web-prettier - glob: "web/**/*.{css,less,json,js,jsx,ts,tsx}" - stage_fixed: true - deps: [web-deps] - run: | - if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then - cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx prettier --check --ignore-unknown - else - cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx prettier --write --ignore-unknown - fi - - name: web-eslint - glob: "web/**/*.{js,jsx,ts,tsx}" - stage_fixed: true - deps: [web-deps] - run: | - if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then - cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx eslint - else - cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx eslint --fix - fi + - name: web-checks + group: + piped: true + jobs: + - name: web-deps + glob: "web/**/*.{css,less,json,js,jsx,ts,tsx}" + run: | + # Ensure web/node_modules is populated. CI runners don't run `npm install` + # before lefthook, and `npx` without local node_modules fetches the + # latest packages from the registry - which breaks because the pinned + # prettier plugins (prettier-plugin-organize-imports, + # prettier-plugin-packagejson) aren't auto-resolved and ESLint 10 + # requires eslint.config.js. + # Serialized via piped group instead of a mkdir mutex. + if [ ! -f web/node_modules/.package-lock.json ]; then + echo '==> web/node_modules missing or incomplete; running npm ci --prefix web' + rm -rf web/node_modules + npm ci --prefix web --no-audit --no-fund + fi + - name: web-linters + group: + parallel: true + jobs: + - name: web-prettier + glob: "web/**/*.{css,less,json,js,jsx,ts,tsx}" + stage_fixed: true + run: | + if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then + cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx prettier --check --ignore-unknown + else + cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx prettier --write --ignore-unknown + fi + - name: web-eslint + glob: "web/**/*.{js,jsx,ts,tsx}" + stage_fixed: true + run: | + if [ "${LEFTHOOK_CHECK_ONLY:-}" = "1" ]; then + cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx eslint + else + cd web && printf '%s\n' {staged_files} | sed 's|^web/||' | xargs npx eslint --fix + fi🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@lefthook.yml` around lines 73 - 109, Replace the unsupported deps-based ordering around web-deps, web-prettier, and web-eslint with Lefthook group configuration using an outer piped group and an inner parallel group. Ensure web-deps completes successfully before web-prettier and web-eslint start, while preserving parallel execution between the two linting jobs and their existing commands.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@lefthook.yml`:
- Around line 73-109: Replace the unsupported deps-based ordering around
web-deps, web-prettier, and web-eslint with Lefthook group configuration using
an outer piped group and an inner parallel group. Ensure web-deps completes
successfully before web-prettier and web-eslint start, while preserving parallel
execution between the two linting jobs and their existing commands.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #16969 +/- ##
=======================================
Coverage 93.16% 93.16%
=======================================
Files 10 10
Lines 717 717
Branches 118 118
=======================================
Hits 668 668
Misses 29 29
Partials 20 20 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
fix: lefthook deps serialization
Extract npm ci guard into web-deps job; use native deps for serialization instead of a mkdir mutex that could leave stale locks on interrupted commits. Also use single quotes in echo to work around lefthook v2.1.10 stripping double quotes on Windows.