Skip to content

Commit fe0e231

Browse files
authored
Merge branch 'main' into test/e2e-varlet
2 parents 5350bef + 91ed541 commit fe0e231

213 files changed

Lines changed: 369 additions & 669 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/vite_global_cli/src/cli.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2102,8 +2102,7 @@ fn print_runtime_header(show_header: bool) {
21022102
if !show_header {
21032103
return;
21042104
}
2105-
println!("{}", vite_shared::header::vite_plus_header());
2106-
println!();
2105+
vite_shared::header::print_header();
21072106
}
21082107

21092108
/// Build a clap Command with custom help formatting matching the JS CLI output.
@@ -2120,7 +2119,7 @@ pub fn command_with_help_with_options(render_options: RenderOptions) -> clap::Co
21202119
fn apply_custom_help(cmd: clap::Command, render_options: RenderOptions) -> clap::Command {
21212120
let after_help = help::render_help_doc(&help::top_level_help_doc());
21222121
let options_heading = help::render_heading("Options");
2123-
let header = if render_options.show_header {
2122+
let header = if render_options.show_header && vite_shared::header::should_print_header() {
21242123
vite_shared::header::vite_plus_header()
21252124
} else {
21262125
String::new()

crates/vite_global_cli/src/commands/env/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ use crate::{
3232
};
3333

3434
fn print_env_header() {
35-
println!("{}", vite_shared::header::vite_plus_header());
36-
println!();
35+
vite_shared::header::print_header();
3736
}
3837

3938
fn should_print_env_header(subcommand: &EnvSubcommands) -> bool {
@@ -140,8 +139,7 @@ pub async fn execute(cwd: AbsolutePathBuf, args: EnvArgs) -> Result<ExitStatus,
140139
if !crate::help::print_unified_clap_help_for_path(&["env"]) {
141140
// Fallback to clap's built-in help printer if unified rendering fails.
142141
use clap::CommandFactory;
143-
println!("{}", vite_shared::header::vite_plus_header());
144-
println!();
142+
vite_shared::header::print_header();
145143
crate::cli::Args::command()
146144
.find_subcommand("env")
147145
.unwrap()

crates/vite_global_cli/src/commands/version.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ fn detect_system_node_version() -> Option<String> {
161161

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

167166
println!("vp v{}", env!("CARGO_PKG_VERSION"));
168167
println!();

crates/vite_global_cli/src/help.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -993,8 +993,7 @@ pub fn maybe_print_unified_clap_subcommand_help(argv: &[String]) -> bool {
993993
}
994994

995995
if command_path.len() == 1 && command_path[0] == "env" {
996-
println!("{}", vite_shared::header::vite_plus_header());
997-
println!();
996+
vite_shared::header::print_header();
998997
println!("{}", render_help_doc(&env_help_doc()));
999998
return true;
1000999
}
@@ -1024,17 +1023,15 @@ pub fn maybe_print_unified_delegate_help(
10241023
};
10251024

10261025
if show_header {
1027-
println!("{}", vite_shared::header::vite_plus_header());
1028-
println!();
1026+
vite_shared::header::print_header();
10291027
}
10301028
println!("{}", render_help_doc(&doc));
10311029
true
10321030
}
10331031

10341032
pub fn print_unified_clap_help_for_path(command_path: &[&str]) -> bool {
10351033
if command_path == ["env"] {
1036-
println!("{}", vite_shared::header::vite_plus_header());
1037-
println!();
1034+
vite_shared::header::print_header();
10381035
println!("{}", render_help_doc(&env_help_doc()));
10391036
return true;
10401037
}
@@ -1057,8 +1054,7 @@ pub fn print_unified_clap_help_for_path(command_path: &[&str]) -> bool {
10571054
..doc
10581055
};
10591056

1060-
println!("{}", vite_shared::header::vite_plus_header());
1061-
println!();
1057+
vite_shared::header::print_header();
10621058
println!("{}", render_owned_help_doc(&doc));
10631059
true
10641060
}

crates/vite_global_cli/src/main.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ fn extract_invalid_subcommand_details(error: &clap::Error) -> Option<InvalidSubc
116116
}
117117

118118
fn print_invalid_subcommand_error(details: &InvalidSubcommandDetails) {
119-
println!("{}", vite_shared::header::vite_plus_header());
120-
println!();
119+
vite_shared::header::print_header();
121120

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

240-
println!("{}", vite_shared::header::vite_plus_header());
241-
println!();
239+
vite_shared::header::print_header();
242240

243241
let highlighted_argument = invalid_argument.bright_blue().to_string();
244242
output::error(&format!("Unexpected argument '{highlighted_argument}'"));

crates/vite_shared/src/header.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,36 @@ pub fn vite_plus_header() -> String {
536536
render_header_variant(header_colors.blue, &header_colors.suffix_gradient, true, true)
537537
}
538538

539+
/// Whether the Vite+ banner should be emitted in the current environment.
540+
///
541+
/// The banner is cosmetic and assumes an interactive terminal; it's
542+
/// suppressed when:
543+
/// - stdout is piped or redirected (lefthook/husky, `execSync`, CI, pagers).
544+
/// - a git commit-flow hook is running. Direct shell hooks inherit the
545+
/// terminal for stdout, so the TTY check alone doesn't catch them; git
546+
/// sets `GIT_INDEX_FILE` for pre-commit / commit-msg / prepare-commit-msg,
547+
/// which is where `vp check --fix` typically runs.
548+
#[must_use]
549+
pub fn should_print_header() -> bool {
550+
if !std::io::stdout().is_terminal() {
551+
return false;
552+
}
553+
if std::env::var_os("GIT_INDEX_FILE").is_some() {
554+
return false;
555+
}
556+
true
557+
}
558+
559+
/// Emit the Vite+ banner (header line + trailing blank line) to stdout, but
560+
/// only when the environment is interactive. No-op otherwise.
561+
pub fn print_header() {
562+
if !should_print_header() {
563+
return;
564+
}
565+
println!("{}", vite_plus_header());
566+
println!();
567+
}
568+
539569
#[cfg(all(test, unix))]
540570
mod tests {
541571
use std::io::{BufReader, Cursor};

packages/cli/binding/index.cjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,4 +775,5 @@ module.exports.rewritePrettier = nativeBinding.rewritePrettier;
775775
module.exports.rewriteScripts = nativeBinding.rewriteScripts;
776776
module.exports.run = nativeBinding.run;
777777
module.exports.runCommand = nativeBinding.runCommand;
778+
module.exports.shouldPrintVitePlusHeader = nativeBinding.shouldPrintVitePlusHeader;
778779
module.exports.vitePlusHeader = nativeBinding.vitePlusHeader;

packages/cli/binding/index.d.cts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,5 +369,13 @@ export interface RunCommandResult {
369369
pathAccesses: Record<string, PathAccess>;
370370
}
371371

372+
/**
373+
* Whether the Vite+ banner should be emitted in the current environment.
374+
*
375+
* Mirrors `vite_shared::header::should_print_header` so both CLIs apply
376+
* the same TTY + git-hook gating without duplicating the rules in JS.
377+
*/
378+
export declare function shouldPrintVitePlusHeader(): boolean;
379+
372380
/** Render the Vite+ header using the Rust implementation. */
373381
export declare function vitePlusHeader(): string;

packages/cli/binding/src/cli/help.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,16 @@ fn print_unknown_argument_error(error: &clap::Error) -> bool {
169169
}
170170

171171
pub(super) fn print_help() {
172-
let header = vite_shared::header::vite_plus_header();
172+
let header = if vite_shared::header::should_print_header() {
173+
format!("{}\n\n", vite_shared::header::vite_plus_header())
174+
} else {
175+
String::new()
176+
};
173177
let bold = "\x1b[1m";
174178
let bold_underline = "\x1b[1;4m";
175179
let reset = "\x1b[0m";
176180
println!(
177-
"{header}
178-
179-
{bold_underline}Usage:{reset} {bold}vp{reset} <COMMAND>
181+
"{header}{bold_underline}Usage:{reset} {bold}vp{reset} <COMMAND>
180182
181183
{bold_underline}Core Commands:{reset}
182184
{bold}dev{reset} Run the development server

packages/cli/binding/src/lib.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,12 @@ pub async fn run(options: CliOptions) -> Result<i32> {
215215
pub fn vite_plus_header() -> String {
216216
vite_shared::header::vite_plus_header()
217217
}
218+
219+
/// Whether the Vite+ banner should be emitted in the current environment.
220+
///
221+
/// Mirrors `vite_shared::header::should_print_header` so both CLIs apply
222+
/// the same TTY + git-hook gating without duplicating the rules in JS.
223+
#[napi]
224+
pub fn should_print_vite_plus_header() -> bool {
225+
vite_shared::header::should_print_header()
226+
}

0 commit comments

Comments
 (0)