-
Notifications
You must be signed in to change notification settings - Fork 15
Expose SetModuleLoaderFunc to allow for dynamic module resolution #26
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
base: master
Are you sure you want to change the base?
Conversation
|
just wanted to start by saying I'm super impressed with this architecture, I hate dynamic dependencies, wrapping quickjs in WASM is so freaking cool. I've been working on a side project that involves having multiple JavaScript runtimes that need to communicate and call each other. Because of this, I needed a way to resolve module imports dynamically at runtime. This PR is my initial attempt to introduce the underlying changes needed to enable that custom resolution logic. I'd love to contribute if this feature is something you think would be useful to others. I'm not totally sure if I've followed all the existing idioms and architectural patterns you're forming in the library yet, but am very open to any suggestions you may have. Thank you! |
|
@pborges Hey! Thanks so much for putting this together! |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #26 +/- ##
==========================================
- Coverage 99.75% 99.13% -0.62%
==========================================
Files 15 15
Lines 2831 2885 +54
==========================================
+ Hits 2824 2860 +36
- Misses 3 15 +12
- Partials 4 10 +6
🚀 New features to boost your workflow:
|
|
Of course! If you want me to do some more work on it let me know. |
|
@pborges I see there's a lint CI error that needs to be fixed first. Once that's sorted out, we can get it merged. |
|
I guess I am confused at this point the only linter errors I see are in unchanged files :/ |
|
@pborges Got it, I'll go ahead and merge it and try fixing the lint error on my side. |
|
Thanks! I think I took care of the linter errors (even the ones not in the affected files) Not 100% why the linter was concerned with those files though |
|
I am not sure retuning a string is the best bet... I am experimenting with returning a qjs.Value for the module which might make more sense, I wouldn't bother merging this, might be a code smell |
Add Custom Module Loader Support
Summary
Exposes QuickJS's
JS_SetModuleLoaderFuncto Go, enabling custom module loading from memory, HTTP, databases, or any Go-accessible source.Motivation
Previously, the library only supported loading ES6 modules from the file system. This limitation prevented:
Changes
New API
Runtime Method:
Loader Function Signature:
Return Values:
Example Usage
Virtual Modules from Memory:
Access Control:
Implementation Details
- GoModuleLoaderProxy - C callback registered with QuickJS
- QJS_SetModuleLoaderCallback - Sets up the loader with callback ID
- Uses QuickJS's opaque pointer pattern (idiomatic C)
- JsModuleLoaderProxy - WASM host function that bridges to Go
- createModuleLoaderProxyWithRegistry - Creates the proxy with registry
- readStringFromWasmMem - Utility to read C strings from WASM memory
- SetModuleLoaderFunc - Public API method
- Registers Go function in proxy registry
- Calls C layer to set up the loader