-
Notifications
You must be signed in to change notification settings - Fork 75
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
exitModuleImportHook alongside synchronous exit module linking #1506
base: master
Are you sure you want to change the base?
Conversation
@@ -264,6 +285,7 @@ export const parseArchive = async ( | |||
archiveLocation, | |||
computeSha512, | |||
computeSourceLocation, | |||
exitModuleImportHook, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't enjoy passing the hook to the archive making part of the archive flow.
It should not be necessary before runtime.
Solutions:
-
A boolean configuration value saying to "expectExitModuleImportHook" would be enough to omit the archive-time errors where exit import hook would kick in.
pros: no unnecessary importing and hook mechanics before runtime
cons: no early errors if exitModuleImportHook doesn't provide a module, another config item -
exitModuleImportHook accepts options, including
archiveOnly
and if that's truthy, it can avoid importing actual modules while still returning undefined where it originally would (eg. if checking against a list of known builtins it wishes to support)
pros: no additional option, no need to import actual modules during archiving
cons: more complexity in exitModuleImportHook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this parameter to isExitModuleImportAllowed
, since the logic for it may be distinct from the logic of exitModuleImportHook
, and it only needs to return truthy or falsy (default: () => false
). Using myExitModuleImportHook
for the parameter is a degenerate case that works, but isn't ideal (it does too much work, as you point out above).
@@ -239,6 +245,7 @@ export {}; | |||
* @property {Array<Transform>} [transforms] | |||
* @property {Array<Transform>} [__shimTransforms__] | |||
* @property {Record<string, object>} [modules] | |||
* @property {ExitModuleImportHook} [exitModuleImportHook] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if
* @property {Record<string, object> | ExitModuleImportHook} [modules]
would be frowned upon.
I don't see a reasonable usecase for passing both. If passing a function, wrapping it in an object lookup of sorts is pretty much a necessity anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to mix types in this way in the API (policy description type mixing as you've done in the past is a different matter, for reasons of needing to be concise). I'd rather have just an assertion around !modules || !exitModuleImportHook
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to remove the modules
option entirely if you mark it as a breaking change, and update any uses within endo that depend on it to use the exitModuleImportHook
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you're assuming this is more ready than it really is.
I experimented with removing the modules option entirely and it does improve a bunch of things, but also has some interesting consequences. I'll talk about it in the meeting.
@@ -78,6 +78,7 @@ export function scaffold( | |||
tags = undefined, | |||
searchSuffixes = undefined, | |||
commonDependencies = undefined, | |||
additionalOptions = {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't extend scaffold with new minor bits of logic forever...
23dd12b
to
31ab2f9
Compare
31ab2f9
to
5cd0309
Compare
@@ -97,6 +100,16 @@ const makeArchiveImportHookMaker = ( | |||
// per-module: | |||
const module = modules[moduleSpecifier]; | |||
if (module === undefined) { | |||
if (exitModuleImportHook) { | |||
console.error('#################x'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leftover debug message.
@@ -156,6 +158,21 @@ export const makeImportHookMaker = ( | |||
// Archived compartments are not executed. | |||
return freeze({ imports: [], exports: [], execute() {} }); | |||
} | |||
if (exitModuleImportHook) { | |||
console.error('#################i'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it's still early in the implementation and these are useful for showing when and what happens. I'll need them for the meeting.
@@ -239,6 +245,7 @@ export {}; | |||
* @property {Array<Transform>} [transforms] | |||
* @property {Array<Transform>} [__shimTransforms__] | |||
* @property {Record<string, object>} [modules] | |||
* @property {ExitModuleImportHook} [exitModuleImportHook] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm willing to remove the modules
option entirely if you mark it as a breaking change, and update any uses within endo that depend on it to use the exitModuleImportHook
instead.
// note it's not being marked as exit in sources | ||
// it could get marked and the second pass, when the archive is being executed, would have the data | ||
// to enforce which exits can be dynamically imported | ||
return record; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Introducing attenuation by policy in here is going to be difficult, because each time a builtin is imported it'd have to get a new instance for different attenuations and here it'll get memoized.
Abandoned in favor of #1507
This is a PoC exitModuleImportHook.
It works, but not necessarily the way we want it to work.
Notes:
ThirdPartyStaticModuleInterface