mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
Fixes #5303 Previously, when a plugin's onLoad callback returned null or undefined, Bun would throw a TypeError: "onLoad() expects an object returned". This change allows plugins to return null/undefined to signal "no match" and fallback to the default loading mechanism (filesystem or next plugin), matching the behavior of onResolve. This is useful for: - Conditional file handling (only process certain files) - Plugin chaining (let another plugin handle it) - Leveraging Bun's built-in loading for some files The implementation follows the same pattern as onResolve: - null/undefined -> continue to next plugin/fallback - Other non-objects (boolean, number, string) -> throw TypeError - Objects -> validate and process Note: In Bun.build() API (BundlerPlugin.ts), ALL non-object values fallback (including primitives like true, 42, "string"), but the C++ layer used by runtime plugins follows stricter validation like onResolve. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>