Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Changelog

- **Added** `-s`/`--silent` flag to suppress `vp run`'s own output (command line, cache-status indicators, and summary), leaving only the tasks' output ([#429](https://github.com/voidzero-dev/vite-task/pull/429))
- **Added** A task's `env` and `untrackedEnv` glob patterns now support `!` negation: a `!`-prefixed pattern excludes matching variables (e.g. `["VITE_*", "!VITE_SECRET"]` tracks every `VITE_*` except `VITE_SECRET`) ([#425](https://github.com/voidzero-dev/vite-task/pull/425))
- **Fixed** `package.json` and `pnpm-workspace.yaml` files with a UTF-8 BOM no longer fail to parse ([#424](https://github.com/voidzero-dev/vite-task/pull/424))
- **Changed** `vp run --filter <expr>` now exits 0 with a warning when the filter matches no packages, matching pnpm. Use `--fail-if-no-match` to restore the previous strict behavior ([#393](https://github.com/voidzero-dev/vite-task/pull/393))
Expand Down
5 changes: 5 additions & 0 deletions crates/vite_task/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ pub struct RunFlags {
#[clap(default_value = "false", short = 'v', long)]
pub verbose: bool,

/// Suppress the runner's own output: the per-task command line, cache-status
/// indicators, and the run summary. The tasks' own output is unaffected.
#[clap(default_value = "false", short = 's', long, conflicts_with = "verbose")]
pub silent: bool,

/// Force caching on for all tasks and scripts.
#[clap(long, conflicts_with = "no_cache")]
pub cache: bool,
Expand Down
11 changes: 11 additions & 0 deletions crates/vite_task/src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ impl<'a> Session<'a> {
/// # Panics
///
/// Panics if parsing a hardcoded bare `RunCommand` fails (should never happen).
#[expect(
clippy::too_many_lines,
reason = "single dispatch point that plans the command and wires up the reporter pipeline"
)]
async fn main_inner(&mut self, command: Command) -> Result<(), SessionError> {
match command.into_resolved() {
ResolvedCommand::Cache { ref subcmd } => self.handle_cache_command(subcmd),
Expand Down Expand Up @@ -335,6 +339,9 @@ impl<'a> Session<'a> {
stderr: stderr_supports_color(),
};

// `--silent` suppresses the per-task command line and summary.
let silent = run_command.flags.silent;

let inner: Box<dyn reporter::GraphExecutionReporterBuilder> = match run_command
.flags
.log
Expand All @@ -343,16 +350,19 @@ impl<'a> Session<'a> {
Arc::clone(&workspace_path),
writer,
color_support,
silent,
)),
crate::cli::LogMode::Labeled => Box::new(LabeledReporterBuilder::new(
Arc::clone(&workspace_path),
writer,
color_support,
silent,
)),
crate::cli::LogMode::Grouped => Box::new(GroupedReporterBuilder::new(
Arc::clone(&workspace_path),
writer,
color_support,
silent,
)),
};

Expand All @@ -364,6 +374,7 @@ impl<'a> Session<'a> {
Some(self.make_summary_writer()),
self.program_name.clone(),
color_support,
silent,
));
// Don't let SIGINT/CTRL_C kill the runner. Child tasks receive
// the signal directly from the terminal driver and handle it
Expand Down
55 changes: 38 additions & 17 deletions crates/vite_task/src/session/reporter/grouped/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct GroupedReporterBuilder {
workspace_path: Arc<AbsolutePath>,
writer: Box<dyn Write>,
color_support: ColorSupport,
silent: bool,
}

impl GroupedReporterBuilder {
Expand All @@ -30,12 +31,18 @@ impl GroupedReporterBuilder {
/// `LeafExecutionReporter::start`) strip ANSI on the way into the buffer,
/// so by the time the buffer reaches `writer` it already matches the
/// terminal's colour capability. `writer` is therefore stored unwrapped.
///
/// `silent` suppresses the runner's chrome — the labeled command line /
/// cache indicator emitted in `LeafExecutionReporter::start` and the
/// `── [pkg#task] ──` block header — leaving just the buffered task output;
/// error banners are unaffected.
pub fn new(
workspace_path: Arc<AbsolutePath>,
writer: Box<dyn Write>,
color_support: ColorSupport,
silent: bool,
) -> Self {
Self { workspace_path, writer, color_support }
Self { workspace_path, writer, color_support, silent }
}
}

Expand All @@ -45,6 +52,7 @@ impl GraphExecutionReporterBuilder for GroupedReporterBuilder {
writer: Rc::new(RefCell::new(self.writer)),
workspace_path: self.workspace_path,
color_support: self.color_support,
silent: self.silent,
})
}
}
Expand All @@ -53,6 +61,7 @@ struct GroupedGraphReporter {
writer: Rc<RefCell<Box<dyn Write>>>,
workspace_path: Arc<AbsolutePath>,
color_support: ColorSupport,
silent: bool,
}

impl GraphExecutionReporter for GroupedGraphReporter {
Expand All @@ -70,6 +79,7 @@ impl GraphExecutionReporter for GroupedGraphReporter {
started: false,
grouped_buffer: None,
color_support: self.color_support,
silent: self.silent,
})
}

Expand All @@ -88,20 +98,27 @@ struct GroupedLeafReporter {
started: bool,
grouped_buffer: Option<Rc<RefCell<Vec<u8>>>>,
color_support: ColorSupport,
silent: bool,
}

impl LeafExecutionReporter for GroupedLeafReporter {
fn start(&mut self, cache_status: CacheStatus) -> StdioConfig {
let line =
format_command_with_cache_status(&self.display, &self.workspace_path, &cache_status);

self.started = true;

// Print labeled command line immediately (before output is buffered).
let labeled_line = vite_str::format!("{} {line}", self.label);
let mut writer = self.writer.borrow_mut();
let _ = writer.write_all(labeled_line.as_bytes());
let _ = writer.flush();
// `--silent` suppresses it; the buffered task output is still flushed
// in `finish`.
if !self.silent {
let line = format_command_with_cache_status(
&self.display,
&self.workspace_path,
&cache_status,
);
let labeled_line = vite_str::format!("{} {line}", self.label);
let mut writer = self.writer.borrow_mut();
let _ = writer.write_all(labeled_line.as_bytes());
let _ = writer.flush();
}

// Create shared buffer for both stdout and stderr.
let buffer = Rc::new(RefCell::new(Vec::new()));
Expand All @@ -128,23 +145,26 @@ impl LeafExecutionReporter for GroupedLeafReporter {
_cache_update_status: CacheUpdateStatus,
error: Option<ExecutionError>,
) {
// Build grouped block: header + buffered output.
// Build grouped block: header + buffered output. `--silent` drops the
// `── [pkg#task] ──` block header, leaving just the task's own output.
let mut extra = Vec::new();
if let Some(ref grouped_buffer) = self.grouped_buffer {
let content = grouped_buffer.borrow();
if !content.is_empty() {
let header = vite_str::format!(
"{} {} {}\n",
"──".style(Style::new().bright_black()),
self.label,
"──".style(Style::new().bright_black())
);
extra.extend_from_slice(header.as_bytes());
if !self.silent {
let header = vite_str::format!(
"{} {} {}\n",
"──".style(Style::new().bright_black()),
self.label,
"──".style(Style::new().bright_black())
);
extra.extend_from_slice(header.as_bytes());
}
extra.extend_from_slice(&content);
}
}

write_leaf_trailing_output(&self.writer, error, self.started, &extra);
write_leaf_trailing_output(&self.writer, error, self.started, self.silent, &extra);
}
}

Expand Down Expand Up @@ -177,6 +197,7 @@ mod tests {
test_path(),
Box::new(std::io::sink()),
ColorSupport::uniform(false),
false,
));
let mut reporter = builder.build();
let mut leaf = reporter.new_leaf_execution(&item.execution_item_display, leaf_kind(item));
Expand Down
33 changes: 25 additions & 8 deletions crates/vite_task/src/session/reporter/interleaved/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct InterleavedReporterBuilder {
workspace_path: Arc<AbsolutePath>,
writer: Box<dyn Write>,
color_support: ColorSupport,
silent: bool,
}

impl InterleavedReporterBuilder {
Expand All @@ -24,12 +25,17 @@ impl InterleavedReporterBuilder {
/// stored unwrapped. `color_support` is forwarded to the pipe writers
/// in `LeafExecutionReporter::start`, where ANSI emitted by child tasks is stripped
/// for non-terminal sinks.
///
/// `silent` suppresses the per-task command line / cache indicator emitted
/// in `LeafExecutionReporter::start`; task output and error banners are
/// unaffected.
pub fn new(
workspace_path: Arc<AbsolutePath>,
writer: Box<dyn Write>,
color_support: ColorSupport,
silent: bool,
) -> Self {
Self { workspace_path, writer, color_support }
Self { workspace_path, writer, color_support, silent }
}
}

Expand All @@ -39,6 +45,7 @@ impl GraphExecutionReporterBuilder for InterleavedReporterBuilder {
writer: Rc::new(RefCell::new(self.writer)),
workspace_path: self.workspace_path,
color_support: self.color_support,
silent: self.silent,
})
}
}
Expand All @@ -47,6 +54,7 @@ struct InterleavedGraphReporter {
writer: Rc<RefCell<Box<dyn Write>>>,
workspace_path: Arc<AbsolutePath>,
color_support: ColorSupport,
silent: bool,
}

