Open
Description
Here's a draft of what solution I can think of regarding relations between loaders and import assertions.
Relation of ESMLoader
class with import assertions:
Before resolve() |
resolve() |
Between resolve() and load() |
load() |
After load() |
---|---|---|---|---|
Check if importAssertions.type value is supported |
nothing | use importAssertions.type to check for race conditions |
nothing | check if finalFormat is compatible with importAssertions.type |
nothing | pass importAssertions to resolve() |
check if importAssertions.type value is supported, and use it to check for race conditions |
nothing | check if finalFormat is compatible with importAssertions.type |
nothing | pass importAssertions to resolve() |
disallow race conditions?1 | nothing | check if finalFormat is compatible with importAssertions.type |
nothing | pass importAssertions to resolve() |
one of the above | pass importAssertions to load() |
check if importAssertions.type value is supported and compatible with finalFormat |
nothing | pass importAssertions to resolve() |
one of the above | pass importAssertions to load() and let load() do the checks |
nothing |
nothing | nothing | use importAssertions.type to check for race conditions |
pass importAssertions to load() and let load() do the checks |
nothing |
nothing | nothing | nothing | pass importAssertions to load() and let load() do the checks |
nothing |
- The first one is the approach on my first
Unflag import assertions
PR, drawbacks of this approach have been discussed. - The second seems really appealing to me, it would allow folks to write hooks to support assertion-less JSON, and also support import assertions that are not supported by Node.js.
- Same thing except the loader throws if a URL is loaded with different assertions. It puts the burden of handling race conditions to the
resolve
hook. Not sure this is actually doable and/or desirable. - pass the output
importAssertions
ofresolve()
toload()
context
. This adds complexity, not sure it's worth it. - Same but now the loader hook is in charge of doing the verification, so users can opt-out. That seems... dangerous? but maybe it's actually OK?
- Same but import assertions are not passed to
resolve()
.
My (new) favourite is 2.
: it seems to me like the perfect balance between simplicity and letting users do powerful things (e.g.: it would be quite easy to implement a loader that supports assertionless imports). I have a PR almost ready implementing this.
Anyway, we can discuss that on next week meeting since Goeffrey invited me, but happy to hear thoughts before that if people want to share them.
Footnotes
-
if the resolver returns an
url
that's already in the cache and the returnedimportAssertion.type
has a value different from the one in the cache, throw aTypeError
. ↩
Metadata
Metadata
Assignees
Labels
No labels