Skip to content

feat(install): add bun as a package manager#1005

Draft
fengmk2 wants to merge 16 commits intomainfrom
bun-pm
Draft

feat(install): add bun as a package manager#1005
fengmk2 wants to merge 16 commits intomainfrom
bun-pm

Conversation

@fengmk2
Copy link
Member

@fengmk2 fengmk2 commented Mar 18, 2026

Summary

Add bun as the 4th supported package manager alongside pnpm, npm, and yarn. Bun is added only as a package manager and runtime support is not planned.

Closes #557

Changes

Rust Core

  • Add Bun variant to PackageManagerType enum
  • Detect bun via packageManager field, bun.lock, bun.lockb, bunfig.toml
  • Download platform-specific native binary from @oven/bun-{os}-{arch} npm packages (including musl variants)
  • Add native binary shim support (non-Node.js wrappers for sh/cmd/ps1)
  • Add PackageManagerType::Bun arms to all 30 command files with correct flag mappings
  • Add bun to interactive package manager selection menu

Command Mappings

  • bun install with --frozen-lockfile, --production, --ignore-scripts, --lockfile-only, --omit optional, --filter
  • bun add with --dev, --peer, --optional, --exact, --global
  • bun remove, bun update (with --latest, --interactive, --recursive, --production)
  • bun outdated (with --filter, --recursive, --production, --omit optional)
  • bun why (with --depth), bun x (with --package), bun audit (with --audit-level)
  • bun pm pack (with --filename, --gzip-level), bun pm ls, bun pm cache, bun pm whoami
  • bun info for package view, bun publish for publishing
  • Unsupported commands (deprecate, fund, owner, ping, search, token) fall back to npm silently

Global CLI & NAPI

  • Add "bun" to PACKAGE_MANAGER_TOOLS in shim dispatch
  • Add "bun" => PackageManagerType::Bun in NAPI binding

TypeScript

  • Add bun to PackageManager type and selection prompt
  • Add --package-manager flag to vp create for easier testing
  • Handle bun in monorepo templates (uses package.json workspaces, not pnpm-workspace.yaml)
  • Bun catalog support: write catalog entries to root package.json with catalog: references in both dependencies and overrides
  • Migration: bun uses overrides with catalog: references (not raw versions)
  • Use bun x instead of bunx for DLX commands (better cross-platform compatibility)

Snap Tests & Output Sanitizer

  • 10 bun command snap tests (add, remove, update, outdated, why, dlx, list, publish, view, cache)
  • 1 bun monorepo creation snap test (new-vite-monorepo-bun) verifying catalog support
  • Filter unstable bun output: Resolving dependencies, Resolved, downloaded and extracted, Resolving..., Saved lockfile, (vX.Y.Z available)

RFCs

  • Update all 11 package-manager RFCs with bun command mapping tables

Ecosystem CI

  • Add bun-vite-template (React + Mantine) test case

Test plan

  • cargo test -p vite_install — 455 tests pass (18 new bun tests)
  • cargo test -p vite_global_cli — 311 tests pass
  • pnpm -F vite-plus snap-test-global bun — all 10 bun snap tests pass
  • pnpm -F vite-plus snap-test-global new-vite-monorepo-bun — catalog test passes
  • pnpm -F vite-plus snap-test-global new-vite-monorepo — existing pnpm test unaffected
  • Ecosystem CI clone verified locally for bun-vite-template
  • Windows native cmd shim tested (no command echo)
  • musl Linux binary detection tested

🤖 Generated with Claude Code

Copy link
Member Author

fengmk2 commented Mar 18, 2026


How to use the Graphite Merge Queue

Add the label auto-merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

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

