Skip to content

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

Description

@81reap

Environment

unplugin@3.0.0 + bun@1.3.13

Reproduction

import { createBunPlugin } from "unplugin";

await Bun.write("./entry.ts", "console.log(process.env.MY_FLAG)\n");

const plugin = createBunPlugin(() => ({
	name: "define-injector",
	bun: {
		setup(build) {
			build.config.define = {
				...(build.config.define ?? {}),
				"process.env.MY_FLAG": JSON.stringify("from-plugin"),
			};
		},
	},
}))();

await Bun.build({
	entrypoints: ["./entry.ts"],
	outdir: "./dist-03",
	plugins: [plugin],
});

const out = await Bun.file("./dist-03/entry.js").text();
console.log("---OUTPUT---");
console.log(out);
console.log("---");
if (out.includes('"from-plugin"')) {
	console.log("✓ plugin.bun.setup WAS consumed (issue would be invalid)");
} else if (out.includes("process.env.MY_FLAG")) {
	console.log("✗ plugin.bun.setup IGNORED (issue is valid)");
} else {
	console.log("? indeterminate");
}

Describe the bug

UnpluginOptions already declares bun?: Partial<BunPlugin> (src/types.ts), mirroring the typed escape hatches for esbuild, vite, webpack, etc. The esbuild adapter consumes its equivalent:

// src/esbuild/index.ts
if (plugin.esbuild?.setup) return plugin.esbuild.setup(rawBuild)
plugin.esbuild?.config?.call(context, initialOptions)

The Bun adapter never reads plugin.bun. Plugins that need Bun-specific behavior — mutating build.config.define, registering extra onResolve/onLoad hooks for bundler-specific quirks, calling build.onStart independently — have nowhere to put that code, even though the type allows it.

Additional context

No response

Logs

$ bun run 03-bun-hatch.ts 
---OUTPUT---
// entry.ts
console.log(process.env.MY_FLAG);

---
✗ plugin.bun.setup IGNORED (issue is valid)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions