Commit e687c62
authored
feat(pm): vite add command for package installation (#221)
### 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.
<!-- CURSOR_SUMMARY -->
---
> [!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.
> <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit b868089. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->1 parent 4aeb13e commit e687c62
64 files changed
Lines changed: 4898 additions & 30 deletions
File tree
- crates
- vite_error/src
- vite_package_manager
- src
- packages
- cli
- binding/src
- commands
- snap-tests/exit-non-zero-on-cmd-not-exists
- global/snap-tests
- cli-helper-message
- command-add-npm10-with-workspace
- packages
- app
- utils
- command-add-npm10
- command-add-npm11-with-workspace
- packages
- app
- utils
- command-add-npm11
- command-add-pnpm10-with-workspace
- packages
- app
- utils
- command-add-pnpm10
- command-add-pnpm9-with-workspace
- packages
- app
- utils
- command-add-pnpm9
- command-add-yarn4-with-workspace
- packages
- admin
- app
- utils
- command-add-yarn4
- tools
- src
- __tests__
- __snapshots__
- rfcs
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
133 | 133 | | |
134 | 134 | | |
135 | 135 | | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
0 commit comments