Skip to content

Add WithBun() support for Vite apps#13733

Merged
IEvangelist merged 3 commits intodotnet:mainfrom
emilienbev:AddWithBun
Jan 16, 2026
Merged

Add WithBun() support for Vite apps#13733
IEvangelist merged 3 commits intodotnet:mainfrom
emilienbev:AddWithBun

Conversation

@emilienbev
Copy link
Contributor

@emilienbev emilienbev commented Jan 3, 2026

Description

This PR adds native bun support for Vite/JavaScript resources via a new WithBun() extension method, enabling bun install and bun run <script> flows similar to existing WithNpm(), WithYarn(), and WithPnpm() support.

Changes

  • Added WithBun() for JavaScriptAppResource-based resources.
  • Uses bun executable and run script command (bun run <script> ...).
  • Does not inject the -- command separator (bun forwards script flags without it).
  • Copies package.json + bun lockfile(s) for Docker layer caching (bun.lock / bun.lockb when present).
  • Sets bun cache mount for Dockerfile generation (/root/.bun/install/cache).
  • Ensures publish-mode Dockerfile generation can execute bun by overriding the build base image to oven/bun:1 when not already specified (assuming using latest isn't recommended here? Unsure.)

Fixes #13686

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copilot AI review requested due to automatic review settings January 3, 2026 00:30
@github-actions
Copy link
Contributor

github-actions bot commented Jan 3, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13733

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13733"

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

This PR adds native Bun package manager support for JavaScript/Vite applications in Aspire, enabling developers to use bun install and bun run commands similar to existing npm, Yarn, and pnpm support.

Key Changes:

  • Introduces a new WithBun() extension method for JavaScript app resources that configures Bun as the package manager
  • Implements Bun-specific behavior: no command separator (--) when passing script flags, support for both bun.lock and bun.lockb files, and Docker base image override to oven/bun:1
  • Adds comprehensive test coverage for Bun installation arguments and command-line behavior

Reviewed changes

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

File Description
src/Aspire.Hosting.JavaScript/JavaScriptHostingExtensions.cs Implements WithBun() extension method with Bun-specific configuration including lockfile handling, Docker image override, and install command setup
tests/Aspire.Hosting.JavaScript.Tests/PackageInstallationTests.cs Adds test verifying Bun uses --frozen-lockfile flag in publish mode
tests/Aspire.Hosting.JavaScript.Tests/AddViteAppWithPnpmTests.cs Adds test confirming Bun correctly omits command separator when passing script arguments

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jan 3, 2026
@emilienbev
Copy link
Contributor Author

@dotnet-policy-service agree

@davidfowl
Copy link
Member

✅ End-to-End Verification Complete

Tested PR locally using dogfood CLI. All scenarios work correctly:

Test Results:

Feature Result
WithBun() extension method ✅ Works
bun install runs automatically ✅ 173 packages installed in 5.87s
bun run dev executes correctly ✅ Vite started
No -- separator in command args ✅ Confirmed: ["run", "dev", "--port", "54299"]
Package manager annotation set to bun ✅ Resource source shows "bun"
Web frontend accessible ✅ HTTP 200 OK

Console Logs Evidence:

webfrontend-installer:

bun install v1.3.6 (d530ed99)
173 packages installed [5.87s]

webfrontend:

Cmd = bun.exe, Args = ["run", "dev", "--port", "54299"]

The WithBun() feature works as documented - bun is used for both package installation and script execution, with proper argument handling (no -- separator needed).

Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

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

Looks good to me, we'll :shipit: - thank you 🙏

@IEvangelist IEvangelist merged commit 930c1a6 into dotnet:main Jan 16, 2026
286 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 13.2 milestone Jan 16, 2026
@github-actions github-actions bot locked and limited conversation to collaborators Feb 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for bun as package manager

4 participants