Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 2 additions & 3 deletions crates/vite_global_cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2102,8 +2102,7 @@ fn print_runtime_header(show_header: bool) {
if !show_header {
return;
}
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
}

/// Build a clap Command with custom help formatting matching the JS CLI output.
Expand All @@ -2120,7 +2119,7 @@ pub fn command_with_help_with_options(render_options: RenderOptions) -> clap::Co
fn apply_custom_help(cmd: clap::Command, render_options: RenderOptions) -> clap::Command {
let after_help = help::render_help_doc(&help::top_level_help_doc());
let options_heading = help::render_heading("Options");
let header = if render_options.show_header {
let header = if render_options.show_header && vite_shared::header::should_print_header() {
vite_shared::header::vite_plus_header()
} else {
String::new()
Expand Down
6 changes: 2 additions & 4 deletions crates/vite_global_cli/src/commands/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ use crate::{
};

fn print_env_header() {
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
}

fn should_print_env_header(subcommand: &EnvSubcommands) -> bool {
Expand Down Expand Up @@ -140,8 +139,7 @@ pub async fn execute(cwd: AbsolutePathBuf, args: EnvArgs) -> Result<ExitStatus,
if !crate::help::print_unified_clap_help_for_path(&["env"]) {
// Fallback to clap's built-in help printer if unified rendering fails.
use clap::CommandFactory;
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
crate::cli::Args::command()
.find_subcommand("env")
.unwrap()
Expand Down
3 changes: 1 addition & 2 deletions crates/vite_global_cli/src/commands/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ fn detect_system_node_version() -> Option<String> {

/// Execute the `--version` command.
pub async fn execute(cwd: AbsolutePathBuf) -> Result<ExitStatus, Error> {
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();

println!("vp v{}", env!("CARGO_PKG_VERSION"));
println!();
Expand Down
12 changes: 4 additions & 8 deletions crates/vite_global_cli/src/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,7 @@ pub fn maybe_print_unified_clap_subcommand_help(argv: &[String]) -> bool {
}

if command_path.len() == 1 && command_path[0] == "env" {
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
println!("{}", render_help_doc(&env_help_doc()));
return true;
}
Expand Down Expand Up @@ -1024,17 +1023,15 @@ pub fn maybe_print_unified_delegate_help(
};

if show_header {
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
}
println!("{}", render_help_doc(&doc));
true
}

pub fn print_unified_clap_help_for_path(command_path: &[&str]) -> bool {
if command_path == ["env"] {
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
println!("{}", render_help_doc(&env_help_doc()));
return true;
}
Expand All @@ -1057,8 +1054,7 @@ pub fn print_unified_clap_help_for_path(command_path: &[&str]) -> bool {
..doc
};

println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();
println!("{}", render_owned_help_doc(&doc));
true
}
Expand Down
6 changes: 2 additions & 4 deletions crates/vite_global_cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@ fn extract_invalid_subcommand_details(error: &clap::Error) -> Option<InvalidSubc
}

fn print_invalid_subcommand_error(details: &InvalidSubcommandDetails) {
println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();

let highlighted_subcommand = details.invalid_subcommand.bright_blue().to_string();
output::error(&format!("Command '{highlighted_subcommand}' not found"));
Expand Down Expand Up @@ -237,8 +236,7 @@ fn print_unknown_argument_error(error: &clap::Error) -> bool {
return false;
};

println!("{}", vite_shared::header::vite_plus_header());
println!();
vite_shared::header::print_header();

let highlighted_argument = invalid_argument.bright_blue().to_string();
output::error(&format!("Unexpected argument '{highlighted_argument}'"));
Expand Down
30 changes: 30 additions & 0 deletions crates/vite_shared/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,36 @@ pub fn vite_plus_header() -> String {
render_header_variant(header_colors.blue, &header_colors.suffix_gradient, true, true)
}

/// Whether the Vite+ banner should be emitted in the current environment.
///
/// The banner is cosmetic and assumes an interactive terminal; it's
/// suppressed when:
/// - stdout is piped or redirected (lefthook/husky, `execSync`, CI, pagers).
/// - a git commit-flow hook is running. Direct shell hooks inherit the
/// terminal for stdout, so the TTY check alone doesn't catch them; git
/// sets `GIT_INDEX_FILE` for pre-commit / commit-msg / prepare-commit-msg,
/// which is where `vp check --fix` typically runs.
#[must_use]
pub fn should_print_header() -> bool {
if !std::io::stdout().is_terminal() {
return false;
}
if std::env::var_os("GIT_INDEX_FILE").is_some() {
return false;
}
true
}

/// Emit the Vite+ banner (header line + trailing blank line) to stdout, but
/// only when the environment is interactive. No-op otherwise.
pub fn print_header() {
if !should_print_header() {
return;
}
println!("{}", vite_plus_header());
println!();
}

#[cfg(all(test, unix))]
mod tests {
use std::io::{BufReader, Cursor};
Expand Down
1 change: 1 addition & 0 deletions packages/cli/binding/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -775,4 +775,5 @@ module.exports.rewritePrettier = nativeBinding.rewritePrettier;
module.exports.rewriteScripts = nativeBinding.rewriteScripts;
module.exports.run = nativeBinding.run;
module.exports.runCommand = nativeBinding.runCommand;
module.exports.shouldPrintVitePlusHeader = nativeBinding.shouldPrintVitePlusHeader;
module.exports.vitePlusHeader = nativeBinding.vitePlusHeader;
8 changes: 8 additions & 0 deletions packages/cli/binding/index.d.cts
Original file line number Diff line number Diff line change
Expand Up @@ -369,5 +369,13 @@ export interface RunCommandResult {
pathAccesses: Record<string, PathAccess>;
}

/**
* Whether the Vite+ banner should be emitted in the current environment.
*
* Mirrors `vite_shared::header::should_print_header` so both CLIs apply
* the same TTY + git-hook gating without duplicating the rules in JS.
*/
export declare function shouldPrintVitePlusHeader(): boolean;

/** Render the Vite+ header using the Rust implementation. */
export declare function vitePlusHeader(): string;
10 changes: 6 additions & 4 deletions packages/cli/binding/src/cli/help.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,16 @@ fn print_unknown_argument_error(error: &clap::Error) -> bool {
}

pub(super) fn print_help() {
let header = vite_shared::header::vite_plus_header();
let header = if vite_shared::header::should_print_header() {
format!("{}\n\n", vite_shared::header::vite_plus_header())
} else {
String::new()
};
let bold = "\x1b[1m";
let bold_underline = "\x1b[1;4m";
let reset = "\x1b[0m";
println!(
"{header}

{bold_underline}Usage:{reset} {bold}vp{reset} <COMMAND>
"{header}{bold_underline}Usage:{reset} {bold}vp{reset} <COMMAND>

{bold_underline}Core Commands:{reset}
{bold}dev{reset} Run the development server
Expand Down
9 changes: 9 additions & 0 deletions packages/cli/binding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,12 @@ pub async fn run(options: CliOptions) -> Result<i32> {
pub fn vite_plus_header() -> String {
vite_shared::header::vite_plus_header()
}

/// Whether the Vite+ banner should be emitted in the current environment.
///
/// Mirrors `vite_shared::header::should_print_header` so both CLIs apply
/// the same TTY + git-hook gating without duplicating the rules in JS.
#[napi]
pub fn should_print_vite_plus_header() -> bool {
vite_shared::header::should_print_header()
}
29 changes: 0 additions & 29 deletions packages/cli/snap-tests-global/cli-helper-message/snap.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
> vp -h # show help message
VITE+ - The Unified Toolchain for the Web

Usage: vp [COMMAND]

Expand Down Expand Up @@ -55,8 +54,6 @@ Options:
-h, --help Print help

> vp -V # show version
VITE+ - The Unified Toolchain for the Web

vp v<semver>

Local vite-plus:
Expand All @@ -76,8 +73,6 @@ Environment:
Node.js v<semver>

> vp install -h # show install help message
VITE+ - The Unified Toolchain for the Web

Usage: vp install [OPTIONS] [PACKAGES]... [-- <PASS_THROUGH_ARGS>...]

Install all dependencies, or add packages if package names are provided
Expand Down Expand Up @@ -116,8 +111,6 @@ Documentation: https://viteplus.dev/guide/install


> vp add -h # show add help message
VITE+ - The Unified Toolchain for the Web

Usage: vp add [OPTIONS] <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]

Add packages to dependencies
Expand Down Expand Up @@ -146,8 +139,6 @@ Documentation: https://viteplus.dev/guide/install


> vp remove -h # show remove help message
VITE+ - The Unified Toolchain for the Web

Usage: vp remove [OPTIONS] <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]

Remove packages from dependencies
Expand All @@ -171,8 +162,6 @@ Documentation: https://viteplus.dev/guide/install


> vp update -h # show update help message
VITE+ - The Unified Toolchain for the Web

Usage: vp update [OPTIONS] [PACKAGES]... [-- <PASS_THROUGH_ARGS>...]

Update packages to their latest versions
Expand All @@ -199,8 +188,6 @@ Documentation: https://viteplus.dev/guide/install


> vp link -h # show link help message
VITE+ - The Unified Toolchain for the Web

Usage: vp link [PACKAGE|DIR] [ARGS]...

Link packages for local development
Expand All @@ -216,8 +203,6 @@ Documentation: https://viteplus.dev/guide/install


> vp unlink -h # show unlink help message
VITE+ - The Unified Toolchain for the Web

Usage: vp unlink [OPTIONS] [PACKAGE|DIR] [ARGS]...

Unlink packages
Expand All @@ -234,8 +219,6 @@ Documentation: https://viteplus.dev/guide/install


> vp dedupe -h # show dedupe help message
VITE+ - The Unified Toolchain for the Web

Usage: vp dedupe [OPTIONS] [-- <PASS_THROUGH_ARGS>...]

Deduplicate dependencies
Expand All @@ -251,8 +234,6 @@ Documentation: https://viteplus.dev/guide/install


> vp outdated -h # show outdated help message
VITE+ - The Unified Toolchain for the Web

Usage: vp outdated [OPTIONS] [PACKAGES]... [-- <PASS_THROUGH_ARGS>...]

Check for outdated packages
Expand All @@ -279,8 +260,6 @@ Documentation: https://viteplus.dev/guide/install


> vp why -h # show why help message
VITE+ - The Unified Toolchain for the Web

Usage: vp why [OPTIONS] <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]

Show why a package is installed
Expand Down Expand Up @@ -309,8 +288,6 @@ Documentation: https://viteplus.dev/guide/install


> vp info -h # show info help message
VITE+ - The Unified Toolchain for the Web

Usage: vp info [OPTIONS] <PACKAGE> [FIELD] [-- <PASS_THROUGH_ARGS>...]

View package information from the registry
Expand All @@ -328,8 +305,6 @@ Documentation: https://viteplus.dev/guide/install


> vp pm -h # show pm help message
VITE+ - The Unified Toolchain for the Web

Usage: vp pm <COMMAND>

Forward a command to the package manager
Expand Down Expand Up @@ -362,8 +337,6 @@ Documentation: https://viteplus.dev/guide/install


> vp env # show env help message
VITE+ - The Unified Toolchain for the Web

Usage: vp env [COMMAND]

Manage Node.js versions
Expand Down Expand Up @@ -423,8 +396,6 @@ Documentation: https://viteplus.dev/guide/env


> vp upgrade -h # show upgrade help message
VITE+ - The Unified Toolchain for the Web

Usage: vp upgrade [OPTIONS] [VERSION]

Update vp itself to the latest version
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/snap-tests-global/command-add-bun/snap.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
> vp add --help # should show help
VITE+ - The Unified Toolchain for the Web

Usage: vp add [OPTIONS] <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]

Add packages to dependencies
Expand Down Expand Up @@ -71,8 +69,6 @@ installed test-vite-plus-install@<semver>
}

> vp install test-vite-plus-package@1.0.0 --save-peer && cat package.json # should install package alias for add
VITE+ - The Unified Toolchain for the Web

bun add v<semver> (af24e281)

installed test-vite-plus-package@<semver>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ up to date in <variable>ms
}

> vp install test-vite-plus-package@1.0.0 --filter "*" --workspace-root -- --no-audit && cat package.json packages/app/package.json packages/utils/package.json # should install packages alias for add command
VITE+ - The Unified Toolchain for the Web


added 1 package in <variable>ms
{
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/snap-tests-global/command-add-npm10/snap.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
> vp add --help # should show help
VITE+ - The Unified Toolchain for the Web

Usage: vp add [OPTIONS] <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]

Add packages to dependencies
Expand Down Expand Up @@ -56,8 +54,6 @@ added 1 package in <variable>ms
}

> vp install test-vite-plus-package@1.0.0 --save-peer -- --no-audit && cat package.json # should install package alias for add
VITE+ - The Unified Toolchain for the Web


added 1 package in <variable>ms
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ up to date in <variable>ms
}

> vp install test-vite-plus-package@1.0.0 --filter "*" --workspace-root -- --no-audit && cat package.json packages/app/package.json packages/utils/package.json # should install packages alias for add command
VITE+ - The Unified Toolchain for the Web


added 1 package in <variable>ms
{
Expand Down
4 changes: 0 additions & 4 deletions packages/cli/snap-tests-global/command-add-npm11/snap.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
> vp add --help # should show help
VITE+ - The Unified Toolchain for the Web

Usage: vp add [OPTIONS] <PACKAGES>... [-- <PASS_THROUGH_ARGS>...]

Add packages to dependencies
Expand Down Expand Up @@ -56,8 +54,6 @@ added 1 package in <variable>ms
}

> vp install test-vite-plus-package@1.0.0 --save-peer -- --no-audit && cat package.json # should install package alias for add
VITE+ - The Unified Toolchain for the Web


added 1 package in <variable>ms
{
Expand Down
Loading
Loading