fix(install): skip prek hook setup when binary not in PATH#1502
fix(install): skip prek hook setup when binary not in PATH#1502cv merged 2 commits intoNVIDIA:mainfrom
Conversation
Remove the elif branch that checked for node_modules/@j178/prek and exited with an error. After `npm install --omit=dev` the package directory may linger while the binary is not linked, causing a spurious failure on clean installs. If prek is not on PATH, simply skip hook setup regardless of node_modules state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
Apologies for the extra round-trip — the original #746 should have been tested with a clean install from the start. Will be more thorough with lifecycle script changes going forward. |
|
✨ Thanks for submitting this fix, which proposes a way to skip prek hook setup when the binary is not in PATH, resolving a regression that occurred during installation with --omit=dev. |
cv
left a comment
There was a problem hiding this comment.
LGTM — security review PASS.
- Fixes false-positive from stale
node_modules/@j178/prekdirectory breaking end-user installs command -v prekis the correct POSIX check- Security hooks are enforced by CI server-side regardless of local hook state
- "Skipping..." message still provides developer visibility
- No injection risk, no privilege changes
No concerns.
|
Rebased onto current Conflict resolution: Mechanical only — the ts-migration PR added adjacent lines ( The contributor's fork is returning HTTP 503, so the rebased branch has been pushed to Tests: 66 passed, 2 failed (both pre-existing failures on |
…back # Conflicts: # package.json
## Problem PR NVIDIA#746 (merged) made `prek` optional in the prepare script, but introduced a regression: when `node_modules/@j178/prek` directory exists but the `prek` binary is not in PATH, the script errors with `exit 1`. This happens in practice when running `npm install --omit=dev` (as the NemoClaw install script does) — the package directory may be present from a previous full install, but the binary won't be linked to PATH. Reported by @DanTup on a clean Ubuntu VM: NVIDIA#746 (comment) ## Root Cause The prepare script tried to distinguish between "prek intentionally absent" and "prek should be here but isn't" by checking for the `node_modules/@j178/prek` directory. However, this distinction is unreliable — the directory can exist without the binary being available (e.g., after `--omit=dev` with a stale `node_modules`). ## Fix Remove the `elif [ -d node_modules/@j178/prek ]` branch entirely. If `prek` is not in PATH, simply skip hook setup regardless of whether the package directory exists. **Before:** ```bash if [ -d .git ]; then if command -v prek >/dev/null 2>&1; then prek install; elif [ -d node_modules/@j178/prek ]; then echo "ERROR: ..." && exit 1; # ← BUG else echo "Skipping git hook setup (prek not installed)"; fi fi ``` **After:** ```bash if [ -d .git ]; then if command -v prek >/dev/null 2>&1; then prek install; else echo "Skipping git hook setup (prek not installed)"; fi fi ``` ## Test Scenarios | Scenario | Expected | Result | |----------|----------|--------| | `.git` exists + `prek` in PATH | Runs `prek install` | ✅ | | `.git` exists + `prek` not in PATH + `node_modules/@j178/prek` exists | Skip (no error) | ✅ (was ❌ `exit 1`) | | `.git` exists + `prek` not in PATH + no `node_modules` | Skip | ✅ | | No `.git` directory | Skip | ✅ | Fixes regression from NVIDIA#746. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Simplified the installation preparation script to streamline git hook setup. When the required tooling isn't available, the script now gracefully skips hook configuration (and logs a skip) instead of failing, reducing setup friction for users. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Carlos Villela <cvillela@nvidia.com>
## Problem PR NVIDIA#746 (merged) made `prek` optional in the prepare script, but introduced a regression: when `node_modules/@j178/prek` directory exists but the `prek` binary is not in PATH, the script errors with `exit 1`. This happens in practice when running `npm install --omit=dev` (as the NemoClaw install script does) — the package directory may be present from a previous full install, but the binary won't be linked to PATH. Reported by @DanTup on a clean Ubuntu VM: NVIDIA#746 (comment) ## Root Cause The prepare script tried to distinguish between "prek intentionally absent" and "prek should be here but isn't" by checking for the `node_modules/@j178/prek` directory. However, this distinction is unreliable — the directory can exist without the binary being available (e.g., after `--omit=dev` with a stale `node_modules`). ## Fix Remove the `elif [ -d node_modules/@j178/prek ]` branch entirely. If `prek` is not in PATH, simply skip hook setup regardless of whether the package directory exists. **Before:** ```bash if [ -d .git ]; then if command -v prek >/dev/null 2>&1; then prek install; elif [ -d node_modules/@j178/prek ]; then echo "ERROR: ..." && exit 1; # ← BUG else echo "Skipping git hook setup (prek not installed)"; fi fi ``` **After:** ```bash if [ -d .git ]; then if command -v prek >/dev/null 2>&1; then prek install; else echo "Skipping git hook setup (prek not installed)"; fi fi ``` ## Test Scenarios | Scenario | Expected | Result | |----------|----------|--------| | `.git` exists + `prek` in PATH | Runs `prek install` | ✅ | | `.git` exists + `prek` not in PATH + `node_modules/@j178/prek` exists | Skip (no error) | ✅ (was ❌ `exit 1`) | | `.git` exists + `prek` not in PATH + no `node_modules` | Skip | ✅ | | No `.git` directory | Skip | ✅ | Fixes regression from NVIDIA#746. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Simplified the installation preparation script to streamline git hook setup. When the required tooling isn't available, the script now gracefully skips hook configuration (and logs a skip) instead of failing, reducing setup friction for users. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Carlos Villela <cvillela@nvidia.com>
Problem
PR #746 (merged) made
prekoptional in the prepare script, but introduced a regression: whennode_modules/@j178/prekdirectory exists but theprekbinary is not in PATH, the script errors withexit 1.This happens in practice when running
npm install --omit=dev(as the NemoClaw install script does) — the package directory may be present from a previous full install, but the binary won't be linked to PATH.Reported by @DanTup on a clean Ubuntu VM: #746 (comment)
Root Cause
The prepare script tried to distinguish between "prek intentionally absent" and "prek should be here but isn't" by checking for the
node_modules/@j178/prekdirectory. However, this distinction is unreliable — the directory can exist without the binary being available (e.g., after--omit=devwith a stalenode_modules).Fix
Remove the
elif [ -d node_modules/@j178/prek ]branch entirely. Ifprekis not in PATH, simply skip hook setup regardless of whether the package directory exists.Before:
After:
Test Scenarios
.gitexists +prekin PATHprek install.gitexists +preknot in PATH +node_modules/@j178/prekexistsexit 1).gitexists +preknot in PATH + nonode_modules.gitdirectoryFixes regression from #746.
Summary by CodeRabbit