-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bun runtime plugin onResolve
doesn't filter non-file:
protocol imports
#9863
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
That's interesting. I found #4458 talking about adding import map support to the bundler. But I wonder how one would define import maps for the runtime? Bunfig? |
Ultimately my interest lies in being able to make up a module from thin air when using a custom protocol in the import. Ideally |
This comment was marked as off-topic.
This comment was marked as off-topic.
This is related to Edit: turns out mutating import maps at runtime is not possible in browsers, I mis-remembered: WICG/import-maps#92. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I am not attempting to create a custom protocol, I have an existing custom protocol which I am looking to bridge Bun into supporting. It is possible that runtime plugins are intentionally locked into the Node has experimental support for custom loaders which I believe are roughly equivalent to Bun's runtime plugins and AFAICT it should be possible to create a custom loader which matches the URL by protocol, here demonstrated on a rudimentary HTTP/HTTPS loader: Whether it is by |
This comment was marked as off-topic.
This comment was marked as off-topic.
Whatever is on the other side of the import is dynamic, I can't bake it in or use a static |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Thanks for the PR, I noted in the repro repo README and in my initial post in this issue that I can't use As far as import maps go, I was just pondering how it could look, I am aware Bun doesn't support import maps at the moment, but should it, I would hope for an implementation where the import map can be passed to I am aware of the Node loader support, I've linked it previously. This is something I am hoping to do an equivalent of in Bun, because it seems like it can support custom protocols as the HTTP/HTTPS loader demonstrates. I believe if I've been able to build Bun locally and while I am not at al proficient in Zig, I think I've gathered enough context by now to maybe be able to contribute regex support to |
This comment was marked as off-topic.
This comment was marked as off-topic.
I cannot write out all the specifiers I am expecting as the specifiers are dynamic, not known at compile time. |
This comment was marked as off-topic.
This comment was marked as off-topic.
With |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Here's the simplest case I can think of to demonstrate
|
What version of Bun is running?
1.1.0+5903a6141
What platform is your computer?
Darwin 23.4.0 arm64 arm
What steps can reproduce the bug?
See my repro repo: https://github.com/TomasHubelbauer/bun-runtime-plugin-onResolve-custom-protocol
Make a runtime plugin with an
onResolve
hook:Register it in
bunfig.toml
:preload = ["./plugin.ts"]
.Run a script with an import that should get captured by the plugin:
bun index.ts
:So far everything works as expected:
Change the plugin to filter for a custom protocol:
Change the import and run the script again:
Now we see a problem:
Notice that
onResolve2
was never even called.This might be a design decision, not a real bug, if I learn as much, I will contribute a documentation change explaining this.
What is the expected behavior?
What do you see instead?
A runtime error in module resolution not preceded by the custom
onResolve
hook call.Additional information
This might not be a bug but a design decision. I ended up trying this, because
build.module
doesn't accept a regex for the module name (so that I could virtualize all modules on a custom protocol) so I ended up looking atonResolve
. Ultimately I would prefer a change tobuild.module
that allows for regexes, but this might also be worth supporting IMO.The text was updated successfully, but these errors were encountered: