Skip to content

feat: expose package manager detection and download APIs#308

Merged
fengmk2 merged 2 commits intomainfrom
11-15-feat_export_download_package_manager_helper
Nov 21, 2025
Merged

feat: expose package manager detection and download APIs#308
fengmk2 merged 2 commits intomainfrom
11-15-feat_export_download_package_manager_helper

Conversation

@fengmk2
Copy link
Copy Markdown
Member

@fengmk2 fengmk2 commented Nov 15, 2025

TL;DR

Expose package manager detection and download functionality through the CLI binding API.

What changed?

  • Added two new public functions to the CLI binding API:
    • detectWorkspace: Detects the workspace root, package manager type, version, and whether it's a monorepo
    • downloadPackageManager: Downloads a specified package manager version
  • Refactored the package manager download logic in vite_install to make it more modular and reusable
  • Added TypeScript type definitions and JSDoc documentation for the new functions
  • Created tests for the new functionality with fixtures for different project types

How to test?

  1. Run the new tests:

    pnpm test packages/cli/src/__tests__/detectWorkspace.spec.ts
    pnpm test packages/cli/src/__tests__/downloadPackageManager.spec.ts
    
  2. Try using the new API in a project:

    import { detectWorkspace, downloadPackageManager } from '@vitejs/cli';
    
    // Detect workspace and package manager
    const workspace = await detectWorkspace(process.cwd());
    console.log(workspace);
    
    // Download a package manager
    const result = await downloadPackageManager({
      name: 'pnpm',
      version: 'latest'
    });
    console.log(result);

Why make this change?

This change enables external tools and plugins to leverage Vite's package manager detection and download capabilities. By exposing these functions through the CLI binding API, other tools can reliably determine the project structure and ensure the correct package manager is available without reimplementing this logic.

Copy link
Copy Markdown
Member Author

fengmk2 commented Nov 15, 2025

@fengmk2 fengmk2 changed the base branch from 11-11-feat_run_command_with_fspy to graphite-base/308 November 15, 2025 08:32
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from f9b8d8e to fead428 Compare November 15, 2025 08:39
@fengmk2 fengmk2 changed the base branch from graphite-base/308 to 11-11-feat_run_command_with_fspy November 15, 2025 08:39
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch 2 times, most recently from e9e6dac to 57029f1 Compare November 15, 2025 09:51
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch 2 times, most recently from 21916a3 to 1db7b58 Compare November 15, 2025 09:57
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from 57029f1 to ebce813 Compare November 15, 2025 09:57
@fengmk2 fengmk2 changed the title feat: export download package manager helper feat: expose package manager detection and download APIs Nov 18, 2025
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from ebce813 to 8bf1272 Compare November 19, 2025 06:27
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch from 1db7b58 to f3cb301 Compare November 19, 2025 06:27
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from 8bf1272 to d1a3ebb Compare November 19, 2025 06:53
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch 2 times, most recently from c315cb6 to f409ec7 Compare November 19, 2025 07:04
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from d1a3ebb to 8a3eb33 Compare November 19, 2025 07:04
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch from f409ec7 to dbd0974 Compare November 19, 2025 07:09
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch 2 times, most recently from b34995d to 74cd86e Compare November 19, 2025 08:21
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch 2 times, most recently from af40762 to bc1410d Compare November 19, 2025 08:24
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch 2 times, most recently from 5859dd3 to b0f8412 Compare November 19, 2025 09:00
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch from bc1410d to d258eb1 Compare November 19, 2025 09:00
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch 2 times, most recently from a41588e to d5a6269 Compare November 19, 2025 10:03
@fengmk2 fengmk2 force-pushed the 11-11-feat_run_command_with_fspy branch 2 times, most recently from 59f106d to 4fd6e56 Compare November 19, 2025 11:05
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from d5a6269 to 37853c1 Compare November 19, 2025 11:05
@fengmk2 fengmk2 marked this pull request as ready for review November 19, 2025 12:56
@fengmk2 fengmk2 self-assigned this Nov 20, 2025
@fengmk2 fengmk2 changed the base branch from 11-11-feat_run_command_with_fspy to graphite-base/308 November 20, 2025 07:07
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from 37853c1 to e94dab5 Compare November 20, 2025 07:07
@graphite-app graphite-app bot changed the base branch from graphite-base/308 to main November 20, 2025 07:08
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from e94dab5 to 1dfda67 Compare November 20, 2025 07:08
Copilot AI review requested due to automatic review settings November 21, 2025 03:40
@fengmk2 fengmk2 force-pushed the 11-15-feat_export_download_package_manager_helper branch from 1dfda67 to 810a8d5 Compare November 21, 2025 03:40
Copy link
Copy Markdown
Member Author

fengmk2 commented Nov 21, 2025

Merge activity

  • Nov 21, 3:41 AM UTC: Graphite rebased this pull request as part of a merge.
  • Nov 21, 5:08 AM UTC: @fengmk2 merged this pull request with Graphite.

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

This PR exposes package manager detection and download functionality through the CLI binding API, enabling external tools to leverage Vite's package manager capabilities without reimplementing the logic.

Key Changes:

  • Added detectWorkspace and downloadPackageManager functions to the public API
  • Refactored download_package_manager in the Rust crate to return package metadata (install_dir, package_name, version)
  • Created comprehensive test suites with fixtures for pnpm and npm monorepos

Reviewed Changes

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

Show a summary per file
File Description
packages/cli/binding/src/package_manager.rs New module implementing the NAPI bindings for workspace detection and package manager download
packages/cli/binding/src/lib.rs Exports the new public functions
packages/cli/binding/index.js Exports the new functions to JavaScript
packages/cli/binding/index.d.ts TypeScript type definitions for the new API
crates/vite_install/src/package_manager.rs Refactored download_package_manager to return tuple with metadata and made functions public
crates/vite_install/src/lib.rs Exports newly public functions
packages/cli/binding/tests/detect-workspace.spec.ts Test suite for workspace detection
packages/cli/binding/tests/download-package-manager.spec.ts Test suite for package manager download
packages/cli/binding/tests/fixtures/* Test fixtures for pnpm-monorepo, npm-monorepo, and npm-project
packages/cli/binding/Cargo.toml Added vite_workspace dependency
Cargo.lock Updated with new dependency

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@fengmk2 fengmk2 merged commit f0bc839 into main Nov 21, 2025
9 of 12 checks passed
@fengmk2 fengmk2 deleted the 11-15-feat_export_download_package_manager_helper branch November 21, 2025 05:08
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.

3 participants