Skip to content

Commit 0264102

Browse files
committed
style: apply formatting fixes from vp check --fix
1 parent 1329e9f commit 0264102

File tree

4 files changed

+74
-89
lines changed

4 files changed

+74
-89
lines changed

crates/vite_installer/src/cli.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,8 @@ pub fn parse() -> Options {
5555
opts.registry = std::env::var("NPM_CONFIG_REGISTRY").ok();
5656
}
5757
if !opts.no_node_manager {
58-
opts.no_node_manager = std::env::var("VP_NODE_MANAGER")
59-
.ok()
60-
.is_some_and(|v| v.eq_ignore_ascii_case("no"));
58+
opts.no_node_manager =
59+
std::env::var("VP_NODE_MANAGER").ok().is_some_and(|v| v.eq_ignore_ascii_case("no"));
6160
}
6261

6362
// quiet implies yes

crates/vite_installer/src/main.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ async fn do_install(
109109
if let Some(ref current) = current_version {
110110
if current == &resolved.version {
111111
if !opts.quiet {
112-
println!(
113-
"\n{} Already installed ({})",
114-
"\u{2714}".green(),
115-
resolved.version
116-
);
112+
println!("\n{} Already installed ({})", "\u{2714}".green(), resolved.version);
117113
}
118114
return Ok(());
119115
}
@@ -285,16 +281,10 @@ async fn download_with_progress(
285281
Ok(data)
286282
}
287283

288-
fn resolve_install_dir(
289-
opts: &cli::Options,
290-
) -> Result<AbsolutePathBuf, Box<dyn std::error::Error>> {
284+
fn resolve_install_dir(opts: &cli::Options) -> Result<AbsolutePathBuf, Box<dyn std::error::Error>> {
291285
if let Some(ref dir) = opts.install_dir {
292286
let path = std::path::PathBuf::from(dir);
293-
let abs = if path.is_absolute() {
294-
path
295-
} else {
296-
std::env::current_dir()?.join(path)
297-
};
287+
let abs = if path.is_absolute() { path } else { std::env::current_dir()?.join(path) };
298288
AbsolutePathBuf::new(abs).ok_or_else(|| "Invalid installation directory".into())
299289
} else {
300290
Ok(vite_shared::get_vp_home()?)
@@ -332,9 +322,20 @@ fn show_interactive_menu(opts: &cli::Options, install_dir: &str) -> bool {
332322
println!(" This will install the {} CLI and monorepo task runner.", "vp".cyan());
333323
println!();
334324
println!(" Install directory: {}", install_dir.cyan());
335-
println!(" PATH modification: {}", if opts.no_modify_path { "no".to_string() } else { format!("{bin_dir} \u{2192} User PATH") }.cyan());
325+
println!(
326+
" PATH modification: {}",
327+
if opts.no_modify_path {
328+
"no".to_string()
329+
} else {
330+
format!("{bin_dir} \u{2192} User PATH")
331+
}
332+
.cyan()
333+
);
336334
println!(" Version: {}", version.cyan());
337-
println!(" Node.js manager: {}", if opts.no_node_manager { "disabled" } else { "auto-detect" }.cyan());
335+
println!(
336+
" Node.js manager: {}",
337+
if opts.no_node_manager { "disabled" } else { "auto-detect" }.cyan()
338+
);
338339
println!();
339340
println!(" 1) {} (default)", "Proceed with installation".bold());
340341
println!(" 2) Cancel");
@@ -358,10 +359,7 @@ fn print_success(opts: &cli::Options, install_dir: &str) {
358359
}
359360

360361
println!();
361-
println!(
362-
" {} Vite+ has been installed successfully!",
363-
"\u{2714}".green().bold()
364-
);
362+
println!(" {} Vite+ has been installed successfully!", "\u{2714}".green().bold());
365363
println!();
366364
println!(" To get started, restart your terminal, then run:");
367365
println!();

crates/vite_installer/src/windows_path.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,7 @@ fn read_user_path() -> io::Result<String> {
8484

8585
let mut hkey: ffi::HKEY = 0;
8686
let result = unsafe {
87-
ffi::RegOpenKeyExW(
88-
ffi::HKEY_CURRENT_USER,
89-
sub_key.as_ptr(),
90-
0,
91-
ffi::KEY_READ,
92-
&mut hkey,
93-
)
87+
ffi::RegOpenKeyExW(ffi::HKEY_CURRENT_USER, sub_key.as_ptr(), 0, ffi::KEY_READ, &mut hkey)
9488
};
9589

9690
if result == ffi::ERROR_FILE_NOT_FOUND {
@@ -143,10 +137,7 @@ fn read_user_path() -> io::Result<String> {
143137
}
144138

145139
// Convert UTF-16 to String (strip trailing null)
146-
let wide: Vec<u16> = buf
147-
.chunks_exact(2)
148-
.map(|c| u16::from_le_bytes([c[0], c[1]]))
149-
.collect();
140+
let wide: Vec<u16> = buf.chunks_exact(2).map(|c| u16::from_le_bytes([c[0], c[1]])).collect();
150141
let s = String::from_utf16_lossy(&wide);
151142
Ok(s.trim_end_matches('\0').to_string())
152143
}
@@ -159,13 +150,7 @@ fn write_user_path(path: &str) -> io::Result<()> {
159150

160151
let mut hkey: ffi::HKEY = 0;
161152
let result = unsafe {
162-
ffi::RegOpenKeyExW(
163-
ffi::HKEY_CURRENT_USER,
164-
sub_key.as_ptr(),
165-
0,
166-
ffi::KEY_WRITE,
167-
&mut hkey,
168-
)
153+
ffi::RegOpenKeyExW(ffi::HKEY_CURRENT_USER, sub_key.as_ptr(), 0, ffi::KEY_WRITE, &mut hkey)
169154
};
170155

171156
if result != ffi::ERROR_SUCCESS {
@@ -230,11 +215,8 @@ pub fn add_to_user_path(bin_dir: &str) -> io::Result<()> {
230215
}
231216

232217
// Prepend to PATH
233-
let new_path = if current.is_empty() {
234-
bin_dir.to_string()
235-
} else {
236-
format!("{bin_dir};{current}")
237-
};
218+
let new_path =
219+
if current.is_empty() { bin_dir.to_string() } else { format!("{bin_dir};{current}") };
238220

239221
write_user_path(&new_path)?;
240222
broadcast_settings_change();

rfcs/windows-installer.md

Lines changed: 50 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ rustup provides `rustup-init.exe` — a single console binary that users downloa
5959
rustup uses one binary for everything — `rustup-init.exe` copies itself to `~/.cargo/bin/rustup.exe` and changes behavior based on `argv[0]`. This works because rustup IS the toolchain manager.
6060

6161
**Not suitable for vp** because:
62+
6263
- `vp.exe` is downloaded from the npm registry as a platform-specific package
6364
- The installer cannot copy itself as `vp.exe` — they are fundamentally different binaries
6465
- `vp.exe` links `vite_js_runtime`, `vite_workspace`, `oxc_resolver` (~15-20 MB) — the installer needs none of these
@@ -75,6 +76,7 @@ crates/vite_installer/ — standalone installer binary
7576
`vite_setup` extracts the reusable installation logic currently in `vite_global_cli/src/commands/upgrade/`. Both `vp upgrade` and `vp-setup.exe` call into `vite_setup`.
7677

7778
**Benefits:**
79+
7880
- Installer binary stays small (3-5 MB)
7981
- `vp upgrade` and `vp-setup.exe` share identical installation logic — no drift
8082
- Clear separation of concerns
@@ -83,17 +85,17 @@ crates/vite_installer/ — standalone installer binary
8385

8486
### What Gets Extracted
8587

86-
| Current location in `upgrade/` | Extracted to `vite_setup::` | Purpose |
87-
|---|---|---|
88-
| `platform.rs``detect_platform_suffix()` | `platform` | OS/arch detection |
89-
| `registry.rs``resolve_version()`, `resolve_platform_package()` | `registry` | npm registry queries |
90-
| `integrity.rs``verify_integrity()` | `integrity` | SHA-512 verification |
91-
| `install.rs``extract_platform_package()` | `extract` | Tarball extraction |
92-
| `install.rs``generate_wrapper_package_json()` | `package_json` | Wrapper package.json |
93-
| `install.rs``write_release_age_overrides()` | `npmrc` | .npmrc overrides |
94-
| `install.rs``install_production_deps()` | `deps` | Run `vp install --silent` |
95-
| `install.rs``swap_current_link()` | `link` | Symlink/junction swap |
96-
| `install.rs``cleanup_old_versions()` | `cleanup` | Old version cleanup |
88+
| Current location in `upgrade/` | Extracted to `vite_setup::` | Purpose |
89+
| ----------------------------------------------------------------- | --------------------------- | ------------------------- |
90+
| `platform.rs``detect_platform_suffix()` | `platform` | OS/arch detection |
91+
| `registry.rs``resolve_version()`, `resolve_platform_package()` | `registry` | npm registry queries |
92+
| `integrity.rs``verify_integrity()` | `integrity` | SHA-512 verification |
93+
| `install.rs``extract_platform_package()` | `extract` | Tarball extraction |
94+
| `install.rs``generate_wrapper_package_json()` | `package_json` | Wrapper package.json |
95+
| `install.rs``write_release_age_overrides()` | `npmrc` | .npmrc overrides |
96+
| `install.rs``install_production_deps()` | `deps` | Run `vp install --silent` |
97+
| `install.rs``swap_current_link()` | `link` | Symlink/junction swap |
98+
| `install.rs``cleanup_old_versions()` | `cleanup` | Old version cleanup |
9799

98100
### What Stays in `vite_global_cli`
99101

@@ -176,24 +178,24 @@ vp-setup.exe -y --version 0.3.0 --no-node-manager --registry https://registry.np
176178

177179
### CLI Flags
178180

179-
| Flag | Description | Default |
180-
|---|---|---|
181-
| `-y` / `--yes` | Accept defaults, no prompts | interactive |
182-
| `-q` / `--quiet` | Suppress output except errors | false |
183-
| `--version <VER>` | Install specific version | latest |
184-
| `--tag <TAG>` | npm dist-tag | latest |
185-
| `--install-dir <PATH>` | Installation directory | `%USERPROFILE%\.vite-plus` |
186-
| `--registry <URL>` | npm registry URL | `https://registry.npmjs.org` |
187-
| `--no-node-manager` | Skip Node.js manager setup | auto-detect |
188-
| `--no-modify-path` | Don't modify User PATH | modify |
181+
| Flag | Description | Default |
182+
| ---------------------- | ----------------------------- | ---------------------------- |
183+
| `-y` / `--yes` | Accept defaults, no prompts | interactive |
184+
| `-q` / `--quiet` | Suppress output except errors | false |
185+
| `--version <VER>` | Install specific version | latest |
186+
| `--tag <TAG>` | npm dist-tag | latest |
187+
| `--install-dir <PATH>` | Installation directory | `%USERPROFILE%\.vite-plus` |
188+
| `--registry <URL>` | npm registry URL | `https://registry.npmjs.org` |
189+
| `--no-node-manager` | Skip Node.js manager setup | auto-detect |
190+
| `--no-modify-path` | Don't modify User PATH | modify |
189191

190192
### Environment Variables (compatible with `install.ps1`)
191193

192-
| Variable | Maps to |
193-
|---|---|
194-
| `VP_VERSION` | `--version` |
195-
| `VP_HOME` | `--install-dir` |
196-
| `NPM_CONFIG_REGISTRY` | `--registry` |
194+
| Variable | Maps to |
195+
| ------------------------- | ------------------- |
196+
| `VP_VERSION` | `--version` |
197+
| `VP_HOME` | `--install-dir` |
198+
| `NPM_CONFIG_REGISTRY` | `--registry` |
197199
| `VP_NODE_MANAGER=yes\|no` | `--no-node-manager` |
198200

199201
CLI flags take precedence over environment variables.
@@ -300,13 +302,13 @@ The binary uses the console subsystem (default for Rust binaries on Windows). Wh
300302

301303
### Existing Installation Handling
302304

303-
| Scenario | Behavior |
304-
|---|---|
305-
| No existing install | Fresh install |
306-
| Same version installed | Print "already up to date", exit 0 |
307-
| Different version installed | Upgrade to target version |
308-
| Corrupt/partial install (broken junction) | Recreate directory structure |
309-
| Running `vp.exe` in bin/ | Rename to `.old`, copy new (same as trampoline pattern) |
305+
| Scenario | Behavior |
306+
| ----------------------------------------- | ------------------------------------------------------- |
307+
| No existing install | Fresh install |
308+
| Same version installed | Print "already up to date", exit 0 |
309+
| Different version installed | Upgrade to target version |
310+
| Corrupt/partial install (broken junction) | Recreate directory structure |
311+
| Running `vp.exe` in bin/ | Rename to `.old`, copy new (same as trampoline pattern) |
310312

311313
## Add/Remove Programs Registration
312314

@@ -402,17 +404,17 @@ Target: 3-5 MB (release, stripped, LTO).
402404

403405
Key dependencies and their approximate contribution:
404406

405-
| Dependency | Purpose | Size impact |
406-
|---|---|---|
407-
| `reqwest` + `native-tls-vendored` | HTTP + TLS | ~1.5 MB |
408-
| `flate2` + `tar` | Tarball extraction | ~200 KB |
409-
| `clap` | CLI parsing | ~300 KB |
410-
| `tokio` (minimal features) | Async runtime | ~400 KB |
411-
| `indicatif` | Progress bars | ~100 KB |
412-
| `sha2` | Integrity verification | ~50 KB |
413-
| `serde_json` | Registry JSON parsing | ~200 KB |
414-
| `winreg` | Windows registry | ~50 KB |
415-
| Rust std + overhead | | ~500 KB |
407+
| Dependency | Purpose | Size impact |
408+
| --------------------------------- | ---------------------- | ----------- |
409+
| `reqwest` + `native-tls-vendored` | HTTP + TLS | ~1.5 MB |
410+
| `flate2` + `tar` | Tarball extraction | ~200 KB |
411+
| `clap` | CLI parsing | ~300 KB |
412+
| `tokio` (minimal features) | Async runtime | ~400 KB |
413+
| `indicatif` | Progress bars | ~100 KB |
414+
| `sha2` | Integrity verification | ~50 KB |
415+
| `serde_json` | Registry JSON parsing | ~200 KB |
416+
| `winreg` | Windows registry | ~50 KB |
417+
| Rust std + overhead | | ~500 KB |
416418

417419
Use `opt-level = "z"` (optimize for size) in package profile override, matching the trampoline approach.
418420

@@ -421,6 +423,7 @@ Use `opt-level = "z"` (optimize for size) in package profile override, matching
421423
### 1. MSI/NSIS/Inno Setup Installer (Rejected)
422424

423425
Traditional Windows installers provide GUI, Add/Remove Programs, and Start Menu integration. However:
426+
424427
- Adds build-time dependency on external tooling (WiX, NSIS)
425428
- GUI is unnecessary for a developer CLI tool
426429
- MSI has complex authoring requirements
@@ -478,11 +481,13 @@ Embed the PowerShell script in a self-extracting exe. Fragile, still requires Po
478481
## Testing Strategy
479482

480483
### Unit Tests
484+
481485
- Platform detection (mock different architectures)
482486
- PATH modification logic (registry read/write)
483487
- Version comparison and existing install detection
484488

485489
### Integration Tests (CI)
490+
486491
- Fresh install from cmd.exe, PowerShell, Git Bash
487492
- Silent mode (`-y`) installation
488493
- Custom registry, custom install dir
@@ -491,6 +496,7 @@ Embed the PowerShell script in a self-extracting exe. Fragile, still requires Po
491496
- Verify PATH is modified correctly
492497

493498
### Manual Tests
499+
494500
- Double-click from Downloads folder
495501
- SmartScreen behavior (signed vs unsigned)
496502
- Windows Defender scan behavior

0 commit comments

Comments
 (0)