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
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/vp_cli_help/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rust-version.workspace = true

[dependencies]
clap = { workspace = true }
owo-colors = { workspace = true }
console = { workspace = true }
terminal_size = { workspace = true }
vp_shared = { workspace = true }

Expand Down
17 changes: 7 additions & 10 deletions crates/vp_cli_help/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use std::{borrow::Cow, fmt::Write as _, io::Write as _};

use clap::{Arg, Command};
use owo_colors::OwoColorize;
use console::style;
use terminal_size::{Width, terminal_size_of};

const HELP_RIGHT_MARGIN: usize = 4;
Expand Down Expand Up @@ -129,14 +129,14 @@ pub fn render_heading(title: &str) -> String {
}

if should_accent_heading(title) {
heading.bold().bright_blue().to_string()
style(&heading).bold().blue().bright().to_string()
} else {
heading.bold().to_string()
style(&heading).bold().to_string()
}
}

fn render_usage_value(usage: &str) -> String {
if should_style_help() { usage.bold().to_string() } else { usage.to_string() }
if should_style_help() { style(&usage).bold().to_string() } else { usage.to_string() }
}

fn should_accent_heading(title: &str) -> bool {
Expand All @@ -149,18 +149,15 @@ fn write_documentation_footer(output: &mut String, documentation_url: &str) {
}

pub fn accent(text: &str) -> String {
if should_style_help() { text.bright_blue().to_string() } else { text.to_string() }
if should_style_help() { style(&text).blue().bright().to_string() } else { text.to_string() }
}

pub fn accent_command(command: &str) -> String {
format!("`{}`", accent(command))
}

pub fn should_style_help() -> bool {
vp_shared::is_stdout_terminal()
&& std::env::var_os("NO_COLOR").is_none()
&& std::env::var("CLICOLOR").map_or(true, |value| value != "0")
&& std::env::var("TERM").map_or(true, |term| term != "dumb")
console::colors_enabled()
}

fn terminal_content_width() -> usize {
Expand Down Expand Up @@ -321,7 +318,7 @@ fn render_muted_comment_suffix(line: &str) -> String {
}

if let Some((prefix, suffix)) = split_comment_suffix(line) {
return format!("{}{}", prefix, suffix.bright_black());
return format!("{}{}", prefix, style(&suffix).black().bright());
}

line.to_string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ root (rfcs/cwd-flag.md).
**Exit code:** 1

```
note: You are running `vp build` as a Vite+ built-in command. If you meant to run the build npm script, use `vpr build` instead.
error: `vp build` at the workspace root needs a target package.
note: You are running `vp build` as a Vite+ built-in command. If you meant to run the build npm script, use `vpr build` instead.
error: `vp build` at the workspace root needs a target package.

Packages in this workspace:
admin apps/admin
Expand All @@ -29,7 +29,7 @@ dev at the root no longer starts a server against the root
**Exit code:** 1

```
error: `vp dev` at the workspace root needs a target package.
error: `vp dev` at the workspace root needs a target package.

Packages in this workspace:
admin apps/admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ root (rfcs/cwd-flag.md).
**Exit code:** 1

```
note: You are running `vp build` as a Vite+ built-in command. If you meant to run the build npm script, use `vpr build` instead.
error: `vp build` at the workspace root needs a target package.
note: You are running `vp build` as a Vite+ built-in command. If you meant to run the build npm script, use `vpr build` instead.
error: `vp build` at the workspace root needs a target package.

Packages in this workspace:
admin apps/admin
Expand All @@ -29,7 +29,7 @@ dev at the root no longer starts a server against the root
**Exit code:** 1

```
error: `vp dev` at the workspace root needs a target package.
error: `vp dev` at the workspace root needs a target package.

Packages in this workspace:
admin apps/admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ listing and the task fails instead of silently building the root.
```
$ vp build ⊘ cache disabled

error: `vp build` at the workspace root needs a target package.
error: `vp build` at the workspace root needs a target package.

Packages in this workspace:
admin apps/admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ listing and the task fails instead of silently building the root.
```
$ vp build ⊘ cache disabled

error: `vp build` at the workspace root needs a target package.
error: `vp build` at the workspace root needs a target package.

Packages in this workspace:
admin apps/admin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,5 @@ the note still reaches piped output, such as an AI agent capturing the command;
```
Found 0 warnings and 0 errors.
Finished in <duration> on 1 file with <n> rules using <n> threads.
note: You are running `vp lint` as a Vite+ built-in command. If you meant to run the lint npm script, use `vpr lint` instead.
note: You are running `vp lint` as a Vite+ built-in command. If you meant to run the lint npm script, use `vpr lint` instead.
```
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ the note still reaches piped output, such as an AI agent capturing the command;
```
Found 0 warnings and 0 errors.
Finished in <duration> on 1 file with <n> rules using <n> threads.
note: You are running `vp lint` as a Vite+ built-in command. If you meant to run the lint npm script, use `vpr lint` instead.
note: You are running `vp lint` as a Vite+ built-in command. If you meant to run the lint npm script, use `vpr lint` instead.
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vp check exposes the stdout EAGAIN failure when a large diagnostic replay meets
```
--- stdout ---
stdout: 1282 lines
pass: All 3 files are correctly formatted (<duration>, <n> threads)
pass: All 3 files are correctly formatted (<duration>, <n> threads)
! eslint(no-unused-vars): Variable 'unused000' is declared but never used. Unused variables should start with a '_'.
,-[src/index.js:2:9]
1 | export function emitDiagnostics() {
Expand All @@ -24,5 +24,5 @@ stdout: 1282 lines
Found 0 errors and 128 warnings in 2 files (<duration>, <n> threads)
--- stderr ---
stderr: 1 lines
warn: Lint warnings found
warn: Lint warnings found
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vp check exposes the stdout EAGAIN failure when a large diagnostic replay meets
```
--- stdout ---
stdout: 1282 lines
pass: All 3 files are correctly formatted (<duration>, <n> threads)
pass: All 3 files are correctly formatted (<duration>, <n> threads)
! eslint(no-unused-vars): Variable 'unused000' is declared but never used. Unused variables should start with a '_'.
,-[src/index.js:2:9]
1 | export function emitDiagnostics() {
Expand All @@ -24,5 +24,5 @@ stdout: 1282 lines
Found 0 errors and 128 warnings in 2 files (<duration>, <n> threads)
--- stderr ---
stderr: 1 lines
warn: Lint warnings found
warn: Lint warnings found
```
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,19 @@ steps = [
{ argv = ["vp", "check"], continue-on-failure = true },
{ argv = ["vp", "check", "--quiet"], comment = "warnings are suppressed while errors are still reported", continue-on-failure = true },
]

[[case]]
name = "check_no_color"
vp = "local"
env = { NO_COLOR = "1" }
steps = [
{ argv = ["vp", "check", "--no-fmt"], comment = "Captured lint diagnostics and Vite+ messages honor NO_COLOR in a terminal", formatted-snapshot = true },
]

[[case]]
name = "check_force_color_zero"
vp = "local"
env = { FORCE_COLOR = "0" }
steps = [
{ argv = ["vp", "check", "--no-fmt"], comment = "Capturing lint output preserves an explicit FORCE_COLOR=0", formatted-snapshot = true },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# check_force_color_zero

## `vp check --no-fmt`

Capturing lint output preserves an explicit FORCE_COLOR=0

**Exit code:** 1

```
\x1b[31;1merror: Lint issues found
x eslint(no-eval): eval can be harmful.
,-[src/index.js:2:3]
1 | function hello() {
2 | eval(\"code\");
: ^^^^
3 | console.log(\"warning\");
`----
help: Avoid eval(). For JSON parsing use JSON.parse(); for dynamic property access use bracket notation (obj[key]); for other cases refactor to avoid evaluating strings as code.

! eslint(no-console): Unexpected console statement.
,-[src/index.js:3:3]
2 | eval(\"code\");
3 | console.log(\"warning\");
: ^^^^^^^^^^^
4 | return \"hello\";
`----
help: Delete this console statement.

Found 1 error and 1 warning in 2 files (<duration>, <n> threads)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# check_no_color

## `vp check --no-fmt`

Captured lint diagnostics and Vite+ messages honor NO_COLOR in a terminal

**Exit code:** 1

```
error: Lint issues found
x eslint(no-eval): eval can be harmful.
,-[src/index.js:2:3]
1 | function hello() {
2 | eval(\"code\");
: ^^^^
3 | console.log(\"warning\");
`----
help: Avoid eval(). For JSON parsing use JSON.parse(); for dynamic property access use bracket notation (obj[key]); for other cases refactor to avoid evaluating strings as code.

! eslint(no-console): Unexpected console statement.
,-[src/index.js:3:3]
2 | eval(\"code\");
3 | console.log(\"warning\");
: ^^^^^^^^^^^
4 | return \"hello\";
`----
help: Delete this console statement.

Found 1 error and 1 warning in 2 files (<duration>, <n> threads)
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "command-no-color",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[[case]]
name = "command_no_color"
vp = ["local", "global"]
env = { NO_COLOR = "1" }
steps = [
{ argv = ["vp", "check", "--help"], formatted-snapshot = true, continue-on-failure = true },
{ argv = ["vp", "--definitely-invalid"], comment = "Argument errors and highlighted arguments honor NO_COLOR", formatted-snapshot = true, continue-on-failure = true },
{ argv = ["vp", "check", "--no-fmt", "--no-lint"], comment = "Shared errors and command-specific summaries honor NO_COLOR", formatted-snapshot = true, continue-on-failure = true },
]

[[case]]
name = "prompt_no_color"
vp = "local"
env = { NO_COLOR = "1" }
steps = [
{ argv = ["vp", "create"], comment = "The picocolors-backed picker remains interactive without color", formatted-snapshot = true, interactions = [
{ "expect-milestone" = "select:select:0" },
{ "write-key" = "ctrl-c" },
] },
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# command_no_color

## `vp check --help`

```
VITE+ - The Unified Toolchain for the Web

Usage: vp check [OPTIONS] [PATHS]...

Run format, lint, and type checks.

Arguments:
[PATHS]... File paths to pass to fmt and lint

Options:
--fix Auto-fix format and lint issues
--quiet Disable reporting on warnings, only errors are reported
--no-fmt Skip format check
--no-lint Skip lint rules; type-check still runs when `lint.options.typeCheck` is true
--no-error-on-unmatched-pattern Do not exit with error when pattern is unmatched
-h, --help Print help

Examples:
vp check
vp check --fix
vp check --no-lint src/index.ts

Documentation: https://viteplus.dev/guide/check
```

## `vp --definitely-invalid`

Argument errors and highlighted arguments honor NO_COLOR

**Exit code:** 2

```
VITE+ - The Unified Toolchain for the Web

error: Unexpected argument \'--definitely-invalid\'
```

## `vp check --no-fmt --no-lint`

Shared errors and command-specific summaries honor NO_COLOR

**Exit code:** 1

```
VITE+ - The Unified Toolchain for the Web

error: No checks enabled

Enable `lint.options.typeCheck` in vite.config.ts for type-check only, drop a `--no-fmt`/`--no-lint` flag, or re-enable `check.fmt`/`check.lint` in vite.config.ts.
```
Loading
Loading