Fixes#3894
Previously, runtime plugins (using `plugin()` API) only received `path`
in their onLoad callbacks, making them much less capable than Bun.build()
plugins which receive `path`, `namespace`, and `loader`.
This change adds:
- **namespace** property - allows plugins to distinguish between different
virtual module namespaces
- **loader** property - provides default loader based on file extension
(js, tsx, jsx, json, text, toml, file)
This enables better plugin composition and makes it possible to:
- Pass information from onResolve to onLoad via namespace
- Handle query strings in imports (workaround for missing pluginData)
- Know the default loader for conditional handling
Example usage:
```typescript
plugin({
setup(builder) {
builder.onResolve({ filter: /\.mdx/ }, (args) => {
const [path, query] = args.path.split("?");
// Store query data externally since pluginData doesn't work yet
queryMap.set(path, parseQuery(query));
return { path, namespace: "mdx-loader" };
});
builder.onLoad({ namespace: "mdx-loader" }, (args) => {
// Can now access namespace and retrieve query data
const query = queryMap.get(args.path);
// ... handle MDX with query parameters
});
}
});
```
**Still missing** (future work):
- pluginData property (would require tracking through resolve/load pipeline)
- suffix property (esbuild compatibility)
- defer, side properties (build-specific)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Merge import.meta.require and require to be the same thing
* support `require` and BunPlugin (runtime plugin)
* plugins
* unused code
* revert launch.json
* start this
* commit
* mark all failing tests as todo
* fasdfad
* bundler tests
* tests
* adjust failing tests to todo
* comment out some more tests
* png as test
* WIP
* WIP
* WIP
* WIP
* Improve typechecking in type files
* Fix typechecking
* Update
* Update submodule
* CI for typechecking
* Add ci
* Update commands
* Format after build
* Dont use bunx
* Rename job
* Use nodemodules prettier
* Update workflow
* Use symlink
* Debug
* Debug
* Clean up and rename jobs