-
Notifications
You must be signed in to change notification settings - Fork 217
feat(cli): advertise VP_USER_AGENT to child processes #1958
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,8 +294,29 @@ fn print_unknown_argument_error(error: &clap::Error) -> bool { | |
| true | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> ExitCode { | ||
| fn main() -> ExitCode { | ||
| // Advertise that this process tree is running under Vite+ so the tools we | ||
| // invoke (e.g. `vp dlx create-vite`) can detect vp as the package manager. | ||
| // The underlying package managers overwrite `npm_config_user_agent` with | ||
| // their own value, so we expose a dedicated variable that is passed through | ||
| // untouched and inherited by every child process (including the `npx` | ||
| // fallback used when there is no local `package.json`). Shim mode clears it | ||
| // again below, since there the user invokes the wrapped tool, not vp. | ||
| // | ||
| // SAFETY: `set_var` must run while the process is still single-threaded. | ||
| // This is the first statement in `main`, before the async runtime (and its | ||
| // worker threads) are created. | ||
| unsafe { | ||
| std::env::set_var( | ||
| vite_shared::env_vars::VP_USER_AGENT, | ||
| concat!("vp/", env!("CARGO_PKG_VERSION")), | ||
| ); | ||
|
Comment on lines
+310
to
+313
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This only runs in the Rust global binary, but the published Useful? React with 👍 / 👎.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed this is a real consistency gap. Tracing it: user-facing So I'd prefer not to duplicate the marker into the JS launcher here; the clean fix is to unify that path onto |
||
| } | ||
|
|
||
| tokio::runtime::Runtime::new().expect("failed to build tokio runtime").block_on(run()) | ||
| } | ||
|
|
||
| async fn run() -> ExitCode { | ||
| // Initialize tracing | ||
| vite_shared::init_tracing(); | ||
|
|
||
|
|
@@ -317,6 +338,11 @@ async fn main() -> ExitCode { | |
| if let Some(tool) = shim::detect_shim_tool(argv0) { | ||
| // Shim mode - dispatch to the appropriate tool. stdout belongs to the | ||
| // wrapped tool; route vp's own output to stderr. | ||
| // | ||
| // The user is invoking the wrapped tool (e.g. `npm`/`npx`), not vp, so | ||
| // don't advertise vp to it or its children. Clear the marker set in | ||
| // `main` before dispatching. SAFETY: see the `set_var` in `main`. | ||
| unsafe { std::env::remove_var(vite_shared::env_vars::VP_USER_AGENT) }; | ||
| output::route_user_output_to_stderr(); | ||
| let exit_code = shim::dispatch(&tool, &args[1..]).await; | ||
| return ExitCode::from(exit_code as u8); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is set before shim detection, any invocation through the managed
npm/npxshims also exportsVP_USER_AGENTbeforerun()reachesshim::detect_shim_tool; in system-first mode this even survives when vp immediately execs the system package manager. A user runningnpx create-vitethrough Vite+'s shims is not usingvp dlx, but create-vite will still seeVP_USER_AGENT=vp/...and can scaffold commands forvpinstead of the package manager the user actually invoked. Set this only on the normalvpcommand path, or clear it before dispatching shim invocations.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, fixed in deeab22.
VP_USER_AGENTis now cleared in the shim branch beforeshim::dispatch, so when vp runs as a managed npm/npx/node shim the wrapped tool and its children no longer see it. Verified:VP_SHIM_TOOL=node vp -e ...showsundefined, whilevp dlx ... node -e ...still showsvp/0.2.1.