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)
Environment
unplugin@3.0.0 + bun@1.3.13
Reproduction
Describe the bug
UnpluginOptionsalready declaresbun?: Partial<BunPlugin>(src/types.ts), mirroring the typed escape hatches foresbuild,vite,webpack, etc. The esbuild adapter consumes its equivalent:The Bun adapter never reads
plugin.bun. Plugins that need Bun-specific behavior — mutatingbuild.config.define, registering extraonResolve/onLoadhooks for bundler-specific quirks, callingbuild.onStartindependently — 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)