Skip to content

fix(command): resolve relative PATH entries against cwd - #2350

Open
RSS1102 wants to merge 15 commits into
voidzero-dev:mainfrom
RSS1102:rss1102/fix-relative-path-bin-resolution
Open

fix(command): resolve relative PATH entries against cwd#2350
RSS1102 wants to merge 15 commits into
voidzero-dev:mainfrom
RSS1102:rss1102/fix-relative-path-bin-resolution

Conversation

@RSS1102

@RSS1102 RSS1102 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • resolve relative PATH entries against the command cwd before binary lookup
  • preserve PATH ordering, empty entries, and ~ expansion semantics
  • defensively normalize the resolved binary path
  • cover relative matches, fallback search, empty PATH entries, and tilde preservation

Problem

which::which_in searches relative PATH entries against the process cwd rather than the cwd supplied for the command. The npm-distributed CLI can therefore fail to resolve node when Vite+ git hooks prepend ./node_modules/.bin, even though the binary exists.

Validation

  • cargo test -p vp_command (17 passed)
  • cargo test -p vp_global_cli relative_path_entry (1 passed)
  • cargo clippy -p vp_command --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check
  • reproduced the failure with vite-plus@0.2.7 and a relative PATH entry, then verified the same command reaches vp check with the patched NAPI binding

Fixes #2326

@netlify

netlify Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploy Preview for viteplus-preview canceled.

Name Link
🔨 Latest commit 25e781f
🔍 Latest deploy log https://app.netlify.com/projects/viteplus-preview/deploys/6a82ac7d3a764a0008a265b7

@RSS1102
RSS1102 marked this pull request as ready for review August 6, 2026 03:21
@RSS1102
RSS1102 force-pushed the rss1102/fix-relative-path-bin-resolution branch from b6e28ea to 990e718 Compare August 6, 2026 03:27
@RSS1102
RSS1102 marked this pull request as draft August 6, 2026 03:27
@RSS1102
RSS1102 marked this pull request as ready for review August 6, 2026 06:47
@fengmk2

fengmk2 commented Aug 6, 2026

Copy link
Copy Markdown
Member

@RSS1102 Can you add a snapshot test to cover this bug fix change?

@RSS1102
RSS1102 marked this pull request as draft August 7, 2026 02:45
@RSS1102
RSS1102 force-pushed the rss1102/fix-relative-path-bin-resolution branch from 7abfc83 to 4e44ec1 Compare August 7, 2026 02:55
@RSS1102
RSS1102 marked this pull request as ready for review August 8, 2026 12:58
@RSS1102 RSS1102 closed this Aug 8, 2026
@RSS1102 RSS1102 reopened this Aug 8, 2026
@fengmk2

fengmk2 commented Aug 9, 2026

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 2f15b4260e

ℹ️ 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".

@fengmk2 fengmk2 self-assigned this Aug 9, 2026
Comment thread crates/vp_command/src/lib.rs Outdated
@fengmk2

fengmk2 commented Aug 11, 2026

Copy link
Copy Markdown
Member

@codex review

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

Copy link
Copy Markdown

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: af66713e7c

ℹ️ 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 thread crates/vp_command/src/lib.rs Outdated
@fengmk2

fengmk2 commented Aug 11, 2026

Copy link
Copy Markdown
Member

@codex review

@fengmk2 fengmk2 added test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: create-e2e Run `vp create` e2e tests test: sfw labels Aug 11, 2026

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

Copy link
Copy Markdown

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: fb1cd60261

ℹ️ 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 thread crates/vp_command/src/lib.rs
@RSS1102

RSS1102 commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@fengmk2 pls review again when you have time

@fengmk2 fengmk2 added the preview-build Publish this PR's commits to the registry bridge as preview builds label Aug 15, 2026
current_path = std::env::var_os("PATH").unwrap_or_default();
&current_path
};
let path = which::which_in(bin_name, Some(path_env), cwd.as_ref())

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One concern is that this changes a single which_in call into multiple calls, one for each PATH entry.

Is there any way to keep a single which_in call, or would that require fixing which itself to resolve relative PATH entries against the provided cwd?

Like:

let path = normalized_entries
    .map(|entry| {
        if is_plain_relative_path(&entry) {
            cwd.join(entry)
        } else {
            entry
        }
    });

let path_env = std::env::join_paths(path)?;

which::which_in(bin_name, Some(path_env), cwd)

@RSS1102 RSS1102 Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree that a single which_in call would be preferable.

However, normalizing the PATH locally still requires special handling for tilde entries and a fallback when join_paths fails, such as when a Unix cwd contains :. That would add more than ten lines while still retaining the current per-entry lookup as a fallback.

I’ve opened an upstream PR to address this in which itself:

I suggest keeping the current workaround with a TODO, then simplifying it to one which_in call after the upstream release. If you prefer to wait for that release, please let me know.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. After the PR is merged, you can create a follow-up issue to track it.

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

Labels

preview-build Publish this PR's commits to the registry bridge as preview builds test: create-e2e Run `vp create` e2e tests test: e2e Auto run e2e tests test: install-e2e run vite install e2e test test: sfw

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vp cannot resolve node through a relative PATH entry — breaks Vite+'s own git hooks

2 participants