Skip to content

feat(pm): vite add command for package installation#221

Merged
fengmk2 merged 1 commit intomainfrom
10-11-feat_pm_support_add_package
Oct 23, 2025
Merged

feat(pm): vite add command for package installation#221
fengmk2 merged 1 commit intomainfrom
10-11-feat_pm_support_add_package

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Oct 11, 2025

TL;DR

Added a new vite add command to simplify adding packages to dependencies with automatic package manager detection.

What changed?

  • Added a new AddCommand implementation in vite_task/src/add.rs that handles adding packages to dependencies
  • Implemented build_add_args method in PackageManager to generate the correct command arguments for different package managers (npm, yarn, pnpm)
  • Added support for workspace filtering, workspace root, and workspace-only flags
  • Added new error types for package manager detection and package specification
  • Added comprehensive tests for the new functionality

How to test?

Test the new command with different package managers:

# Basic usage
vite add react react-dom

# Add dev dependencies
vite add typescript -D

# Add to specific workspace packages
vite add lodash --filter app

# Add to workspace root
vite add eslint -w

# Add to multiple workspaces
vite add jest --filter app --filter web

Why make this change?

This change simplifies the process of adding dependencies to projects by automatically detecting the package manager and translating the command to the appropriate syntax. It eliminates the need for users to remember different command formats for npm, yarn, and pnpm, especially in monorepo setups where workspace flags differ significantly between package managers.


Note

Introduces a unified vite add command that detects pnpm/yarn/npm, builds correct args (filters, workspace/root/global, save flags), aliases install <pkgs> to add, and adds error handling with extensive tests/snapshots.

  • CLI (vite task):
    • Add Add subcommand in crates/vite_task/src/lib.rs with flags (-D/-P/-O/--save-peer, -E, --filter, -w, --workspace, -g, pass-through --).
    • Implement execution in crates/vite_task/src/add.rs; prints resolved command and runs via task graph.
    • Treat install <PACKAGES> as alias to add via parse_install_as_add.
  • Package Manager Adapter:
    • New crates/vite_package_manager/src/add.rs with AddCommandOptions and SaveDependencyType and PackageManager::resolve_add_command that maps to pnpm/yarn/npm args (filters ordering, workspace/root, save flags, exact, catalogs, --allow-build, global via npm).
    • Export in crates/vite_package_manager/src/lib.rs.
  • Errors:
    • Add Error::NoPackagesSpecified in crates/vite_error/src/lib.rs.
  • Tests/Fixtures:
    • Comprehensive unit tests for arg resolution and command building across pnpm (v9/10), yarn (v4), npm (v10/11), including workspaces, catalogs, pass-through, and global.
    • Update CLI help/snapshots to include add and new outputs.
    • packages/tools: normalize CI output; strip Yarn YN0013 in replaceUnstableOutput with new test.
      Written by Cursor Bugbot for commit b868089. This will update automatically on new commits. Configure here.

Copy link
Copy Markdown
Member Author

fengmk2 commented Oct 11, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@fengmk2 fengmk2 changed the title feat(pm): support add package feat(pm): add vite add command for package installation Oct 11, 2025
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch 2 times, most recently from 300547f to 2695939 Compare October 13, 2025 04:55
@fengmk2 fengmk2 changed the title feat(pm): add vite add command for package installation feat(pm): vite add command for package installation Oct 13, 2025
Comment thread packages/global/snap-tests/command-add-pnpm/snap.txt Outdated
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 2695939 to 5ffc1b5 Compare October 13, 2025 08:15
@fengmk2 fengmk2 changed the base branch from add-package-rfc to graphite-base/221 October 16, 2025 08:26
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 5ffc1b5 to 921c4e8 Compare October 16, 2025 08:26
@fengmk2 fengmk2 changed the base branch from graphite-base/221 to 10-15-refactor_pm_rename_resolve_commmand_to_resolve_install_command October 16, 2025 08:26
@fengmk2 fengmk2 changed the title feat(pm): vite add command for package installation feat(pm): vite add command for package installation Oct 17, 2025
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch 7 times, most recently from a40e9f4 to f33a8b1 Compare October 17, 2025 05:39
@fengmk2 fengmk2 force-pushed the 10-15-refactor_pm_rename_resolve_commmand_to_resolve_install_command branch from 88f7e5b to 91c00c5 Compare October 17, 2025 07:17
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch 2 times, most recently from 579a820 to 61e86bf Compare October 17, 2025 07:40
@fengmk2 fengmk2 force-pushed the 10-15-refactor_pm_rename_resolve_commmand_to_resolve_install_command branch from 91c00c5 to 39b091e Compare October 17, 2025 07:45
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch 4 times, most recently from 54197ef to adba73b Compare October 20, 2025 03:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 57 out of 57 changed files in this pull request and generated 3 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread crates/vite_package_manager/src/package_manager.rs Outdated
Comment thread crates/vite_task/src/lib.rs Outdated
Comment thread crates/vite_task/src/lib.rs Outdated
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 777bd7c to 20d51ba Compare October 23, 2025 03:05
Comment thread packages/global/snap-tests/command-add-pnpm10/snap.txt Outdated
Comment thread packages/cli/binding/src/cli.rs Outdated
Copilot AI review requested due to automatic review settings October 23, 2025 05:02
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 20d51ba to 23ad827 Compare October 23, 2025 05:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 59 out of 60 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (2)

