-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
esm: Modify getFormat and getSource loader hooks #34144
esm: Modify getFormat and getSource loader hooks #34144
Conversation
This came up when trying to implement hooks that would get sources from a location with its own meta data (e.g. HTTPS). The current model requires that the format is determined before trying to load the source which isn't really possible there. Allowing |
I agree with the motivation but I'm not sure about this specific solution, specifically with the disagreement among hooks as that could be difficult to debug. |
One thing @GeoffreyBooth brought up: If the hooks get reshuffled, it may be possible to only get
The downside is that we'd have to decide what the default I think my current vote would be to reorder (call |
/cc @nodejs/modules-active-members (since the discussion has started anyhow :)) |
Looking forward to any further thoughts/insight on this! |
@julian-londono just post a comment when you are ready for further review here. Another question I had about this - would it make sense for the |
Good question, I could see this having valid use cases, but it was not under the original scope of this change - I can explore this more and get back to you @guybedford |
I've created an doc summarizing my exploration into this issue and potential solutions (RFC): @guybedford : We think that allowing |
Looking forward to some thoughts about my exploration into the issue - after this I could move forward with adding potential documentation updates 👍 |
It still feels to me a little inconsistent to have transformSource not fit the model. For example, how would a loader be written to support TypeScript if it were to compose with an existing loader that returned the source from getSource? It would need to override both hooks... most users wouldn't hit that until the composition case actually happens making this somewhat of a composition footgun. Trying to think of alternatives here... would it be an option to reorder getFormat to be called after getSource so that the internal cache can be used without needing to trigger the fetch separately? |
Seems like a good alternative is to remove the
In this case, |
This sounds like a great concept to me! |
This PR aims to amend the current behavior of the
getFormat
andgetSource
experimental loader hooks by allowinggetSource
to optionally override the format of the source that had been defined bygetFormat
.This is an active WIP ; I am working under the guidance of contributor @jkrems
Checklist
make -j4 test
(UNIX) passes