Files
bun.sh/test/js
Claude Bot d8e57cd4c1 Add namespace and loader properties to runtime plugin onLoad callbacks
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>
2025-11-01 08:31:12 +00:00
..
2025-10-27 18:58:06 -07:00