@fengmk2 fengmk2 mentioned this pull request Mar 18, 2026
5 tasks
@fengmk2 fengmk2 self-assigned this Mar 18, 2026
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from 45e4691 to bc38b7a Compare March 18, 2026 01:50
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch 2 times, most recently from 810d51c to efc5c42 Compare March 18, 2026 02:28
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from efc5c42 to d143fc6 Compare March 18, 2026 03:51
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from d143fc6 to 9db93c2 Compare March 18, 2026 04:01
@fengmk2 fengmk2 force-pushed the bun-pm branch 2 times, most recently from 183be48 to f551a2a Compare March 18, 2026 06:05
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from 9db93c2 to cc73dcc Compare March 18, 2026 06:05
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch 2 times, most recently from 000f043 to 00ae674 Compare March 18, 2026 06:15
@fengmk2 fengmk2 force-pushed the bun-pm branch 2 times, most recently from a38d005 to c16f4d5 Compare March 18, 2026 06:49
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from 00ae674 to 5fb8073 Compare March 18, 2026 06:49
@fengmk2 fengmk2 force-pushed the bun-pm branch 2 times, most recently from ffb13dd to 3659cb9 Compare March 18, 2026 07:18
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch 2 times, most recently from cfccc29 to d64cba8 Compare March 18, 2026 07:42
@fengmk2 fengmk2 force-pushed the bun-pm branch 3 times, most recently from f5c94ee to 2430298 Compare March 18, 2026 11:38
@fengmk2 fengmk2 force-pushed the trampoline-exe-for-shims branch from df57cf4 to 5534094 Compare March 18, 2026 11:38
fengmk2 added 3 commits March 25, 2026 20:26
The bun platform package (`@oven/bun-{os}-{arch}`) places the native
binary at `package/bin/bun`, not `package/bun`. Fixed the path in
`download_bun_package_manager` to look in the correct location.

Updated all 10 bun snap test outputs with working bun command results.
Bun outputs "Resolving dependencies" and "Resolved, downloaded and
extracted [N]" intermittently depending on cache state. Filter these
lines in the snap test output sanitizer for stable snapshots.
Fix 7 defects in bun package manager support:

P1 - Windows shims: use bun.native.exe on Windows instead of bun.native
P1 - Hash validation: skip hash check for platform-specific package
     (hash from packageManager field belongs to main bun package)
P1 - Audit command: use `bun audit` with `--audit-level` instead of
     `bun pm audit` with `--level`
P1 - Install flags: forward --ignore-scripts and --omit optional to bun
     instead of warning them away
P2 - Update flags: forward --production, --omit optional, --no-save,
     and --recursive to bun update
P2 - Pack flags: map --out to bun's --filename, forward --gzip-level
P3 - Why flags: forward --depth to bun why

Update corresponding RFC documents to reflect correct bun mappings.
Add 18 new unit tests covering all fixes.
fengmk2 added 2 commits March 25, 2026 20:42
- Remove unused `expected_hash` parameter from `download_bun_package_manager`
  (hash belongs to main bun package, not platform binary; documented at call site)
- Remove misleading shamefully-hoist comment in install.rs
- Filter additional unstable bun output: "Resolving..." prefix and
  "(vX.Y.Z available)" hints that appear intermittently
On musl Linux (Alpine), the glibc bun binary from `@oven/bun-linux-x64`
cannot execute. Use `@oven/bun-linux-x64-musl` and
`@oven/bun-linux-aarch64-musl` on musl targets via `cfg(target_env)`,
matching the pattern used by the Node.js provider.

This fixes bun snap test failures on Linux x64 musl CI.
Bun intermittently prints "Saved lockfile" depending on cache state.
Filter this line in the snap test output sanitizer for stable snapshots.
- view.rs: use native `bun info` instead of npm fallback
- dlx.rs: forward `--package` flag to `bun x` (before package spec)
- install.rs: forward `--lockfile-only` to bun
- outdated.rs: forward `--production` and `--omit optional` to bun
- login/logout/owner/ping/search/token: remove unnecessary warning
  logs when falling back to npm (the fallback itself is correct)
Copy link
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

