-
Notifications
You must be signed in to change notification settings - Fork 11
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
The missing ability in the new spec (2): ES Module hook #12
Comments
Hi @Jack-Works, Awhile back we had a Realms proposal that was doing too much with a single abstraction. We have since split this into separate proposals for Realms (this one), Compartments https://github.com/tc39/proposal-compartments , and SES https://github.com/tc39/proposal-ses . https://www.youtube.com/watch?v=pMyGLmfgU5A&list=PLzDw4TTug5O3vIAd4IR1Gp5t_46co_dv9 is a good explanation of Compartments after it was separated from Realms but before it was separated from SES. However, almost all of this explanation remains valid. The Realms proposal now is only about creating a new set of primordial intrinsics. The Compartments proposal is about customizing execution / evaluation within a Realm. This involves controlling three "namespaces" that provide the context for evaluation -- globals, imports, host hooks. Please re-file these issues there, as is relevant to the state of the Compartments proposal. Note that many of the host hook issues may be delayed to yet another follow-on proposal. But all the hooks needed for manipulating module importing behavior will remain in the Compartments proposal. |
@erights we can also transfer the issue directly on GitHub. I agree this might also be in the context for Compartments. |
Please do. Thanks. |
The current Compartment API can do all of those things besides source text modification |
It's important to hook the imports to archive the virtualization
In the old API, it is possible to do this via code transformation by the rewrite hook (#243).
Based on the old API (which have no support on ES Module), I created a wrapper (https://github.com/DimensionDev/webextension-polyfill/blob/master/src/realms.ts) to transform all ES Module into SystemJS format
My
SystemJSRealm
supports ESModule, dynamic import, andimport.meta
based on the old Realm API.In the new Realm, the new
Realm#import()
API makes ES Module becomes the first-class citizen but I am no longer be able to do the things in the old Realms API.I propose to add the following hooks:
Clarify: The order IMO should be:
ExportRecord
hook returns a result, use it as the Module record.fs
,path
, orstd:....
HostResolveModuleSpecifier
hook.lodash
into the host supported pathhttps://cdn.pika.dev/lodash
FetchSourceText
hook.HostFinalizeImportMeta
hookimport.meta
propertyThe text was updated successfully, but these errors were encountered: