Skip to content

Commit 33c628c

Browse files
authored
fix(bun): consume plugin.bun (#603)
1 parent 11bea2a commit 33c628c

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

src/bun/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export function getBunPlugin<UserOptions = Record<string, never>>(
3232
async setup(build) {
3333
const context = createBuildContext(build)
3434

35+
for (const plugin of plugins) {
36+
await plugin.bun?.setup?.(build)
37+
}
38+
3539
if (plugins.some(plugin => plugin.buildStart)) {
3640
build.onStart(async () => {
3741
for (const plugin of plugins) {

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,4 +131,36 @@ describe.skipIf(typeof Bun === 'undefined')('bun nested plugin support', () => {
131131

132132
Bun.file = originalFile
133133
})
134+
135+
it('should call plugin.bun.setup with the build before standard hooks', async () => {
136+
const callOrder: string[] = []
137+
const bunSetup = vi.fn((_build: Bun.PluginBuilder) => {
138+
callOrder.push('plugin.bun.setup')
139+
})
140+
141+
const unplugin = createUnplugin(() => ({
142+
name: 'with-bun-setup',
143+
bun: { setup: bunSetup },
144+
resolveId: () => null,
145+
load: () => null,
146+
}))
147+
148+
const bunPlugin = unplugin.bun()
149+
const mockBuild = {
150+
onResolve: vi.fn(() => {
151+
callOrder.push('onResolve')
152+
}),
153+
onLoad: vi.fn(() => {
154+
callOrder.push('onLoad')
155+
}),
156+
onStart: vi.fn(),
157+
config: { outdir: './dist' },
158+
} as never as Bun.PluginBuilder
159+
160+
await bunPlugin.setup(mockBuild)
161+
162+
expect(bunSetup).toHaveBeenCalledTimes(1)
163+
expect(bunSetup).toHaveBeenCalledWith(mockBuild)
164+
expect(callOrder).toEqual(['plugin.bun.setup', 'onResolve', 'onLoad', 'onLoad'])
165+
})
134166
})

0 commit comments

Comments
 (0)