Adds Bun as a 4th supported package manager across Vite+ (Rust core, NAPI/binding, TypeScript CLI), updating command mappings/RFCs and adding snapshot coverage to validate behavior.

Changes:

  • Introduces PackageManagerType::Bun with detection (packageManager field + bun lock/config files) and Bun binary download/shim support.
  • Adds Bun support across CLI commands (install/add/remove/update/outdated/pm subcommands/etc.) plus TypeScript prompts/migration/template handling.
  • Updates RFC documentation and adds global snap-tests for Bun flows.

Reviewed changes

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

Show a summary per file
File Description
rfcs/why-package-command.md Documents vp why mappings and Bun behavior/limitations.
rfcs/update-package-command.md Documents vp update mappings including Bun flags.
rfcs/pm-command-group.md Documents vp pm subcommands and Bun delegation rules.
rfcs/pack-command.md Clarifies vp pm pack behavior for Bun (bun pm pack).
rfcs/outdated-package-command.md Documents vp outdated mappings including Bun support/limits.
rfcs/link-unlink-package-commands.md Documents vp link/unlink mappings including Bun.
rfcs/install-command.md Documents vp install mappings including Bun flags.
rfcs/exec-command.md Updates vp exec RFC to reference Bun equivalences.
rfcs/dlx-command.md Updates vp dlx RFC to include Bun (bun x) mapping.
rfcs/dedupe-package-command.md Notes Bun lacks dedupe; documents fallback expectations.
rfcs/add-remove-package-commands.md Documents add/remove mappings including Bun and limitations.
packages/tools/src/utils.ts Stabilizes bun CLI output in snapshot normalization.
packages/cli/src/utils/prompts.ts Adds Bun to interactive package manager selection.
packages/cli/src/types/package.ts Extends PackageManager type with bun.
packages/cli/src/migration/migrator.ts Treats Bun like npm for overrides; excludes Bun from catalog usage.
packages/cli/src/migration/bin.ts Forces reinstall with --force for npm and bun.
packages/cli/src/create/templates/monorepo.ts Treats Bun like npm workspace layout (workspaces field).
packages/cli/src/create/command.ts Uses bun x as runner; fixes npx -- passthrough condition.
packages/cli/snap-tests-global/command-why-bun/steps.json Adds Bun snap-test steps for vp why.
packages/cli/snap-tests-global/command-why-bun/snap.txt Expected output snapshot for Bun vp why.
packages/cli/snap-tests-global/command-why-bun/package.json Bun-based fixture project for vp why.
packages/cli/snap-tests-global/command-view-bun/steps.json Adds Bun snap-test steps for vp pm view.
packages/cli/snap-tests-global/command-view-bun/snap.txt Expected output snapshot for Bun vp pm view.
packages/cli/snap-tests-global/command-view-bun/package.json Bun-based fixture project for vp pm view.
packages/cli/snap-tests-global/command-update-bun/steps.json Adds Bun snap-test steps for vp update.
packages/cli/snap-tests-global/command-update-bun/snap.txt Expected output snapshot for Bun vp update.
packages/cli/snap-tests-global/command-update-bun/package.json Bun-based fixture project for vp update.
packages/cli/snap-tests-global/command-remove-bun/steps.json Adds Bun snap-test steps for vp remove.
packages/cli/snap-tests-global/command-remove-bun/snap.txt Expected output snapshot for Bun vp remove.
packages/cli/snap-tests-global/command-remove-bun/package.json Bun-based fixture project for vp remove.
packages/cli/snap-tests-global/command-publish-bun/steps.json Adds Bun snap-test steps for vp pm publish.
packages/cli/snap-tests-global/command-publish-bun/snap.txt Expected output snapshot for Bun vp pm publish.
packages/cli/snap-tests-global/command-publish-bun/package.json Bun-based fixture project for vp pm publish.
packages/cli/snap-tests-global/command-outdated-bun/steps.json Adds Bun snap-test steps for vp outdated.
packages/cli/snap-tests-global/command-outdated-bun/snap.txt Expected output snapshot for Bun vp outdated.
packages/cli/snap-tests-global/command-outdated-bun/package.json Bun-based fixture project for vp outdated.
packages/cli/snap-tests-global/command-list-bun/steps.json Adds Bun snap-test steps for vp pm list.
packages/cli/snap-tests-global/command-list-bun/snap.txt Expected output snapshot for Bun vp pm list.
packages/cli/snap-tests-global/command-list-bun/package.json Bun-based fixture project for vp pm list.
packages/cli/snap-tests-global/command-dlx-bun/steps.json Adds Bun snap-test steps for vp dlx.
packages/cli/snap-tests-global/command-dlx-bun/snap.txt Expected output snapshot for Bun vp dlx.
packages/cli/snap-tests-global/command-dlx-bun/package.json Bun-based fixture project for vp dlx.
packages/cli/snap-tests-global/command-cache-bun/steps.json Adds Bun snap-test steps for vp pm cache.
packages/cli/snap-tests-global/command-cache-bun/snap.txt Expected output snapshot for Bun vp pm cache.
packages/cli/snap-tests-global/command-cache-bun/package.json Bun-based fixture project for vp pm cache.
packages/cli/snap-tests-global/command-add-bun/steps.json Adds Bun snap-test steps for vp add.
packages/cli/snap-tests-global/command-add-bun/snap.txt Expected output snapshot for Bun vp add.
packages/cli/snap-tests-global/command-add-bun/package.json Bun-based fixture project for vp add.
packages/cli/binding/src/package_manager.rs Maps "bun" to PackageManagerType::Bun in NAPI binding.
crates/vite_install/src/shim.rs Adds native binary shim generation for bun (and similar).
crates/vite_install/src/package_manager.rs Adds Bun detection, platform package selection, and bun binary download flow.
crates/vite_install/src/commands/why.rs Adds Bun why resolution with supported/unsupported flags behavior.
crates/vite_install/src/commands/whoami.rs Adds Bun whoami mapping (bun pm whoami).
crates/vite_install/src/commands/view.rs Uses bun info when PM is Bun; otherwise npm view.
crates/vite_install/src/commands/update.rs Adds Bun update argument mapping.
crates/vite_install/src/commands/unlink.rs Adds Bun unlink mapping with recursive warning.
crates/vite_install/src/commands/token.rs Documents Bun fallback behavior (comment).
crates/vite_install/src/commands/search.rs Documents Bun fallback behavior (comment).
crates/vite_install/src/commands/run.rs Allows run to use bun binary for Bun PM.
crates/vite_install/src/commands/remove.rs Adds Bun remove mapping and unsupported flag warnings.
crates/vite_install/src/commands/rebuild.rs Disables rebuild for Bun with warning.
crates/vite_install/src/commands/publish.rs Adds Bun publish mapping + unsupported flag warnings.
crates/vite_install/src/commands/prune.rs Disables prune for Bun with warning.
crates/vite_install/src/commands/ping.rs Documents Bun fallback behavior (comment).
crates/vite_install/src/commands/pack.rs Adds Bun pack mapping to bun pm pack with option translations.
crates/vite_install/src/commands/owner.rs Documents Bun fallback behavior (comment).
crates/vite_install/src/commands/outdated.rs Adds Bun outdated mapping + unsupported option warnings.
crates/vite_install/src/commands/logout.rs Uses npm logout when PM is Bun.
crates/vite_install/src/commands/login.rs Uses npm login when PM is Bun.
crates/vite_install/src/commands/list.rs Adds Bun list mapping to bun pm ls with warnings for unsupported flags.
crates/vite_install/src/commands/link.rs Adds Bun link mapping (bun link).
crates/vite_install/src/commands/install.rs Adds Bun install argument mapping + standardizes warnings via output::warn.
crates/vite_install/src/commands/fund.rs Warns and falls back to npm fund for Bun.
crates/vite_install/src/commands/dlx.rs Adds Bun dlx runner (bun x).
crates/vite_install/src/commands/dist_tag.rs Warns and falls back to npm dist-tag for Bun.
crates/vite_install/src/commands/deprecate.rs Warns and falls back to npm deprecate for Bun.
crates/vite_install/src/commands/dedupe.rs Warns and falls back to bun install for Bun dedupe.
crates/vite_install/src/commands/config.rs Warns and falls back to npm config for Bun.
crates/vite_install/src/commands/cache.rs Adds Bun cache mapping via bun pm cache / rm.
crates/vite_install/src/commands/audit.rs Adds Bun audit mapping + behavior for unsupported flags.
crates/vite_install/src/commands/add.rs Adds Bun add mapping + unsupported flag warnings.
crates/vite_global_cli/src/shim/dispatch.rs Includes bun in package-manager tool list for project-context resolution.

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

