Skip to content

fix(bun) :: consume plugin.bun#603

Merged
sxzz merged 1 commit into
unjs:mainfrom
81reap:feat/bun-plugin-escape-hatch
May 22, 2026
Merged

fix(bun) :: consume plugin.bun#603
sxzz merged 1 commit into
unjs:mainfrom
81reap:feat/bun-plugin-escape-hatch

Conversation

@81reap

@81reap 81reap commented May 22, 2026

Copy link
Copy Markdown
Contributor

I am volunteering and working on getting a bun plugin for TanStack/router and found this bug.

Summary by CodeRabbit

  • New Features
    • Bun plugins now support an optional setup hook that runs during plugin initialization, guaranteed to execute before other standard plugin hooks.
  • Tests
    • Added a Bun-only unit test verifying the setup hook is invoked exactly once and occurs prior to standard hook registrations.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 22, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fe66fdd3-1131-497d-88fa-e2f2e00a2782

📥 Commits

Reviewing files that changed from the base of the PR and between 19ba784 and 4d08c7d.

📒 Files selected for processing (2)
  • src/bun/index.ts
  • test/unit-tests/bun/nested.test.ts

📝 Walkthrough

Walkthrough

Calls each generated plugin's optional bun.setup(build) inside the Bun plugin's setup(build) before registering standard Bun hooks; adds a unit test asserting bun.setup runs once and before onResolve/onLoad.

Changes

Bun setup hook invocation

Layer / File(s) Summary
Bun setup hook implementation
src/bun/index.ts
The Bun plugin setup(build) now iterates instantiated plugins and awaits each plugin's optional bun.setup?.(build) before registering standard hook handlers.
Execution order verification test
test/unit-tests/bun/nested.test.ts
Adds a Bun-only test that mocks bun.setup and mockBuild handlers, runs bunPlugin.setup(mockBuild), asserts bun.setup was called once with mockBuild, and that its call occurs before onResolve and onLoad registrations.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Poem

"I'm a rabbit in the build, nibbling at the seam,
bun.setup wakes the plugins — a neat little dream.
One call, clean and early, before hooks take flight,
Order kept tidy, everything feels right.
Hooray for small fixes and carrot-coded light!"

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(bun) :: consume plugin.bun' directly describes the main change: consuming the plugin.bun.setup hook in the Bun plugin implementation.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/bun/index.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.

test/unit-tests/bun/nested.test.ts

ESLint skipped: the ESLint configuration for this file references a package that is not available in the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@test/unit-tests/bun/nested.test.ts`:
- Around line 141-163: The test only exercises bun.setup so onResolve/onLoad
registration never runs; update the test to provide/verify standard hook
registration by adding dummy onResolve/onLoad hooks to the plugin declaration
(e.g. pass bun: { setup: bunSetup, onResolve: bunOnResolve, onLoad: bunOnLoad }
when calling createUnplugin) or alternatively add a separate plugin that
supplies onResolve/onLoad, then call bunPlugin.setup(mockBuild) and assert
callOrder includes 'onResolve'/'onLoad' after 'plugin.bun.setup' and that
mockBuild.onResolve/onLoad were called; reference createUnplugin, bunSetup,
bunPlugin.setup, mockBuild, and callOrder to locate and change the test.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f464f193-446b-4de0-a48e-ece92194b208

📥 Commits

Reviewing files that changed from the base of the PR and between 11bea2a and 19ba784.

📒 Files selected for processing (2)
  • src/bun/index.ts
  • test/unit-tests/bun/nested.test.ts

Comment thread test/unit-tests/bun/nested.test.ts
@pkg-pr-new

pkg-pr-new Bot commented May 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/unplugin@603

commit: 4d08c7d

@sxzz sxzz merged commit 33c628c into unjs:main May 22, 2026
11 checks passed
@sxzz sxzz linked an issue May 22, 2026 that may be closed by this pull request
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.

Bun adapter: plugin.bun escape hatch is typed but never consumed

2 participants