fix(cli): add managed bin to hook path#1647
Conversation
✅ Deploy Preview for viteplus-preview canceled.
|
05e3832 to
66db44e
Compare
|
@codex review |
There was a problem hiding this comment.
💡 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".
| [ -n "$__vp_bin" ] && [ -d "$__vp_bin" ] && export PATH="$__vp_bin:$PATH" | ||
| d=${rootExpr} |
There was a problem hiding this comment.
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" "$@" |
There was a problem hiding this comment.
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 👍 / 👎.
When committing via VS Code on MacOS I hit the error
But node was installed and
vp env doctorwas 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
vpbin but notnode, 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 stagedcan start even when Git launches the hook with a restricted PATH.