Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions crates/vite_global_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,28 @@ 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`).
//
// 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 thread
fengmk2 marked this conversation as resolved.
Outdated
Comment thread
fengmk2 marked this conversation as resolved.
Outdated
}

tokio::runtime::Runtime::new().expect("failed to build tokio runtime").block_on(run())
}

async fn run() -> ExitCode {
// Initialize tracing
vite_shared::init_tracing();

Expand Down
7 changes: 7 additions & 0 deletions crates/vite_shared/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ pub const VP_CLI_BIN: &str = "VP_CLI_BIN";
/// Global CLI version, passed from Rust binary to JS for --version display.
pub const VP_GLOBAL_VERSION: &str = "VP_GLOBAL_VERSION";

/// Advertises that the process tree is running under Vite+ (value: `vp/<version>`).
///
/// Set once at startup and inherited by every child process. Tools we invoke
/// (e.g. `vp dlx create-vite`) read it to detect vp as the package manager,
/// since the underlying package manager overwrites `npm_config_user_agent`.
pub const VP_USER_AGENT: &str = "VP_USER_AGENT";

// ── HTTP client TLS / CA configuration ──────────────────────────────────

/// Path to a PEM bundle of extra CA certificates to trust for HTTPS.
Expand Down
Loading