Skip to content

Enhance Vite+ package manager management #2375

Description

@liangmiQwQ

In my opinion, there is room to improve the current package manager management system.

  1. At present, Vite+ places the pm under $VP_HOME/package_manager, whether it's local CLI or global CLI

    • For global CLI, it's fine.
    • But for local CLI, there is room to improve. Vite+ allows local CLI runs without installing global CLI, if there is no global CLI installed and users run vp install in package json scripts or tasks, ~/.vite-plus will still be generated, leaving hard-to-find cache files and influence future probable Vite+ global CLI installation.
    • There are some Vite+ features that need package manager available, but since it's not able to make sure pnpm binary exists, Vite+ has to find the exact package manager in VPHOME, make the behavior inconsistent and cause problems like Do not update package.json when running vpr #2374.
  2. To get pm's binaries, corepack was introduced in feat(env): add corepack to the default shims tool list #1808.

    • corepack only handles pnpm, yarn, npm. But Vite+ can handle more package managers like bun, which causes confuse
    • One goal of Vite+ is to help beginners learn/use JavaScript, they've already known Vite+ helps manage package manager, it will be quite confusing to introduce another one. Learning corepack this concept itself also brings pressure.
    • Since feat: respect packageManager in package manager shims #1654, Vite+ has already implemented a corepack-like version management logic, so corepack now mainly handles
    • corepack can't read Vite+'s downloaded package managers, means the same pm might be downloaded twice.

Proposed package-manager refactor plan

The refactor is split into three dependent but independently mergeable parts:

  1. Replace Corepack with Vite+-owned shims
    PR feat(env)!: replace Corepack with package manager shims #2391 removes the Corepack integration. vp env setup directly provides shims for npm, pnpm, Yarn, and Bun.

  2. Manage package managers through vp env
    Extend vp env from Node.js-only management to a complete JavaScript environment: Node.js plus a selected package manager. Commands such as pin, use, install, clean, and current can manage either component.

  3. Run package managers from PATH
    Ordinary commands detect the appropriate manager and execute the binary available on PATH. They no longer download a manager, modify PATH, or write package-manager metadata to package.json. A Vite+ shim may still be the binary on PATH, so managed versions remain supported.

The goal is to separate three responsibilities that are currently mixed together:

  • detecting which package manager a project uses;
  • provisioning managed versions through vp env and shims;
  • executing ordinary package-manager commands.

This addresses the unexpected package.json mutation reported in #2374, avoids project-local Vite+ installations creating hidden global state, and removes the overlap between Corepack and Vite+ package-manager management.

The change is technically breaking, but the common workflow should remain mostly unchanged. The main affected cases are Corepack-specific usage, scripts consuming vp env --json, and local-only installations without a package manager on PATH.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

Fields

Priority

None yet

Effort

None yet

Target date

None yet

Start date

None yet

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions