-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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: add import.meta.require
#55730
esm: add import.meta.require
#55730
Conversation
Review requested:
|
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.
Did the discussion settle on a decision around the perf implications?
a833dcc
to
8705725
Compare
Would be great to have some time at the collab-summit to discuss |
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.
Is there still demand for it? I'm not against it but I don't expect many people to need it when you can usually just import the common js modules.
8705725
to
4c0d438
Compare
The primary use cases I can see for this is importing JSON files, so you don't have to write all the |
4c0d438
to
78cc229
Compare
0be122b
to
62df36f
Compare
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.
🙌 LGTM (assuming it's needed and the potential perf concern is 👍)
This seems a little weakly motivated in the PR description - it would help a lot to get more background on the specific use cases this is seeking to solve. |
This needs to go through WinterCG before landing. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #55730 +/- ##
========================================
Coverage 88.40% 88.40%
========================================
Files 654 654
Lines 187655 187773 +118
Branches 36111 36131 +20
========================================
+ Hits 165889 165997 +108
- Misses 14996 15008 +12
+ Partials 6770 6768 -2
|
For wintercg, the most that needs to happen is a PR adding the new thing to https://github.com/wintercg/import-meta-registry |
WinterCG PR: wintercg/import-meta-registry#9 |
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.
LGTM!
46623ef
to
303de93
Compare
I've posted my arguments against this in the WinterCG issue here - wintercg/import-meta-registry#9 (comment). If Node.js does not want to discuss this in a WinterCG context and would rather make it a project issue I'm happy to bring discussion back here too. |
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 much prefer to see a different API, ideally one that could be supported by other runtimes, to address that specific use-case. Adding a request for changes to make sure this doesn't land before the cross runtime solution have been ruled out.
The feedback is not very useful honestly. If you propose changes to the API please suggest what kind of API you would like to see.
I also dont agree with the changes proposed, all other |
I really don't see why the former would imply the latter 😅
The |
e313daf
to
44652ff
Compare
I've posted https://github.com/guybedford/proposal-import-sync to follow-up exploration in this space, and will add it to the agenda for the TC39 modules group meeting on Thursday. If anyone is interested in discussing this you are welcome to attend, the event is available on the public TC39 calendar here - https://calendar.google.com/calendar/u/0/event?eid=c2luNm9jcm4wbTJyNXNxY2JkbGZtdmdwZWNfMjAyNDExMTRUMTYwMDAwWiAzN2EyMTA3ZGZmMTUxOTNiNDJmZmZhMDkxYmM5OTkxNjU2OTVkNDNiN2U0ZjQzYjY1ZWFiMDkzZGEyNzU3YTNhQGc. |
By the way I don't think module.exports = {
plugins: [
require('@tailwindcss/forms'),
],
} Now if you do this const config = {
plugins: [
????('@tailwindcss/forms'),
],
}
export default config;
export { config as "module.exports" }; The The example may be easier to workaround if users have control over the config and can just unwrap it, but compatibility issues can still arise from fragmented versions or if the return values get encapsulated and passed around (imagine the API just takes specifiers instead of giving control to users how it should be loaded), and this return value mismatch can happen to many other use cases. In that vein having a non-functional replacement just means it'll encourage people to do |
I think this is still worth pursuing (in a different form), I will reiterate on this once I'm back from vacation |
History:
Consider the following cjs snippet:
The equivalent in esm would be something like (more or less):
We could improve the dx with the new
import.meta.require
:Now that we have cjs/esm interoperability we can create
import.meta.require
to syncronously require modules in ESM.It's just an alias for:
WinterCG PR: wintercg/import-meta-registry#9