impl GraphExecutionReporter for InterleavedGraphReporter {
Expand All @@ -67,6 +75,7 @@ impl GraphExecutionReporter for InterleavedGraphReporter {
stdio_suggestion,
started: false,
color_support: self.color_support,
silent: self.silent,
})
}

Expand All @@ -84,18 +93,25 @@ struct InterleavedLeafReporter {
stdio_suggestion: StdioSuggestion,
started: bool,
color_support: ColorSupport,
silent: bool,
}

impl LeafExecutionReporter for InterleavedLeafReporter {
fn start(&mut self, cache_status: CacheStatus) -> StdioConfig {
let line =
format_command_with_cache_status(&self.display, &self.workspace_path, &cache_status);

self.started = true;

let mut writer = self.writer.borrow_mut();
let _ = writer.write_all(line.as_bytes());
let _ = writer.flush();
// `--silent` suppresses the command line / cache indicator; the task's
// own output still streams through the pipe writers below.
if !self.silent {
let line = format_command_with_cache_status(
&self.display,
&self.workspace_path,
&cache_status,
);
let mut writer = self.writer.borrow_mut();
let _ = writer.write_all(line.as_bytes());
let _ = writer.flush();
}

StdioConfig {
suggestion: self.stdio_suggestion,
Expand All @@ -118,7 +134,7 @@ impl LeafExecutionReporter for InterleavedLeafReporter {
_cache_update_status: CacheUpdateStatus,
error: Option<ExecutionError>,
) {
write_leaf_trailing_output(&self.writer, error, self.started, &[]);
write_leaf_trailing_output(&self.writer, error, self.started, self.silent, &[]);
}
}

Expand Down Expand Up @@ -150,6 +166,7 @@ mod tests {
test_path(),
Box::new(std::io::sink()),
ColorSupport::uniform(false),
false,
));
let mut reporter = builder.build();
let mut leaf = reporter.new_leaf_execution(display, leaf_kind);
Expand Down
Loading
Loading