From 8ec65eca9a4a25a59838de25eb5b94d7778c5c0d Mon Sep 17 00:00:00 2001 From: MK Date: Thu, 11 Dec 2025 17:19:20 +0800 Subject: [PATCH] refactor(cli): remove packages commands from local cli --- packages/cli/binding/src/cli.rs | 1962 +---------------- packages/cli/binding/src/commands/add.rs | 72 - packages/cli/binding/src/commands/dedupe.rs | 49 - packages/cli/binding/src/commands/link.rs | 49 - packages/cli/binding/src/commands/mod.rs | 9 - packages/cli/binding/src/commands/outdated.rs | 78 - packages/cli/binding/src/commands/pm.rs | 225 -- packages/cli/binding/src/commands/remove.rs | 66 - packages/cli/binding/src/commands/unlink.rs | 50 - packages/cli/binding/src/commands/update.rs | 74 - packages/cli/binding/src/commands/why.rs | 79 - .../cli/snap-tests/command-helper/snap.txt | 26 + .../cli/snap-tests/command-helper/steps.json | 1 + 13 files changed, 39 insertions(+), 2701 deletions(-) delete mode 100644 packages/cli/binding/src/commands/add.rs delete mode 100644 packages/cli/binding/src/commands/dedupe.rs delete mode 100644 packages/cli/binding/src/commands/link.rs delete mode 100644 packages/cli/binding/src/commands/outdated.rs delete mode 100644 packages/cli/binding/src/commands/pm.rs delete mode 100644 packages/cli/binding/src/commands/remove.rs delete mode 100644 packages/cli/binding/src/commands/unlink.rs delete mode 100644 packages/cli/binding/src/commands/update.rs delete mode 100644 packages/cli/binding/src/commands/why.rs diff --git a/packages/cli/binding/src/cli.rs b/packages/cli/binding/src/cli.rs index f17794de1b..7f9a2e47a1 100644 --- a/packages/cli/binding/src/cli.rs +++ b/packages/cli/binding/src/cli.rs @@ -9,7 +9,6 @@ use clap::{Parser, Subcommand}; use serde::{Deserialize, Serialize}; use tokio::fs::write; use vite_error::Error; -use vite_install::commands::{add::SaveDependencyType, outdated::Format}; use vite_path::AbsolutePathBuf; use vite_str::Str; use vite_task::{ @@ -18,10 +17,8 @@ use vite_task::{ }; use crate::commands::{ - add::AddCommand, dedupe::DedupeCommand, doc::doc as doc_cmd, fmt::fmt, install::InstallCommand, - lib_cmd::lib, link::LinkCommand, lint::lint, outdated::OutdatedCommand, pm::PmCommand, - remove::RemoveCommand, test::test, unlink::UnlinkCommand, update::UpdateCommand, - vite::vite as vite_cmd, why::WhyCommand, + doc::doc as doc_cmd, fmt::fmt, install::InstallCommand, lib_cmd::lib, lint::lint, test::test, + vite::vite as vite_cmd, }; #[derive(Debug, Clone, Serialize, Deserialize)] @@ -51,6 +48,7 @@ pub struct Args { #[derive(Subcommand, Debug)] pub enum Commands { + /// Run tasks Run { tasks: Vec, #[clap(last = true)] @@ -73,39 +71,44 @@ pub enum Commands { #[clap(long, conflicts_with = "topological")] no_topological: bool, }, + /// Lint code Lint { #[clap(last = true)] /// Arguments to pass to oxlint args: Vec, }, + /// Format code Fmt { #[clap(last = true)] /// Arguments to pass to oxfmt args: Vec, }, + /// Build application Build { #[clap(last = true)] /// Arguments to pass to vite build args: Vec, }, + /// Run test Test { #[clap(last = true)] /// Arguments to pass to vite test args: Vec, }, - /// Lib command, build a library + /// Build library #[command(disable_help_flag = true)] Lib { /// Arguments to pass to tsdown #[arg(allow_hyphen_values = true, trailing_var_arg = true)] args: Vec, }, + /// Run development server Dev { #[arg(allow_hyphen_values = true, trailing_var_arg = true)] /// Arguments to pass to vite dev args: Vec, }, - /// Doc command, build documentation + /// Build documentation Doc { #[arg(allow_hyphen_values = true, trailing_var_arg = true)] /// Arguments to pass to vitepress @@ -125,641 +128,12 @@ pub enum Commands { #[arg(allow_hyphen_values = true, trailing_var_arg = true)] args: Vec, }, - /// Add packages to dependencies - Add { - /// Save to `dependencies` (default) - #[arg(short = 'P', long)] - save_prod: bool, - /// Save to `devDependencies` - #[arg(short = 'D', long)] - save_dev: bool, - /// Save to `peerDependencies` and `devDependencies` - #[arg(long)] - save_peer: bool, - /// Save to `optionalDependencies` - #[arg(short = 'O', long)] - save_optional: bool, - /// Save exact version rather than semver range (e.g., `^1.0.0` -> `1.0.0`) - #[arg(short = 'E', long)] - save_exact: bool, - - /// Save the new dependency to the specified catalog name. - /// Example: `vite add vue --save-catalog-name vue3` - #[arg(long, value_name = "CATALOG_NAME")] - save_catalog_name: Option, - /// Save the new dependency to the default catalog - #[arg(long)] - save_catalog: bool, - - /// A list of package names allowed to run postinstall - #[arg(long, value_name = "NAMES")] - allow_build: Option, - - /// Filter packages in monorepo (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Add to workspace root (ignore-workspace-root-check) - #[arg(short = 'w', long)] - workspace_root: bool, - - /// Only add if package exists in workspace (pnpm-specific) - #[arg(long)] - workspace: bool, - - /// Install globally - #[arg(short = 'g', long)] - global: bool, - - /// Packages to add - #[arg(required = true)] - packages: Vec, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - /// Remove packages from dependencies - #[command(alias = "rm", alias = "un", alias = "uninstall")] - Remove { - /// Only remove from `devDependencies` (pnpm-specific) - #[arg(short = 'D', long)] - save_dev: bool, - - /// Only remove from `optionalDependencies` (pnpm-specific) - #[arg(short = 'O', long)] - save_optional: bool, - - /// Only remove from `dependencies` (pnpm-specific) - #[arg(short = 'P', long)] - save_prod: bool, - - /// Filter packages in monorepo (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Remove from workspace root - #[arg(short = 'w', long)] - workspace_root: bool, - - /// Remove recursively from all workspace packages, including workspace root - #[arg(short = 'r', long)] - recursive: bool, - - /// Remove global packages - #[arg(short = 'g', long)] - global: bool, - - /// Packages to remove - #[arg(required = true)] - packages: Vec, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - /// Update packages to their latest versions - #[command(alias = "up")] - Update { - /// Update to latest version (ignore semver range) - #[arg(short = 'L', long)] - latest: bool, - - /// Update global packages - #[arg(short = 'g', long)] - global: bool, - - /// Update recursively in all workspace packages - #[arg(short = 'r', long)] - recursive: bool, - - /// Filter packages in monorepo (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Include workspace root - #[arg(short = 'w', long)] - workspace_root: bool, - - /// Update only devDependencies - #[arg(short = 'D', long)] - dev: bool, - - /// Update only dependencies (production) - #[arg(short = 'P', long)] - prod: bool, - - /// Interactive mode - show outdated packages and choose which to update - #[arg(short = 'i', long)] - interactive: bool, - - /// Don't update optionalDependencies - #[arg(long)] - no_optional: bool, - - /// Update lockfile only, don't modify package.json - #[arg(long)] - no_save: bool, - - /// Only update if package exists in workspace (pnpm-specific) - #[arg(long)] - workspace: bool, - - /// Packages to update (optional - updates all if omitted) - packages: Vec, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - /// Deduplicate dependencies by removing older versions - #[command(alias = "ddp")] - Dedupe { - /// Check if deduplication would make changes - #[arg(long)] - check: bool, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - /// Check for outdated packages - Outdated { - /// Package name(s) to check (supports glob patterns in pnpm) - packages: Vec, - - /// Show extended information - #[arg(long)] - long: bool, - - /// Output format: table (default), list, or json - #[arg(long, value_name = "FORMAT", value_parser = clap::value_parser!(Format))] - format: Option, - - /// Check recursively across all workspaces - #[arg(short = 'r', long)] - recursive: bool, - - /// Filter packages in monorepo (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Include workspace root - #[arg(short = 'w', long)] - workspace_root: bool, - - /// Only production and optional dependencies (pnpm-specific) - #[arg(short = 'P', long)] - prod: bool, - - /// Only dev dependencies (pnpm-specific) - #[arg(short = 'D', long)] - dev: bool, - - /// Exclude optional dependencies (pnpm-specific) - #[arg(long)] - no_optional: bool, - - /// Only show compatible versions (pnpm-specific) - #[arg(long)] - compatible: bool, - - /// Sort results by field (pnpm-specific) - #[arg(long, value_name = "FIELD")] - sort_by: Option, - - /// Check globally installed packages - #[arg(short = 'g', long)] - global: bool, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - /// Show why a package is installed - #[command(alias = "explain")] - Why { - /// Package(s) to check - #[arg(required = true)] - packages: Vec, - - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Show extended information (pnpm-specific) - #[arg(long)] - long: bool, - - /// Show parseable output (pnpm-specific) - #[arg(long)] - parseable: bool, - - /// Check recursively across all workspaces - #[arg(short = 'r', long)] - recursive: bool, - - /// Filter packages in monorepo (pnpm/npm-specific) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Check in workspace root (pnpm-specific) - #[arg(short = 'w', long)] - workspace_root: bool, - - /// Only production dependencies (pnpm-specific) - #[arg(short = 'P', long)] - prod: bool, - - /// Only dev dependencies (pnpm-specific) - #[arg(short = 'D', long)] - dev: bool, - - /// Limit tree depth (pnpm-specific) - #[arg(long)] - depth: Option, - - /// Exclude optional dependencies (pnpm-specific) - #[arg(long)] - no_optional: bool, - - /// Check globally installed packages - #[arg(short = 'g', long)] - global: bool, - - /// Exclude peer dependencies (pnpm/yarn@2+-specific) - #[arg(long)] - exclude_peers: bool, - - /// Use a finder function defined in .pnpmfile.cjs (pnpm-specific) - #[arg(long, value_name = "FINDER_NAME")] - find_by: Option, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - /// Link packages for local development - #[command(alias = "ln")] - Link { - /// Package name or directory to link - /// If empty, registers current package globally - #[arg(value_name = "PACKAGE|DIR")] - package: Option, - - /// Arguments to pass to package manager - #[arg(allow_hyphen_values = true, trailing_var_arg = true)] - args: Vec, - }, - /// Unlink packages - Unlink { - /// Package name to unlink - /// If empty, unlinks current package globally - #[arg(value_name = "PACKAGE|DIR")] - package: Option, - - /// Unlink in every workspace package (pnpm/yarn@2+-specific) - #[arg(short = 'r', long)] - recursive: bool, - - /// Arguments to pass to package manager - #[arg(allow_hyphen_values = true, trailing_var_arg = true)] - args: Vec, - }, - /// Package manager utilities - #[command(subcommand)] - Pm(PmCommands), -} - -#[derive(Subcommand, Debug, Clone)] -pub enum PmCommands { - /// Remove unnecessary packages - Prune { - /// Remove devDependencies - #[arg(long)] - prod: bool, - - /// Remove optional dependencies - #[arg(long)] - no_optional: bool, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - - /// Create a tarball of the package - Pack { - /// Pack all workspace packages - #[arg(short = 'r', long)] - recursive: bool, - - /// Filter packages to pack (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Customizes the output path for the tarball. Use %s and %v to include the package name and version (pnpm and yarn@2+ only), e.g., %s.tgz or some-dir/%s-%v.tgz - #[arg(long)] - out: Option, - - /// Directory where the tarball will be saved (pnpm and npm only) - #[arg(long)] - pack_destination: Option, - - /// Gzip compression level (0-9) - #[arg(long)] - pack_gzip_level: Option, - - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - - /// List installed packages - #[command(alias = "ls")] - List { - /// Package pattern to filter - pattern: Option, - - /// Maximum depth of dependency tree - #[arg(long)] - depth: Option, - - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Show extended information - #[arg(long)] - long: bool, - - /// Parseable output format - #[arg(long)] - parseable: bool, - - /// Only production dependencies - #[arg(short = 'P', long)] - prod: bool, - - /// Only dev dependencies - #[arg(short = 'D', long)] - dev: bool, - - /// Exclude optional dependencies - #[arg(long)] - no_optional: bool, - - /// Exclude peer dependencies - #[arg(long)] - exclude_peers: bool, - - /// Show only project packages (pnpm-specific) - #[arg(long)] - only_projects: bool, - - /// Use a finder function defined in .pnpmfile.cjs (pnpm-specific) - #[arg(long, value_name = "FINDER_NAME")] - find_by: Option, - - /// List across all workspaces - #[arg(short = 'r', long)] - recursive: bool, - - /// Filter packages in monorepo (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Vec, - - /// List global packages - #[arg(short = 'g', long)] - global: bool, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - - /// View package information from registry - #[command(alias = "info", alias = "show")] - View { - /// Package name with optional version - #[arg(required = true)] - package: String, - - /// Specific field to view - field: Option, - - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - - /// Publish package to registry - Publish { - /// Tarball or folder to publish - #[arg(value_name = "TARBALL|FOLDER")] - target: Option, - - /// Preview without publishing - #[arg(long)] - dry_run: bool, - - /// Publish tag (default: latest) - #[arg(long)] - tag: Option, - - /// Access level (public/restricted) - #[arg(long)] - access: Option, - - /// One-time password for authentication - #[arg(long, value_name = "OTP")] - otp: Option, - - /// Skip git checks (pnpm-specific) - #[arg(long)] - no_git_checks: bool, - - /// Set the branch name to publish from (pnpm-specific) - #[arg(long, value_name = "BRANCH")] - publish_branch: Option, - - /// Save publish summary to pnpm-publish-summary.json (pnpm-specific) - #[arg(long)] - report_summary: bool, - - /// Force publish - #[arg(long)] - force: bool, - - /// Output in JSON format (pnpm-specific) - #[arg(long)] - json: bool, - - /// Publish all workspace packages - #[arg(short = 'r', long)] - recursive: bool, - - /// Filter packages in monorepo (can be used multiple times) - #[arg(long, value_name = "PATTERN")] - filter: Option>, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - - /// Manage package owners - #[command(subcommand, alias = "author")] - Owner(OwnerCommands), - - /// Manage package cache - Cache { - /// Subcommand: dir, path, clean - #[arg(required = true)] - subcommand: String, - - /// Additional arguments to pass through to the package manager - #[arg(last = true, allow_hyphen_values = true)] - pass_through_args: Option>, - }, - - /// Manage package manager configuration - #[command(subcommand, alias = "c")] - Config(ConfigCommands), -} - -#[derive(Subcommand, Debug, Clone)] -pub enum ConfigCommands { - /// List all configuration - List { - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Use global config - #[arg(short = 'g', long)] - global: bool, - - /// Config location: project (default) or global - #[arg(long, value_name = "LOCATION")] - location: Option, - }, - - /// Get configuration value - Get { - /// Config key - key: String, - - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Use global config - #[arg(short = 'g', long)] - global: bool, - - /// Config location: project (default) or global - #[arg(long, value_name = "LOCATION")] - location: Option, - }, - - /// Set configuration value - Set { - /// Config key - key: String, - - /// Config value - value: String, - - /// Output in JSON format - #[arg(long)] - json: bool, - - /// Use global config - #[arg(short = 'g', long)] - global: bool, - - /// Config location: project (default) or global - #[arg(long, value_name = "LOCATION")] - location: Option, - }, - - /// Delete configuration key - Delete { - /// Config key - key: String, - - /// Use global config - #[arg(short = 'g', long)] - global: bool, - - /// Config location: project (default) or global - #[arg(long, value_name = "LOCATION")] - location: Option, - }, -} - -#[derive(Subcommand, Debug, Clone)] -pub enum OwnerCommands { - /// List package owners - #[command(alias = "ls")] - List { - /// Package name - package: String, - - /// One-time password for authentication - #[arg(long, value_name = "OTP")] - otp: Option, - }, - - /// Add package owner - Add { - /// Username - user: String, - /// Package name - package: String, - - /// One-time password for authentication - #[arg(long, value_name = "OTP")] - otp: Option, - }, - - /// Remove package owner - Rm { - /// Username - user: String, - /// Package name - package: String, - - /// One-time password for authentication - #[arg(long, value_name = "OTP")] - otp: Option, - }, } impl Commands { /// Check if this command is a package manager command that should skip auto-install pub fn is_package_manager_command(&self) -> bool { - matches!( - self, - Commands::Install { .. } - | Commands::Add { .. } - | Commands::Remove { .. } - | Commands::Dedupe { .. } - | Commands::Outdated { .. } - | Commands::Why { .. } - | Commands::Link { .. } - | Commands::Unlink { .. } - | Commands::Pm(..) - ) + matches!(self, Commands::Install { .. }) } } @@ -1062,235 +436,7 @@ pub async fn main< } // package manager commands - Commands::Install { args } => { - // Check if args contain packages - if yes, redirect to Add command - // This allows `vite install ` to work as an alias for `vite add ` - if let Some(Commands::Add { - filter, - workspace_root, - workspace, - packages, - save_prod, - save_dev, - save_peer, - save_optional, - save_exact, - save_catalog, - save_catalog_name, - global, - allow_build, - pass_through_args, - }) = parse_install_as_add(args) - { - let exit_status = execute_add_command( - cwd, - &packages, - save_prod, - save_dev, - save_peer, - save_optional, - save_exact, - save_catalog, - save_catalog_name.as_deref(), - filter.as_deref(), - workspace_root, - workspace, - global, - allow_build.as_deref(), - pass_through_args.as_deref(), - ) - .await?; - return Ok(exit_status); - } else { - InstallCommand::builder(cwd).build().execute(args).await? - } - } - Commands::Add { - filter, - workspace_root, - workspace, - packages, - save_prod, - save_dev, - save_peer, - save_optional, - save_exact, - save_catalog, - save_catalog_name, - global, - allow_build, - pass_through_args, - } => { - let exit_status = execute_add_command( - cwd, - packages, - *save_prod, - *save_dev, - *save_peer, - *save_optional, - *save_exact, - *save_catalog, - save_catalog_name.as_deref(), - filter.as_deref(), - *workspace_root, - *workspace, - *global, - allow_build.as_deref(), - pass_through_args.as_deref(), - ) - .await?; - return Ok(exit_status); - } - Commands::Remove { - save_dev, - save_optional, - save_prod, - filter, - workspace_root, - recursive, - global, - packages, - pass_through_args, - } => { - let exit_status = RemoveCommand::new(cwd) - .execute( - packages, - *save_dev, - *save_optional, - *save_prod, - filter.as_deref(), - *workspace_root, - *recursive, - *global, - pass_through_args.as_deref(), - ) - .await?; - return Ok(exit_status); - } - Commands::Update { - latest, - global, - recursive, - filter, - workspace_root, - dev, - prod, - interactive, - no_optional, - no_save, - workspace, - packages, - pass_through_args, - } => { - let exit_status = UpdateCommand::new(cwd) - .execute( - packages, - *latest, - *global, - *recursive, - filter.as_deref(), - *workspace_root, - *dev, - *prod, - *interactive, - *no_optional, - *no_save, - *workspace, - pass_through_args.as_deref(), - ) - .await?; - return Ok(exit_status); - } - Commands::Dedupe { check, pass_through_args } => { - let exit_status = - DedupeCommand::new(cwd).execute(*check, pass_through_args.as_deref()).await?; - return Ok(exit_status); - } - Commands::Outdated { - packages, - long, - format, - recursive, - filter, - workspace_root, - prod, - dev, - no_optional, - compatible, - sort_by, - global, - pass_through_args, - } => { - let exit_status = OutdatedCommand::new(cwd) - .execute( - packages, - *long, - *format, - *recursive, - filter.as_deref(), - *workspace_root, - *prod, - *dev, - *no_optional, - *compatible, - sort_by.as_deref(), - *global, - pass_through_args.as_deref(), - ) - .await?; - return Ok(exit_status); - } - Commands::Link { package, args } => { - let exit_status = LinkCommand::new(cwd).execute(package.as_deref(), Some(args)).await?; - return Ok(exit_status); - } - Commands::Unlink { package, recursive, args } => { - let exit_status = - UnlinkCommand::new(cwd).execute(package.as_deref(), *recursive, Some(args)).await?; - return Ok(exit_status); - } - Commands::Why { - packages, - json, - long, - parseable, - recursive, - filter, - workspace_root, - prod, - dev, - depth, - no_optional, - global, - exclude_peers, - find_by, - pass_through_args, - } => { - let exit_status = WhyCommand::new(cwd) - .execute( - packages, - *json, - *long, - *parseable, - *recursive, - filter.as_deref(), - *workspace_root, - *prod, - *dev, - *depth, - *no_optional, - *global, - *exclude_peers, - find_by.as_deref(), - pass_through_args.as_deref(), - ) - .await?; - return Ok(exit_status); - } - Commands::Pm(pm_command) => { - let exit_status = PmCommand::new(cwd).execute(pm_command.clone()).await?; - return Ok(exit_status); - } + Commands::Install { args } => InstallCommand::builder(cwd).build().execute(args).await?, }; let execution_summary_dir = EXECUTION_SUMMARY_DIR.as_path(); @@ -1398,76 +544,6 @@ async fn read_vite_config_from_workspace_root< Ok(None) } -/// Check if install args contain packages (non-flag arguments). -/// If packages are detected, reparse as Add command. -fn parse_install_as_add(args: &[String]) -> Option { - // Check if there are any non-flag arguments (potential package names) - let has_packages = args.iter().any(|arg| !arg.starts_with('-')); - - if !has_packages { - return None; - } - - // Reconstruct command line with "add" subcommand - let mut cmd_args = vec!["vite".to_string(), "add".to_string()]; - cmd_args.extend_from_slice(args); - - // Try to parse as Add command - match Args::try_parse_from(&cmd_args) { - Ok(parsed_args) => Some(parsed_args.commands), - Err(_) => None, // If parsing fails, fall back to regular install - } -} - -/// Execute add command with the given parameters -async fn execute_add_command( - cwd: AbsolutePathBuf, - packages: &[String], - save_prod: bool, - save_dev: bool, - save_peer: bool, - save_optional: bool, - save_exact: bool, - save_catalog: bool, - save_catalog_name: Option<&str>, - filter: Option<&[String]>, - workspace_root: bool, - workspace: bool, - global: bool, - allow_build: Option<&str>, - pass_through_args: Option<&[String]>, -) -> Result { - let save_dependency_type = if save_dev { - Some(SaveDependencyType::Dev) - } else if save_peer { - Some(SaveDependencyType::Peer) - } else if save_optional { - Some(SaveDependencyType::Optional) - } else if save_prod { - Some(SaveDependencyType::Production) - } else { - None - }; - - // empty string means save as `catalog:` - let save_catalog_name = if save_catalog { Some("") } else { save_catalog_name }; - - AddCommand::new(cwd) - .execute( - packages, - save_dependency_type, - save_exact, - save_catalog_name, - filter, - workspace_root, - workspace, - global, - allow_build, - pass_through_args, - ) - .await -} - #[cfg(test)] mod tests { use clap::Parser; @@ -1946,1018 +1022,4 @@ mod tests { std::env::remove_var("VITE_TASK_EXECUTION_ENV"); } } - - mod install_as_add_tests { - use super::*; - - #[test] - fn test_parse_install_as_add_with_packages() { - let args = vec!["react".to_string(), "react-dom".to_string()]; - let result = parse_install_as_add(&args); - assert!(result.is_some()); - if let Some(Commands::Add { packages, save_dev, save_exact, .. }) = result { - assert_eq!(packages, vec!["react", "react-dom"]); - assert!(!save_dev); - assert!(!save_exact); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_parse_install_as_add_with_dev_flag() { - let args = vec!["-D".to_string(), "typescript".to_string()]; - let result = parse_install_as_add(&args); - assert!(result.is_some()); - if let Some(Commands::Add { packages, save_dev, .. }) = result { - assert_eq!(packages, vec!["typescript"]); - assert!(save_dev); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_parse_install_as_add_without_packages() { - let args = vec![]; - let result = parse_install_as_add(&args); - assert!(result.is_none()); - } - - #[test] - fn test_parse_install_as_add_with_only_flags() { - let args = vec!["--some-install-flag".to_string()]; - let result = parse_install_as_add(&args); - assert!(result.is_none()); - } - - #[test] - fn test_parse_install_as_add_complex() { - let args = vec![ - "-D".to_string(), - "-E".to_string(), - "--filter".to_string(), - "app".to_string(), - "typescript".to_string(), - "eslint".to_string(), - ]; - let result = parse_install_as_add(&args); - assert!(result.is_some()); - if let Some(Commands::Add { packages, save_dev, save_exact, filter, .. }) = result { - assert_eq!(packages, vec!["typescript", "eslint"]); - assert!(save_dev); - assert!(save_exact); - assert_eq!(filter.unwrap(), vec!["app"]); - } else { - panic!("Expected Add command"); - } - } - } - - mod add_command_tests { - use super::*; - - #[test] - fn test_args_add_command() { - let args = Args::try_parse_from(&["vite-plus", "add", "react"]).unwrap(); - if let Commands::Add { filter, workspace_root, workspace, packages, .. } = - &args.commands - { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(filter.is_none()); - assert!(!workspace_root); - assert!(!workspace); - } else { - panic!("Expected Add command"); - } - - let args = Args::try_parse_from(&["vite-plus", "add", "--save-peer", "react"]).unwrap(); - if let Commands::Add { - filter, workspace_root, workspace, packages, save_peer, .. - } = &args.commands - { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(filter.is_none()); - assert!(!workspace_root); - assert!(!workspace); - assert!(save_peer); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_args_add_command_with_workspace_root() { - let args = Args::try_parse_from(&["vite-plus", "add", "-w", "react"]).unwrap(); - if let Commands::Add { filter, workspace_root, workspace, packages, .. } = - &args.commands - { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(filter.is_none()); - assert!(workspace_root); - assert!(!workspace); - } else { - panic!("Expected Add command"); - } - let args = Args::try_parse_from(&["vite-plus", "add", "react", "-w"]).unwrap(); - if let Commands::Add { filter, workspace_root, workspace, packages, .. } = - &args.commands - { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(filter.is_none()); - assert!(workspace_root); - assert!(!workspace); - } else { - panic!("Expected Add command"); - } - - let args = - Args::try_parse_from(&["vite-plus", "add", "react", "--workspace-root"]).unwrap(); - if let Commands::Add { filter, workspace_root, workspace, packages, .. } = - &args.commands - { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(filter.is_none()); - assert!(workspace_root); - assert!(!workspace); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_args_add_command_multiple_packages() { - let args = - Args::try_parse_from(&["vite-plus", "add", "react", "react-dom", "@types/react"]) - .unwrap(); - if let Commands::Add { packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react", "react-dom", "@types/react"]); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_args_add_command_with_flags() { - let args = Args::try_parse_from(&[ - "vite-plus", - "add", - "--filter", - "app", - "-w", - "--workspace", - "typescript", - "-D", - ]) - .unwrap(); - if let Commands::Add { filter, workspace_root, workspace, packages, save_dev, .. } = - &args.commands - { - assert_eq!(filter, &Some(vec!["app".to_string()])); - assert!(workspace_root); - assert!(workspace); - assert_eq!(packages, &vec!["typescript"]); - assert!(save_dev); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_args_add_command_with_allow_build() { - let args = Args::try_parse_from(&[ - "vite-plus", - "add", - "--filter", - "app", - "-w", - "--workspace", - "typescript", - "-D", - "--allow-build=react,napi", - ]) - .unwrap(); - if let Commands::Add { - filter, - workspace_root, - workspace, - packages, - save_dev, - allow_build, - .. - } = &args.commands - { - assert_eq!(filter, &Some(vec!["app".to_string()])); - assert!(workspace_root); - assert!(workspace); - assert_eq!(packages, &vec!["typescript"]); - assert!(save_dev); - assert_eq!(allow_build, &Some("react,napi".to_string())); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_args_add_command_multiple_filters() { - let args = Args::try_parse_from(&[ - "vite-plus", - "add", - "--filter", - "app", - "--filter", - "web", - "react", - ]) - .unwrap(); - if let Commands::Add { filter, packages, .. } = &args.commands { - assert_eq!(filter, &Some(vec!["app".to_string(), "web".to_string()])); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Add command"); - } - } - - #[test] - fn test_args_add_command_invalid_filter() { - let args = Args::try_parse_from(&["vite-plus", "add", "react", "--filter"]); - assert!(args.is_err()); - } - - #[test] - fn test_args_add_command_with_pass_through_args() { - let args = Args::try_parse_from(&[ - "vite-plus", - "add", - "react", - "--", - "--watch", - "--mode=production", - "--use-stderr", - ]) - .unwrap(); - if let Commands::Add { packages, pass_through_args, .. } = &args.commands { - assert_eq!(packages, &vec!["react"]); - assert_eq!( - pass_through_args, - &Some(vec![ - "--watch".to_string(), - "--mode=production".to_string(), - "--use-stderr".to_string() - ]) - ); - } else { - panic!("Expected Add command"); - } - - let args = Args::try_parse_from(&[ - "vite-plus", - "add", - "react", - "napi", - "--", - "--allow-build=react,napi", - ]) - .unwrap(); - if let Commands::Add { packages, pass_through_args, .. } = &args.commands { - assert_eq!(packages, &vec!["react", "napi"]); - assert_eq!(pass_through_args, &Some(vec!["--allow-build=react,napi".to_string()])); - } else { - panic!("Expected Add command"); - } - } - } - - mod remove_command_tests { - use super::*; - - #[test] - fn test_args_remove_command() { - let args = Args::try_parse_from(&["vite-plus", "remove", "react"]).unwrap(); - if let Commands::Remove { - save_dev, - save_optional, - save_prod, - filter, - workspace_root, - recursive, - global, - packages, - pass_through_args, - } = &args.commands - { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(!save_dev); - assert!(!save_optional); - assert!(!save_prod); - assert!(filter.is_none()); - assert!(!workspace_root); - assert!(!recursive); - assert!(!global); - assert!(pass_through_args.is_none()); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_dev_flag() { - let args = Args::try_parse_from(&["vite-plus", "remove", "-D", "typescript"]).unwrap(); - if let Commands::Remove { save_dev, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["typescript".to_string()]); - assert!(save_dev); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_optional_flag() { - let args = Args::try_parse_from(&["vite-plus", "remove", "-O", "lodash"]).unwrap(); - if let Commands::Remove { save_optional, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["lodash".to_string()]); - assert!(save_optional); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_prod_flag() { - let args = Args::try_parse_from(&["vite-plus", "remove", "-P", "express"]).unwrap(); - if let Commands::Remove { save_prod, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["express".to_string()]); - assert!(save_prod); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_workspace_root() { - let args = Args::try_parse_from(&["vite-plus", "remove", "-w", "react"]).unwrap(); - if let Commands::Remove { workspace_root, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(workspace_root); - } else { - panic!("Expected Remove command"); - } - - let args = Args::try_parse_from(&["vite-plus", "remove", "react", "--workspace-root"]) - .unwrap(); - if let Commands::Remove { workspace_root, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(workspace_root); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_recursive() { - let args = Args::try_parse_from(&["vite-plus", "remove", "-r", "react"]).unwrap(); - if let Commands::Remove { recursive, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(recursive); - } else { - panic!("Expected Remove command"); - } - - let args = - Args::try_parse_from(&["vite-plus", "remove", "react", "--recursive"]).unwrap(); - if let Commands::Remove { recursive, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react".to_string()]); - assert!(recursive); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_global() { - let args = Args::try_parse_from(&["vite-plus", "remove", "-g", "npm"]).unwrap(); - if let Commands::Remove { global, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["npm".to_string()]); - assert!(global); - } else { - panic!("Expected Remove command"); - } - - let args = Args::try_parse_from(&["vite-plus", "remove", "npm", "--global"]).unwrap(); - if let Commands::Remove { global, packages, .. } = &args.commands { - assert_eq!(packages, &vec!["npm".to_string()]); - assert!(global); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_multiple_packages() { - let args = Args::try_parse_from(&[ - "vite-plus", - "remove", - "react", - "react-dom", - "@types/react", - ]) - .unwrap(); - if let Commands::Remove { packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react", "react-dom", "@types/react"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_single_filter() { - let args = - Args::try_parse_from(&["vite-plus", "remove", "--filter", "app", "typescript"]) - .unwrap(); - if let Commands::Remove { filter, packages, .. } = &args.commands { - assert_eq!(filter, &Some(vec!["app".to_string()])); - assert_eq!(packages, &vec!["typescript"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_multiple_filters() { - let args = Args::try_parse_from(&[ - "vite-plus", - "remove", - "--filter", - "app", - "--filter", - "web", - "react", - ]) - .unwrap(); - if let Commands::Remove { filter, packages, .. } = &args.commands { - assert_eq!(filter, &Some(vec!["app".to_string(), "web".to_string()])); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_combined_flags() { - let args = Args::try_parse_from(&[ - "vite-plus", - "remove", - "-D", - "-w", - "--filter", - "app", - "typescript", - "eslint", - ]) - .unwrap(); - if let Commands::Remove { save_dev, workspace_root, filter, packages, .. } = - &args.commands - { - assert!(save_dev); - assert!(workspace_root); - assert_eq!(filter, &Some(vec!["app".to_string()])); - assert_eq!(packages, &vec!["typescript", "eslint"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_with_pass_through_args() { - let args = Args::try_parse_from(&[ - "vite-plus", - "remove", - "react", - "--", - "--ignore-scripts", - "--force", - ]) - .unwrap(); - if let Commands::Remove { packages, pass_through_args, .. } = &args.commands { - assert_eq!(packages, &vec!["react"]); - assert_eq!( - pass_through_args, - &Some(vec!["--ignore-scripts".to_string(), "--force".to_string()]) - ); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_alias_rm() { - let args = Args::try_parse_from(&["vite-plus", "rm", "react"]).unwrap(); - if let Commands::Remove { packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_alias_un() { - let args = Args::try_parse_from(&["vite-plus", "un", "react"]).unwrap(); - if let Commands::Remove { packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_alias_uninstall() { - let args = Args::try_parse_from(&["vite-plus", "uninstall", "react"]).unwrap(); - if let Commands::Remove { packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Remove command"); - } - } - - #[test] - fn test_args_remove_command_invalid_filter() { - let args = Args::try_parse_from(&["vite-plus", "remove", "react", "--filter"]); - assert!(args.is_err()); - } - - #[test] - fn test_args_remove_command_complex_scenario() { - let args = Args::try_parse_from(&[ - "vite-plus", - "remove", - "-D", - "-r", - "--filter", - "app", - "--filter", - "web", - "typescript", - "eslint", - "@types/node", - "--", - "--ignore-scripts", - ]) - .unwrap(); - if let Commands::Remove { - save_dev, - recursive, - filter, - packages, - pass_through_args, - .. - } = &args.commands - { - assert!(save_dev); - assert!(recursive); - assert_eq!(filter, &Some(vec!["app".to_string(), "web".to_string()])); - assert_eq!(packages, &vec!["typescript", "eslint", "@types/node"]); - assert_eq!(pass_through_args, &Some(vec!["--ignore-scripts".to_string()])); - } else { - panic!("Expected Remove command"); - } - } - } - - mod update_command_tests { - use super::*; - - #[test] - fn test_args_update_command_basic() { - let args = Args::try_parse_from(&["vite-plus", "update"]).unwrap(); - if let Commands::Update { - latest, - global, - recursive, - filter, - workspace_root, - dev, - prod, - interactive, - no_optional, - no_save, - workspace, - packages, - .. - } = &args.commands - { - assert!(!latest); - assert!(!global); - assert!(!recursive); - assert!(filter.is_none()); - assert!(!workspace_root); - assert!(!dev); - assert!(!prod); - assert!(!interactive); - assert!(!no_optional); - assert!(!no_save); - assert!(!workspace); - assert!(packages.is_empty()); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_alias() { - let args = Args::try_parse_from(&["vite-plus", "up"]).unwrap(); - assert!(matches!(args.commands, Commands::Update { .. })); - } - - #[test] - fn test_args_update_command_with_packages() { - let args = - Args::try_parse_from(&["vite-plus", "update", "react", "react-dom"]).unwrap(); - if let Commands::Update { packages, .. } = &args.commands { - assert_eq!(packages, &vec!["react", "react-dom"]); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_latest_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-L", "react"]).unwrap(); - if let Commands::Update { latest, packages, .. } = &args.commands { - assert!(latest); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--latest", "react"]).unwrap(); - if let Commands::Update { latest, packages, .. } = &args.commands { - assert!(latest); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_global_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-g"]).unwrap(); - if let Commands::Update { global, .. } = &args.commands { - assert!(global); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--global"]).unwrap(); - if let Commands::Update { global, .. } = &args.commands { - assert!(global); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_recursive_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-r"]).unwrap(); - if let Commands::Update { recursive, .. } = &args.commands { - assert!(recursive); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--recursive"]).unwrap(); - if let Commands::Update { recursive, .. } = &args.commands { - assert!(recursive); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_workspace_root_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-w"]).unwrap(); - if let Commands::Update { workspace_root, .. } = &args.commands { - assert!(workspace_root); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--workspace-root"]).unwrap(); - if let Commands::Update { workspace_root, .. } = &args.commands { - assert!(workspace_root); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_dev_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-D"]).unwrap(); - if let Commands::Update { dev, .. } = &args.commands { - assert!(dev); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--dev"]).unwrap(); - if let Commands::Update { dev, .. } = &args.commands { - assert!(dev); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_prod_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-P"]).unwrap(); - if let Commands::Update { prod, .. } = &args.commands { - assert!(prod); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--prod"]).unwrap(); - if let Commands::Update { prod, .. } = &args.commands { - assert!(prod); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_interactive_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "-i"]).unwrap(); - if let Commands::Update { interactive, .. } = &args.commands { - assert!(interactive); - } else { - panic!("Expected Update command"); - } - - let args = Args::try_parse_from(&["vite-plus", "update", "--interactive"]).unwrap(); - if let Commands::Update { interactive, .. } = &args.commands { - assert!(interactive); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_no_optional_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "--no-optional"]).unwrap(); - if let Commands::Update { no_optional, .. } = &args.commands { - assert!(no_optional); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_no_save_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "--no-save"]).unwrap(); - if let Commands::Update { no_save, .. } = &args.commands { - assert!(no_save); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_workspace_flag() { - let args = Args::try_parse_from(&["vite-plus", "update", "--workspace"]).unwrap(); - if let Commands::Update { workspace, .. } = &args.commands { - assert!(workspace); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_filter() { - let args = - Args::try_parse_from(&["vite-plus", "update", "--filter", "app", "react"]).unwrap(); - if let Commands::Update { filter, packages, .. } = &args.commands { - assert_eq!(filter, &Some(vec!["app".to_string()])); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_multiple_filters() { - let args = Args::try_parse_from(&[ - "vite-plus", - "update", - "--filter", - "app", - "--filter", - "web", - "react", - ]) - .unwrap(); - if let Commands::Update { filter, packages, .. } = &args.commands { - assert_eq!(filter, &Some(vec!["app".to_string(), "web".to_string()])); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_combined_flags() { - let args = Args::try_parse_from(&[ - "vite-plus", - "update", - "-L", - "-r", - "-D", - "--filter", - "app", - "typescript", - "eslint", - ]) - .unwrap(); - if let Commands::Update { latest, recursive, dev, filter, packages, .. } = - &args.commands - { - assert!(latest); - assert!(recursive); - assert!(dev); - assert_eq!(filter, &Some(vec!["app".to_string()])); - assert_eq!(packages, &vec!["typescript", "eslint"]); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_with_pass_through_args() { - let args = Args::try_parse_from(&[ - "vite-plus", - "update", - "react", - "--", - "--registry", - "https://custom-registry.com", - ]) - .unwrap(); - if let Commands::Update { packages, pass_through_args, .. } = &args.commands { - assert_eq!(packages, &vec!["react"]); - assert_eq!( - pass_through_args, - &Some(vec![ - "--registry".to_string(), - "https://custom-registry.com".to_string() - ]) - ); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_complex_scenario() { - let args = Args::try_parse_from(&[ - "vite-plus", - "update", - "-L", - "-r", - "-w", - "-D", - "--filter", - "app", - "--filter", - "web", - "--no-optional", - "react", - "vue", - "--", - "--registry", - "https://registry.npmjs.org", - ]) - .unwrap(); - if let Commands::Update { - latest, - recursive, - workspace_root, - dev, - filter, - no_optional, - packages, - pass_through_args, - .. - } = &args.commands - { - assert!(latest); - assert!(recursive); - assert!(workspace_root); - assert!(dev); - assert_eq!(filter, &Some(vec!["app".to_string(), "web".to_string()])); - assert!(no_optional); - assert_eq!(packages, &vec!["react", "vue"]); - assert_eq!( - pass_through_args, - &Some(vec!["--registry".to_string(), "https://registry.npmjs.org".to_string()]) - ); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_all_packages() { - // When no packages are specified, should update all packages - let args = Args::try_parse_from(&["vite-plus", "update", "-r"]).unwrap(); - if let Commands::Update { recursive, packages, .. } = &args.commands { - assert!(recursive); - assert!(packages.is_empty()); - } else { - panic!("Expected Update command"); - } - } - - #[test] - fn test_args_update_command_workspace_combinations() { - // Test --workspace-root with --recursive - let args = Args::try_parse_from(&["vite-plus", "update", "-w", "-r"]).unwrap(); - if let Commands::Update { workspace_root, recursive, .. } = &args.commands { - assert!(workspace_root); - assert!(recursive); - } else { - panic!("Expected Update command"); - } - - // Test --workspace flag - let args = - Args::try_parse_from(&["vite-plus", "update", "--workspace", "react"]).unwrap(); - if let Commands::Update { workspace, packages, .. } = &args.commands { - assert!(workspace); - assert_eq!(packages, &vec!["react"]); - } else { - panic!("Expected Update command"); - } - } - } - - mod dedupe_command_tests { - use super::*; - - #[test] - fn test_args_dedupe_command_basic() { - let args = Args::try_parse_from(&["vite-plus", "dedupe"]).unwrap(); - if let Commands::Dedupe { check, .. } = &args.commands { - assert!(!check); - } else { - panic!("Expected Dedupe command"); - } - } - - #[test] - fn test_args_dedupe_command_with_alias() { - let args = Args::try_parse_from(&["vite-plus", "ddp"]).unwrap(); - assert!(matches!(args.commands, Commands::Dedupe { .. })); - } - - #[test] - fn test_args_dedupe_command_with_check() { - let args = Args::try_parse_from(&["vite-plus", "dedupe", "--check"]).unwrap(); - if let Commands::Dedupe { check, .. } = &args.commands { - assert!(check); - } else { - panic!("Expected Dedupe command"); - } - } - - #[test] - fn test_args_dedupe_command_with_pass_through_args() { - let args = Args::try_parse_from(&[ - "vite-plus", - "dedupe", - "--", - "--some-flag", - "--another-flag", - ]) - .unwrap(); - if let Commands::Dedupe { pass_through_args, .. } = &args.commands { - assert_eq!( - pass_through_args, - &Some(vec!["--some-flag".to_string(), "--another-flag".to_string()]) - ); - } else { - panic!("Expected Dedupe command"); - } - } - - #[test] - fn test_args_dedupe_command_with_check_and_pass_through() { - let args = - Args::try_parse_from(&["vite-plus", "dedupe", "--check", "--", "--custom-flag"]) - .unwrap(); - if let Commands::Dedupe { check, pass_through_args, .. } = &args.commands { - assert!(check); - assert_eq!(pass_through_args, &Some(vec!["--custom-flag".to_string()])); - } else { - panic!("Expected Dedupe command"); - } - } - } } diff --git a/packages/cli/binding/src/commands/add.rs b/packages/cli/binding/src/commands/add.rs deleted file mode 100644 index a0944e5e93..0000000000 --- a/packages/cli/binding/src/commands/add.rs +++ /dev/null @@ -1,72 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{ - commands::add::{AddCommandOptions, SaveDependencyType}, - package_manager::PackageManager, -}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Add command for adding packages to dependencies. -/// -/// This command automatically detects the package manager and translates -/// the add command to the appropriate package manager-specific syntax. -pub struct AddCommand { - cwd: AbsolutePathBuf, -} - -impl AddCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute( - self, - packages: &[String], - save_dependency_type: Option, - save_exact: bool, - save_catalog_name: Option<&str>, - filters: Option<&[String]>, - workspace_root: bool, - workspace_only: bool, - global: bool, - allow_build: Option<&str>, - pass_through_args: Option<&[String]>, - ) -> Result { - let add_command_options = AddCommandOptions { - packages, - save_dependency_type, - save_exact, - filters, - workspace_root, - workspace_only, - global, - save_catalog_name, - allow_build, - pass_through_args, - }; - - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - package_manager.run_add_command(&add_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_add_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = AddCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/dedupe.rs b/packages/cli/binding/src/commands/dedupe.rs deleted file mode 100644 index f1e407ab8e..0000000000 --- a/packages/cli/binding/src/commands/dedupe.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{commands::dedupe::DedupeCommandOptions, package_manager::PackageManager}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Dedupe command for deduplicating dependencies by removing older versions. -/// -/// This command automatically detects the package manager and translates -/// the dedupe command to the appropriate package manager-specific syntax. -pub struct DedupeCommand { - cwd: AbsolutePathBuf, -} - -impl DedupeCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute( - self, - check: bool, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let dedupe_command_options = DedupeCommandOptions { check, pass_through_args }; - package_manager.run_dedupe_command(&dedupe_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_dedupe_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = DedupeCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/link.rs b/packages/cli/binding/src/commands/link.rs deleted file mode 100644 index 681a904b1c..0000000000 --- a/packages/cli/binding/src/commands/link.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{commands::link::LinkCommandOptions, package_manager::PackageManager}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Link command for local package development. -/// -/// This command automatically detects the package manager and translates -/// the link command to the appropriate package manager-specific syntax. -pub struct LinkCommand { - cwd: AbsolutePathBuf, -} - -impl LinkCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute( - self, - package: Option<&str>, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let link_command_options = LinkCommandOptions { package, pass_through_args }; - package_manager.run_link_command(&link_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_link_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = LinkCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/mod.rs b/packages/cli/binding/src/commands/mod.rs index 4d1a9c8850..e523b8a314 100644 --- a/packages/cli/binding/src/commands/mod.rs +++ b/packages/cli/binding/src/commands/mod.rs @@ -1,16 +1,7 @@ -pub(crate) mod add; -pub(crate) mod dedupe; pub(crate) mod doc; pub(crate) mod fmt; pub(crate) mod install; pub(crate) mod lib_cmd; -pub(crate) mod link; pub(crate) mod lint; -pub(crate) mod outdated; -pub(crate) mod pm; -pub(crate) mod remove; pub(crate) mod test; -pub(crate) mod unlink; -pub(crate) mod update; pub(crate) mod vite; -pub(crate) mod why; diff --git a/packages/cli/binding/src/commands/outdated.rs b/packages/cli/binding/src/commands/outdated.rs deleted file mode 100644 index e1d8f4fdb6..0000000000 --- a/packages/cli/binding/src/commands/outdated.rs +++ /dev/null @@ -1,78 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{ - commands::outdated::{Format, OutdatedCommandOptions}, - package_manager::PackageManager, -}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Outdated command for checking outdated packages. -/// -/// This command automatically detects the package manager and translates -/// the outdated command to the appropriate package manager-specific syntax. -pub struct OutdatedCommand { - cwd: AbsolutePathBuf, -} - -impl OutdatedCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - #[allow(clippy::too_many_arguments)] - pub async fn execute( - self, - packages: &[String], - long: bool, - format: Option, - recursive: bool, - filters: Option<&[String]>, - workspace_root: bool, - prod: bool, - dev: bool, - no_optional: bool, - compatible: bool, - sort_by: Option<&str>, - global: bool, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let outdated_command_options = OutdatedCommandOptions { - packages, - long, - format, - recursive, - filters, - workspace_root, - prod, - dev, - no_optional, - compatible, - sort_by, - global, - pass_through_args, - }; - package_manager.run_outdated_command(&outdated_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_outdated_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = OutdatedCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/pm.rs b/packages/cli/binding/src/commands/pm.rs deleted file mode 100644 index 7cf400caf7..0000000000 --- a/packages/cli/binding/src/commands/pm.rs +++ /dev/null @@ -1,225 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{ - commands::{ - cache::CacheCommandOptions, config::ConfigCommandOptions, list::ListCommandOptions, - owner::OwnerSubcommand, pack::PackCommandOptions, prune::PruneCommandOptions, - publish::PublishCommandOptions, view::ViewCommandOptions, - }, - package_manager::PackageManager, -}; -use vite_path::AbsolutePathBuf; - -use crate::{ - Error, - cli::{ConfigCommands, OwnerCommands, PmCommands}, -}; - -/// Package manager utilities command. -/// -/// This command provides a unified interface to package manager utilities -/// across pnpm, npm, and yarn. -pub struct PmCommand { - cwd: AbsolutePathBuf, -} - -impl PmCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute(self, command: PmCommands) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - match command { - PmCommands::Prune { prod, no_optional, pass_through_args } => { - let options = PruneCommandOptions { - prod, - no_optional, - pass_through_args: pass_through_args.as_deref(), - }; - package_manager.run_prune_command(&options, &self.cwd).await - } - PmCommands::Pack { - recursive, - filter, - out, - pack_destination, - pack_gzip_level, - json, - pass_through_args, - } => { - let options = PackCommandOptions { - recursive, - filters: filter.as_deref(), - out: out.as_deref(), - pack_destination: pack_destination.as_deref(), - pack_gzip_level, - json, - pass_through_args: pass_through_args.as_deref(), - }; - package_manager.run_pack_command(&options, &self.cwd).await - } - PmCommands::List { - pattern, - depth, - json, - long, - parseable, - prod, - dev, - no_optional, - exclude_peers, - only_projects, - find_by, - recursive, - filter, - global, - pass_through_args, - } => { - let options = ListCommandOptions { - pattern: pattern.as_deref(), - depth, - json, - long, - parseable, - prod, - dev, - no_optional, - exclude_peers, - only_projects, - find_by: find_by.as_deref(), - recursive, - filters: if filter.is_empty() { None } else { Some(&filter) }, - global, - pass_through_args: pass_through_args.as_deref(), - }; - package_manager.run_list_command(&options, &self.cwd).await - } - PmCommands::View { package, field, json, pass_through_args } => { - let options = ViewCommandOptions { - package: &package, - field: field.as_deref(), - json, - pass_through_args: pass_through_args.as_deref(), - }; - package_manager.run_view_command(&options, &self.cwd).await - } - PmCommands::Publish { - target, - dry_run, - tag, - access, - otp, - no_git_checks, - publish_branch, - report_summary, - force, - json, - recursive, - filter, - pass_through_args, - } => { - let options = PublishCommandOptions { - target: target.as_deref(), - dry_run, - tag: tag.as_deref(), - access: access.as_deref(), - otp: otp.as_deref(), - no_git_checks, - publish_branch: publish_branch.as_deref(), - report_summary, - force, - json, - recursive, - filters: filter.as_deref(), - pass_through_args: pass_through_args.as_deref(), - }; - package_manager.run_publish_command(&options, &self.cwd).await - } - PmCommands::Owner(owner_command) => { - let subcommand = match owner_command { - OwnerCommands::List { package, otp } => OwnerSubcommand::List { package, otp }, - OwnerCommands::Add { user, package, otp } => { - OwnerSubcommand::Add { user, package, otp } - } - OwnerCommands::Rm { user, package, otp } => { - OwnerSubcommand::Rm { user, package, otp } - } - }; - package_manager.run_owner_command(&subcommand, &self.cwd).await - } - PmCommands::Cache { subcommand, pass_through_args } => { - let options = CacheCommandOptions { - subcommand: &subcommand, - pass_through_args: pass_through_args.as_deref(), - }; - package_manager.run_cache_command(&options, &self.cwd).await - } - PmCommands::Config(config_command) => match config_command { - ConfigCommands::List { json, global, location } => { - let options = ConfigCommandOptions { - subcommand: "list", - key: None, - value: None, - json, - location: if global { Some("global") } else { location.as_deref() }, - pass_through_args: None, - }; - package_manager.run_config_command(&options, &self.cwd).await - } - ConfigCommands::Get { key, json, global, location } => { - let options = ConfigCommandOptions { - subcommand: "get", - key: Some(key.as_str()), - value: None, - json, - location: if global { Some("global") } else { location.as_deref() }, - pass_through_args: None, - }; - package_manager.run_config_command(&options, &self.cwd).await - } - ConfigCommands::Set { key, value, json, global, location } => { - let options = ConfigCommandOptions { - subcommand: "set", - key: Some(key.as_str()), - value: Some(value.as_str()), - json, - location: if global { Some("global") } else { location.as_deref() }, - pass_through_args: None, - }; - package_manager.run_config_command(&options, &self.cwd).await - } - ConfigCommands::Delete { key, global, location } => { - let options = ConfigCommandOptions { - subcommand: "delete", - key: Some(key.as_str()), - value: None, - json: false, - location: if global { Some("global") } else { location.as_deref() }, - pass_through_args: None, - }; - package_manager.run_config_command(&options, &self.cwd).await - } - }, - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_pm_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = PmCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/remove.rs b/packages/cli/binding/src/commands/remove.rs deleted file mode 100644 index f227bbc3ca..0000000000 --- a/packages/cli/binding/src/commands/remove.rs +++ /dev/null @@ -1,66 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{commands::remove::RemoveCommandOptions, package_manager::PackageManager}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Remove command for removing packages from dependencies. -/// -/// This command automatically detects the package manager and translates -/// the remove command to the appropriate package manager-specific syntax. -pub struct RemoveCommand { - cwd: AbsolutePathBuf, -} - -impl RemoveCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute( - self, - packages: &[String], - save_dev: bool, - save_optional: bool, - save_prod: bool, - filters: Option<&[String]>, - workspace_root: bool, - recursive: bool, - global: bool, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let remove_command_options = RemoveCommandOptions { - packages, - filters, - workspace_root, - recursive, - global, - save_dev, - save_optional, - save_prod, - pass_through_args, - }; - package_manager.run_remove_command(&remove_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_remove_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = RemoveCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/unlink.rs b/packages/cli/binding/src/commands/unlink.rs deleted file mode 100644 index ea72b62421..0000000000 --- a/packages/cli/binding/src/commands/unlink.rs +++ /dev/null @@ -1,50 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{commands::unlink::UnlinkCommandOptions, package_manager::PackageManager}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Unlink command for removing package links. -/// -/// This command automatically detects the package manager and translates -/// the unlink command to the appropriate package manager-specific syntax. -pub struct UnlinkCommand { - cwd: AbsolutePathBuf, -} - -impl UnlinkCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute( - self, - package: Option<&str>, - recursive: bool, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let unlink_command_options = UnlinkCommandOptions { package, recursive, pass_through_args }; - package_manager.run_unlink_command(&unlink_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_unlink_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = UnlinkCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/update.rs b/packages/cli/binding/src/commands/update.rs deleted file mode 100644 index eb84142137..0000000000 --- a/packages/cli/binding/src/commands/update.rs +++ /dev/null @@ -1,74 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{commands::update::UpdateCommandOptions, package_manager::PackageManager}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Update command for updating packages to their latest versions. -/// -/// This command automatically detects the package manager and translates -/// the update command to the appropriate package manager-specific syntax. -pub struct UpdateCommand { - cwd: AbsolutePathBuf, -} - -impl UpdateCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - pub async fn execute( - self, - packages: &[String], - latest: bool, - global: bool, - recursive: bool, - filters: Option<&[String]>, - workspace_root: bool, - dev: bool, - prod: bool, - interactive: bool, - no_optional: bool, - no_save: bool, - workspace_only: bool, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let update_command_options = UpdateCommandOptions { - packages, - latest, - global, - recursive, - filters, - workspace_root, - dev, - prod, - interactive, - no_optional, - no_save, - workspace_only, - pass_through_args, - }; - package_manager.run_update_command(&update_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_update_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = UpdateCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/binding/src/commands/why.rs b/packages/cli/binding/src/commands/why.rs deleted file mode 100644 index 67366bcd62..0000000000 --- a/packages/cli/binding/src/commands/why.rs +++ /dev/null @@ -1,79 +0,0 @@ -use std::process::ExitStatus; - -use vite_install::{commands::why::WhyCommandOptions, package_manager::PackageManager}; -use vite_path::AbsolutePathBuf; - -use crate::Error; - -/// Why command for showing why a package is installed. -/// -/// This command automatically detects the package manager and translates -/// the why command to the appropriate package manager-specific syntax. -pub struct WhyCommand { - cwd: AbsolutePathBuf, -} - -impl WhyCommand { - pub fn new(cwd: AbsolutePathBuf) -> Self { - Self { cwd } - } - - #[allow(clippy::too_many_arguments)] - pub async fn execute( - self, - packages: &[String], - json: bool, - long: bool, - parseable: bool, - recursive: bool, - filters: Option<&[String]>, - workspace_root: bool, - prod: bool, - dev: bool, - depth: Option, - no_optional: bool, - global: bool, - exclude_peers: bool, - find_by: Option<&str>, - pass_through_args: Option<&[String]>, - ) -> Result { - // Detect package manager - let package_manager = PackageManager::builder(&self.cwd).build_with_default().await?; - - let why_command_options = WhyCommandOptions { - packages, - json, - long, - parseable, - recursive, - filters, - workspace_root, - prod, - dev, - depth, - no_optional, - global, - exclude_peers, - find_by, - pass_through_args, - }; - package_manager.run_why_command(&why_command_options, &self.cwd).await - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_why_command_new() { - let workspace_root = if cfg!(windows) { - AbsolutePathBuf::new("C:\\test".into()).unwrap() - } else { - AbsolutePathBuf::new("/test".into()).unwrap() - }; - - let cmd = WhyCommand::new(workspace_root.clone()); - assert_eq!(cmd.cwd, workspace_root); - } -} diff --git a/packages/cli/snap-tests/command-helper/snap.txt b/packages/cli/snap-tests/command-helper/snap.txt index 9b70f98c86..6113b10259 100644 --- a/packages/cli/snap-tests/command-helper/snap.txt +++ b/packages/cli/snap-tests/command-helper/snap.txt @@ -1,3 +1,29 @@ +> vite -h # help message +Usage: vite [OPTIONS] [TASK] [-- ...] + +Commands: + run Run tasks + lint Lint code + fmt Format code + build Build application + test Run test + lib Build library + dev Run development server + doc Build documentation + cache Manage the task cache + install Install command. It will be passed to the package manager's install command currently + help Print this message or the help of the given subcommand(s) + +Arguments: + [TASK] + [TASK_ARGS]... Optional arguments for the tasks, captured after '--' + +Options: + -d, --debug Display cache for debugging + --no-debug + -h, --help Print help + -V, --version Print version + > vite lib -h # lib help message tsdown/ diff --git a/packages/cli/snap-tests/command-helper/steps.json b/packages/cli/snap-tests/command-helper/steps.json index 35372922f9..706f525726 100644 --- a/packages/cli/snap-tests/command-helper/steps.json +++ b/packages/cli/snap-tests/command-helper/steps.json @@ -4,6 +4,7 @@ "VITE_DISABLE_AUTO_INSTALL": "1" }, "commands": [ + "vite -h # help message", "vite lib -h # lib help message", "vite fmt -h # fmt help message", "vite lint -h # lint help message",