Comment on lines +15 to +17
let to_bin = to_bin.as_ref();
let relative_path = diff_paths(source_file, to_bin.parent().unwrap()).unwrap();
let relative_file = relative_path.to_str().unwrap();
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

write_native_shims uses multiple unwrap() calls (to_bin.parent(), diff_paths(...), to_str()). These can panic on edge cases (e.g., to_bin without parent, paths on different volumes, non-UTF8 paths) and would crash the install/shim flow. Please convert these to fallible handling and return a vite_error::Error with context instead of panicking.

Copilot uses AI. Check for mistakes.
Comment on lines +538 to +541
// Download the platform-specific package directly
let platform_tgz_url = get_npm_package_tgz_url(platform_package_name, version);
let target_dir_tmp = tempfile::tempdir_in(parent_dir)?.path().to_path_buf();

Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

tempfile::tempdir_in(parent_dir)?.path().to_path_buf() drops the TempDir immediately, so you lose RAII cleanup on early returns/errors and the “robust temporary directory creation” guarantee in the comment. Consider keeping the TempDir handle alive for the whole download/extract/rename flow (or using into_path() and explicitly cleaning up on failure).

Copilot uses AI. Check for mistakes.
fengmk2 added 4 commits March 25, 2026 22:55
- dlx: bun supports --package flag (before package spec)
- install: bun supports --lockfile-only
- outdated: bun supports --production and --omit optional
- pm-command-group: view uses native `bun info` instead of npm fallback
Add `--package-manager` option to `vp create` for specifying the package
manager without interactive prompts. Priority: workspace detection >
CLI flag > interactive prompt/default.

Fix bun catalog support in monorepo migration:
- Enable `catalog:` protocol for bun (was incorrectly excluded)
- Add `rewriteBunCatalog()` to write catalog entries to root package.json
  (bun stores catalogs in package.json, not pnpm-workspace.yaml)
- Bun overrides use raw versions (catalog: not supported in overrides)

Add `new-vite-monorepo-bun` snap test verifying:
- Root package.json has catalog, workspaces, and overrides fields
- Sub-packages use `catalog:` references for dependencies
- No pnpm-workspace.yaml or .yarnrc.yml files created
Bun's overrides field supports catalog: references. Use them instead
of raw version strings so all version management is centralized in
the catalog definition.
Add bun-based React + Mantine project (why-reproductions-are-required/
bun-vite-template) to ecosystem-ci to verify bun package manager
support works end-to-end with `vp migrate` and `vp run build`.
Add `@` prefix to the execution line in `native_cmd_shim` to prevent
cmd.exe from echoing the full command path before running it. Without
this, bun commands on Windows print the raw shim path in output.
@fengmk2 fengmk2 changed the title feat(install): add bun as a package manager (#557) feat(install): add bun as a package manager Mar 25, 2026
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.

feat: support bun (vite install)

3 participants