crates/vite_package_manager/src/add.rs:1

  • The args parameter should be &[String] instead of &Vec<String>. Using a slice is more idiomatic and flexible in Rust.
use std::{collections::HashMap, process::ExitStatus};

packages/cli/binding/src/cli.rs:1

  • This debug statement appears to be leftover from development. Consider removing it or clarifying if it's intentionally added for debugging purposes.
//! CLI types and logic moved from vite_task

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/tools/src/utils.ts
Comment thread packages/cli/binding/src/cli.rs
Comment thread packages/cli/binding/src/cli.rs Outdated
Comment thread packages/cli/binding/src/cli.rs Outdated
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 23ad827 to 320d654 Compare October 23, 2025 07:32
Copilot AI review requested due to automatic review settings October 23, 2025 08:01
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 320d654 to c6a3c8c Compare October 23, 2025 08:01
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 62 out of 64 changed files in this pull request and generated 4 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported
Comments suppressed due to low confidence (2)

packages/tools/src/utils.ts:1

  • Corrected spelling of 'passth rough' to 'passthrough'.
import { Minimatch } from 'minimatch';

packages/tools/src/utils.ts:1

  • Corrected spelling of 'passth rough' to 'passthrough'.
import { Minimatch } from 'minimatch';

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/cli/binding/src/cli.rs Outdated
Comment thread packages/cli/binding/src/cli.rs
Comment thread crates/vite_package_manager/src/package_manager.rs
Comment thread crates/vite_package_manager/src/add.rs
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from c6a3c8c to 25352cf Compare October 23, 2025 08:16
Comment thread crates/vite_package_manager/src/package_manager.rs Outdated
Copilot AI review requested due to automatic review settings October 23, 2025 08:24
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 25352cf to 805bfae Compare October 23, 2025 08:24
Comment thread crates/vite_package_manager/src/package_manager.rs Outdated
Comment thread crates/vite_package_manager/src/package_manager.rs Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 62 out of 64 changed files in this pull request and generated 6 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/tools/src/__tests__/utils.spec.ts Outdated
Comment thread packages/tools/src/__tests__/utils.spec.ts Outdated
Comment thread crates/vite_package_manager/src/package_manager.rs
Comment thread crates/vite_package_manager/src/package_manager.rs Outdated
Comment thread packages/cli/binding/src/cli.rs
Comment thread packages/tools/src/utils.ts Outdated
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 805bfae to 5004b6b Compare October 23, 2025 08:38
Copilot AI review requested due to automatic review settings October 23, 2025 08:41
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 5004b6b to 6086205 Compare October 23, 2025 08:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 62 out of 64 changed files in this pull request and generated 5 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread packages/tools/src/utils.ts Outdated
Comment thread packages/tools/src/__tests__/utils.spec.ts Outdated
Comment thread packages/tools/src/__tests__/utils.spec.ts Outdated
Comment thread crates/vite_package_manager/src/package_manager.rs
Comment thread crates/vite_package_manager/src/package_manager.rs
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from 6086205 to cce1331 Compare October 23, 2025 11:11
Copilot AI review requested due to automatic review settings October 23, 2025 11:17
@fengmk2 fengmk2 force-pushed the 10-11-feat_pm_support_add_package branch from cce1331 to 1f4e6a9 Compare October 23, 2025 11:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 62 out of 64 changed files in this pull request and generated 2 comments.

Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread crates/vite_package_manager/src/package_manager.rs
Comment thread crates/vite_package_manager/src/add.rs
@fengmk2 fengmk2 merged commit e687c62 into main Oct 23, 2025
10 checks passed
Copy link
Copy Markdown
Member Author

fengmk2 commented Oct 23, 2025

Merge activity

@fengmk2 fengmk2 deleted the 10-11-feat_pm_support_add_package branch October 23, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants