Skip to content

fix(cli): add managed bin to hook path#1647

Open
TheAlexLichter wants to merge 1 commit into
mainfrom
fix/hook-managed-node-path
Open

fix(cli): add managed bin to hook path#1647
TheAlexLichter wants to merge 1 commit into
mainfrom
fix/hook-managed-node-path

Conversation

@TheAlexLichter
Copy link
Copy Markdown
Member

@TheAlexLichter TheAlexLichter commented May 20, 2026

When committing via VS Code on MacOS I hit the error

./node_modules/.bin/vp: line 20: exec: node: not found
VITE+ - pre-commit script failed (code 127)
VITE+ - command not found in PATH=./node_modules/.bin:/Library/Developer/CommandLineTools/usr/libexec/git-core:/usr/bin:/bin:/usr/sbin:/sbin

But node was installed and vp env doctor was happy.
The issues seemed that the managed Node is not available in the Git hook.

I learned that Git hooks often run with a much smaller, non-interactive PATH, possibly not including the shims.
In my case, path was limited to what is shared in the error above. That included the local vp bin but not node, leading to the error.

The PR fixes that by making generated hooks add Vite+’s managed bin directory before running the user hook. Then vp staged can start even when Git launches the hook with a restricted PATH.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 20, 2026

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit 66db44e
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a0e0cf4f8b26000082af74c

@TheAlexLichter TheAlexLichter force-pushed the fix/hook-managed-node-path branch from 05e3832 to 66db44e Compare May 20, 2026 19:35
@TheAlexLichter TheAlexLichter marked this pull request as ready for review May 20, 2026 19:42
@TheAlexLichter TheAlexLichter requested a review from fengmk2 May 20, 2026 19:42
@fengmk2
Copy link
Copy Markdown
Member

fengmk2 commented May 21, 2026

@codex review

Copy link
Copy Markdown
Member

@fengmk2 fengmk2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TheAlexLichter Thanks! 💯

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66db44e7e1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +59 to 61
[ -n "$__vp_bin" ] && [ -d "$__vp_bin" ] && export PATH="$__vp_bin:$PATH"
d=${rootExpr}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Compute repo root before prepending VP_HOME/bin

Prepending VP_HOME/bin to PATH before evaluating d=${rootExpr} lets any shim in VP_HOME/bin override core utilities used in rootExpr (notably dirname), so users who installed a global package that exposes dirname can get an incorrect d and therefore an incorrect node_modules/.bin path. In that case local hook commands may resolve to the wrong binaries or fail with command not found; moving the d=${rootExpr} computation before this PATH mutation (or invoking dirname via a safe/system path) avoids this regression.

Useful? React with 👍 / 👎.

d=${rootExpr}
export PATH="$d/node_modules/.bin:$PATH"
sh -e "$s" "$@"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Invoke a trusted shell instead of PATH-resolved sh

Because VP_HOME/bin is prepended to PATH, the final sh -e "$s" "$@" call now resolves sh through that user-controlled directory before the system path. If a global shim/binary named sh exists in VP_HOME/bin, the hook dispatcher runs that program instead of a POSIX shell, so hooks can fail or execute unintended logic. Using an absolute shell path (or computing and invoking a trusted shell before mutating PATH) prevents this breakage.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants