Skip to content

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

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

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

Conversation

@fengmk2

@fengmk2fengmk2 commented Oct 11, 2025

Copy link
Copy Markdown
Member

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.

@fengmk2Graphite App

fengmk2 commented Oct 11, 2025

Copy link
Copy Markdown
MemberAuthor

@fengmk2fengmk2 changed the title feat(pm): support add packagefeat(pm): add vite add command for package installationOct 11, 2025
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch 2 times, most recently from 300547f to 2695939CompareOctober 13, 2025 04:55
@fengmk2fengmk2 changed the title feat(pm): add vite add command for package installationfeat(pm): vite add command for package installationOct 13, 2025
Comment threadpackages/global/snap-tests/command-add-pnpm/snap.txt Outdated
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 2695939 to 5ffc1b5CompareOctober 13, 2025 08:15
@fengmk2
fengmk2 changed the base branch from add-package-rfc to graphite-base/221October 16, 2025 08:26
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 5ffc1b5 to 921c4e8CompareOctober 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_commandOctober 16, 2025 08:26
@fengmk2fengmk2 changed the title feat(pm): vite add command for package installationfeat(pm): vite add command for package installationOct 17, 2025
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch 7 times, most recently from a40e9f4 to f33a8b1CompareOctober 17, 2025 05:39
@fengmk2
fengmk2force-pushed the 10-15-refactor_pm_rename_resolve_commmand_to_resolve_install_command branch from 88f7e5b to 91c00c5CompareOctober 17, 2025 07:17
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch 2 times, most recently from 579a820 to 61e86bfCompareOctober 17, 2025 07:40
@fengmk2
fengmk2force-pushed the 10-15-refactor_pm_rename_resolve_commmand_to_resolve_install_command branch from 91c00c5 to 39b091eCompareOctober 17, 2025 07:45
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch 4 times, most recently from 54197ef to adba73bCompareOctober 20, 2025 03:27

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 threadcrates/vite_package_manager/src/package_manager.rs Outdated
Comment threadcrates/vite_task/src/lib.rs Outdated
Comment threadcrates/vite_task/src/lib.rs Outdated
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 777bd7c to 20d51baCompareOctober 23, 2025 03:05
Comment threadpackages/global/snap-tests/command-add-pnpm10/snap.txt Outdated
Comment threadpackages/cli/binding/src/cli.rs Outdated
CopilotAI review requested due to automatic review settings October 23, 2025 05:02
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 20d51ba to 23ad827CompareOctober 23, 2025 05:02

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 threadpackages/tools/src/utils.ts
Comment threadpackages/cli/binding/src/cli.rs
Comment threadpackages/cli/binding/src/cli.rs Outdated
Comment threadpackages/cli/binding/src/cli.rs Outdated
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 23ad827 to 320d654CompareOctober 23, 2025 07:32
CopilotAI review requested due to automatic review settings October 23, 2025 08:01
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 320d654 to c6a3c8cCompareOctober 23, 2025 08:01

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 threadpackages/cli/binding/src/cli.rs Outdated
Comment threadpackages/cli/binding/src/cli.rs
Comment threadcrates/vite_package_manager/src/package_manager.rs
Comment threadcrates/vite_package_manager/src/add.rs
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from c6a3c8c to 25352cfCompareOctober 23, 2025 08:16
Comment threadcrates/vite_package_manager/src/package_manager.rs Outdated
CopilotAI review requested due to automatic review settings October 23, 2025 08:24
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 25352cf to 805bfaeCompareOctober 23, 2025 08:24
Comment threadcrates/vite_package_manager/src/package_manager.rs Outdated
Comment threadcrates/vite_package_manager/src/package_manager.rs Outdated

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 threadpackages/tools/src/__tests__/utils.spec.ts Outdated
Comment threadpackages/tools/src/__tests__/utils.spec.ts Outdated
Comment threadcrates/vite_package_manager/src/package_manager.rs
Comment threadcrates/vite_package_manager/src/package_manager.rs Outdated
Comment threadpackages/cli/binding/src/cli.rs
Comment threadpackages/tools/src/utils.ts Outdated
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 805bfae to 5004b6bCompareOctober 23, 2025 08:38
CopilotAI review requested due to automatic review settings October 23, 2025 08:41
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 5004b6b to 6086205CompareOctober 23, 2025 08:41

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 threadpackages/tools/src/utils.ts Outdated
Comment threadpackages/tools/src/__tests__/utils.spec.ts Outdated
Comment threadpackages/tools/src/__tests__/utils.spec.ts Outdated
Comment threadcrates/vite_package_manager/src/package_manager.rs
Comment threadcrates/vite_package_manager/src/package_manager.rs
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from 6086205 to cce1331CompareOctober 23, 2025 11:11
CopilotAI review requested due to automatic review settings October 23, 2025 11:17
@fengmk2
fengmk2force-pushed the 10-11-feat_pm_support_add_package branch from cce1331 to 1f4e6a9CompareOctober 23, 2025 11:17

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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 threadcrates/vite_package_manager/src/package_manager.rs
Comment threadcrates/vite_package_manager/src/add.rs
@fengmk2
fengmk2 merged commit e687c62 into mainOct 23, 2025
10 checks passed
@fengmk2Graphite App

Copy link
Copy Markdown
MemberAuthor

Merge activity

@fengmk2
fengmk2 deleted the 10-11-feat_pm_support_add_package branch October 23, 2025 11:25
Sign up for freeto 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

@fengmk2@Brooooooklyn@wan9chi