| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
Looks interesting. Two questions:
|
Sorry, something went wrong.
setImportMetaCallback in the test is being used to create a 1st class channel from the preload code and the module instances. You can see in the generateModule output that it is reading the references off of import.meta.mock. Per the HTTPS loader PR the actual behavior of import.meta.url on the web differs from files and recreating HTTPS semantics is not currently possible with a loader without manual prefixing of modules with things like import.meta.url = ... new value here ...;\n. See https://github.com/nodejs/node/pull/36328/files#diff-b1de5e9ce1e9b411001c63d11a5092dbba32e1586269a20dc11408375eb2f16cR135-R137
I actually think the problem here is in part my using a MessagePort which wants to asynchronously dispatch events. I generally think we need to move loaders off thread and have faced pushback in the past due to startup penalty of doing so; however, I wrote this with off-thread in mind. Using globals is easier! However, this avoids leaking globals and allows communication to be done in a way that cannot be tampered with or prevented by user code between Loader <-> Preload Code <-> Module Instances. Definitely want to make the API work better so might have to use a different communications API than MessagePort for now. Currently the functions are never passed to the loader via a 1st class reference, they are only passed as a list of exports and the global preload code is managing the first class references. All communication with the loader is done via message ports. |
Sorry, something went wrong.
Yes, but it has enough information to just use mockedModules by itself, without recourse to using meta.mock, no?
🙏
Of course you're right. And to think I wrote something like this... (well, it was a while ago 😊). So, OK, removing my objection on thread-separated loaders. |
Sorry, something went wrong.
|
now that consolidation PR is landed, rebasing, looks like we need a slight alteration to handle multiple nesting importMetaCallbacks |
Sorry, something went wrong.
|
removing draft status since there aren't any pending design comments and hoping to land early next week |
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
Sorry, something went wrong.
|
Reading through CI reliability and the failed CI runs, I think the cause for the failures isn't this PR. |
Sorry, something went wrong.
Co-authored-by: Derek Lewis <DerekNonGeneric@inf.is>
Co-authored-by: Geoffrey Booth <456802+GeoffreyBooth@users.noreply.github.com>
Co-authored-by: Geoffrey Booth <456802+GeoffreyBooth@users.noreply.github.com>
Sorry, something went wrong.
PR-URL: #39240 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
PR-URL: #39240 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
PR-URL: #39240 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
PR-URL: #39240 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Geoffrey Booth <webadmin@geoffreybooth.com>
| Back | FazBrowse Home | New Git URL |
This PR adds a communications channel for loaders to utilize across global preload code and hooks. It allows communication from the loader directly to references. Currently it is somewhat awkward to use since MessagePort does async events but does solve the global usage in https://dev.to/giltayar/mock-all-you-want-supporting-es-modules-in-the-testdouble-js-mocking-library-3gh1 .
The important bit of this PR is that we add a test for mocking via a reflective API on the main thread.
It does alter the API signature of getGlobalPreloadCode and adds a new implicit parameter to change the import.meta initialization, this can be used to fix the problem with HTTPS imports being done via a loader by allowing a rewrite of the import.meta to the proper value instead of the cache key in the module map.
Likely we should iterate on this API since this is more the bare minimum to make things work and not a pleasant API currently.
CC: @nodejs/loaders @giltayar