-
Notifications
You must be signed in to change notification settings - Fork 7
doc: add node import.meta.require #9
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
Conversation
|
ES modules have an important analysis property over CommonJS modules - the ability to determine apart from This property is effectively invalidated by providing a For WinterCG runtimes, having to support For these reasons, I don't feel this belongs in the WinterCG. I'm happy to discuss further or we could bring this to the WinterCG meeting as well. |
I think the purpose of the registry is just to claim keys so that if other runtimes choose to support them, they support them in the same way. It’s not a requirement that every runtime implement every The arguments about static analyzability are persuasive, but since Node already has |
|
While this repo is maintained as a namespace reservation system, it is being used to gain support for standards, and that is completely natural and we may need to adjust process to work with that reality as well. For example it may help to clearly indicate WinterCG standards versus platform-specific properties like in https://github.com/wintercg/import-meta-registry/pull/7/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5R27). At the end of the day though, everything Node.js implements is effectively a standard, the question is really just if it's expected to work outside of Node.js as well. I'd argue as a kind of intrinsic, In terms of static analysis, So yes I think it matters a lot to change these ergonomics. I'm also happy to discuss use cases further - the desire for sync imports and the desire for sync asset loading. There are many ways to approach these problems and it would be good to work through those discussions as well without jumping to this solution specifically. |
|
@guybedford dynamic imports take an expression, as does require, so both can be statically checked when they're static strings, and neither can be statically checked otherwise. In other words, CJS and ESM imports are precisely identically statically analyzable, as far as I can tell. Can you help me understand where I'm mistaken? It is certainly true that |
|
As I mentioned in #9 (comment), the different property is that so long as there is no This is a major change in module analysis semantics that a module with no other imports may have a hidden runtime require function in it. |
|
Thanks, I think I understand your explanation. I'm still not clear on when this actually causes problems in practice, though (since the specifier can't always be statically known regardless). Do you have a concrete use case that this would break, that you could elaborate on? |
|
Yes this is a different aspect of the analysis of a dynamic specifier expression - it's the guarantee not about knowing what the dynamic specifier expression is, but where the dynamic import expression itself is. That is, we lose being able to statically know all |
|
Right - what's the impact of that loss, though? Or put another way, what's the benefit of having that knowledge? |
|
The importance of determining module access is because WinterCG runtimes want to ahead of time compile all JS code and do not want to have dynamic runtime code loading. |
|
So, a file that has |
|
With |
|
I get that, but since i can make a function |
|
The final call site is the |
|
So if the nonzero possibility of user-weakening already exists, why does the existence of |
|
Because even while analysis of |
This is meh, it's a significative dx improvement. |
|
If the goal is to improve the DX of loading JSON files, we should make an API that does that instead of exposing |
Obviously not only for JSON files. |
|
I think we need to spend more time answering the question - why do we need to improve the DX of |
Is that possible? |
I don't see why not - check if a module can be loaded sync, or it is in the registry cache, and execute it if necessary, throwing on TLA. Or just throw an "unable to execute sync" error. @marco-ippolito hypothetically, if we had an |
|
Im not familiar with |
|
There is no So my question is are we just working around the non-existence of If there really is interest in this from Node.js, then as a representative for Node.js and the OpenJS Foundation at TC39, I could present on an |
I think that's the main motivation. Technically the other thing that Wouldn't |
Certainly it would, but when we get first-class bundles with module declarations and module expressions on the web there may even be web-first motivations to be had for it. Either way it could be worth a discussion at least especially if this is something that would solve a real problem for Node.js. |
|
I dont think I would want to get in the discussion for |
|
If the only reason for Therefore I am completely against any WinterCG endorsement, since if WinterCG and Node.js supports it then it would become a permanent JS standard. |
|
Certainly if there were no standards or alternatives paths I could empathize with the use case - but I'm completely offering to actively help with standardization here, and could present as soon as the next TC39 meeting. |
|
I feel like we shouldn't ship This does raise a meta point that there's a risk of TC39 being bypassed if its process is just too cumbersome. |
|
If
Also afaik WinterCG endorsement doesnt mean that other runtimes HAVE to implement the api, but if they decide to, it should behave in the same way. Node already has the |
What's the difference? As far as I can tell, |
Extension-less for example? I don't think they are equivalent at all. |
That’s subjective
CJS users, sure. But IMO, we should not take familiarity with CJS for granted, there are new JS users everyday, and it doesn’t seem unlikely they would familiarize themselves only with ESM, so having a CJS API on all ES modules only muddies the water on that regard.
Consider the PR on nodejs/node also blocked by me for the above reason. I’m fine with this PR though. |
|
Ok closing both PRs since there is no consensus.
We already have that, its called
true, but again we already fixed this limitation in Node and at least one other runtime, so that would be great to have in spec but I dont see why we shouldn't improve current DX I feel like the conversation is not going anywhere, and the reasons against are not more than the pros imho, but I don't have the energy to continue the discussion after I have explained my points. |
At least as of today, |
|
I've created https://github.com/guybedford/proposal-import-sync to further investigate the potential for a |
Refs: nodejs/node#55730
I will update documentation once it lands