-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
esm: add import.meta.sync #60652
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.sync #60652
Conversation
|
Review requested:
|
4b714ac to
15c1287
Compare
|
To open the PR against your fork, you'd need to sync the |
Usually I just set the target branch to marco-ippolito/node 🤷 I think its because my fork main is not sync'ed with upstream main. |
|
|
|
I think the naming should still emphasize that it's |
|
I guess I'm also confused why this is better than making Module.createRequire more ergonomic - since |
|
|
I remember that, #55730 (comment) as well - but if it's just "sync import" then you can't do either of those two use cases. Given top-level await, so you can |
|
Another note: since it's intended to be an equivalent of |
Its clearly written in the documentation. Conditional synchronous imports.
I agree, will add it later if there is some consensus |
|
You can already do conditional synchronous imports with |
Thats async... 😄 You need to rewrite the function to be async (or tla) |
|
I think a use case that have come up before during the discussion of the function aSyncAPI(plugins) {
for (const p of plugins) {
const something = import.meta.sync(p);
doSomething(something);
}
// do other things after the plugins are all initialized.
} |
|
Ah, you mean conditional synchronous imports not at the module level. The standard way to do that will be using deferred imports, and then normal JavaScript (simply referencing the identifier would cause the import to happen immediately/sync) - in which case this PR would immediately be obsolete. Is it worth adding this now when any ecosystem adoption will imminently become a legacy problem? |
Did you mean something like |
|
I prefer |
|
Reading #55730 (comment) I remembered that being |
|
Also, just food for thought (not proposing it as anything to be provided to the user land), if the ecosystem did not already universally accept that |
Wouldn't this be covered by dynamic |
I think you'd be referring to |
15c1287 to
b5a91fd
Compare
WinterTC process or TC39 process? I think it's important to be clear about your approach here.
Import sync has been accepted by TC39, and you are a champion of the proposal. The only limitation here is yourself! |
|
I'm a bit reluctant to do this this way now. I think it would be best to hold off a bit longer and see where the tc39 process goes with |
|
@guybedford yeah I mean wintertc we are adding a need property in the |
|
@marco-ippolito is it your plan to do both |
|
I guess if things go well with |
|
@marco-ippolito I think you need to either stick with TC39 process or go with the WinterTC approach but not both. |
What?💀 |
|
I've corrected my comment to (re-edited 11/15):
I stand by the comment though - this feels more like a political strategy than an honest approach to committee engagement and implementation by taking two appraoches at the same time, at the risk of a worse off result for the ecosystem. This is not ad hominem, this is a genuine ecosystem concern. Returning to a a purely technical discussion (and in good faith as always), having both |
|
It's a stage one proposal and for as much as I would like to see it happen, it's gonna take a long time especially since for the web it piggybacks other proposals. I don't see why we can't have it in the runtime. |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
A way to avoid these import { importSync } from 'node:module'
importSync('./foo.js')
// where `./foo.js` resolves relative to this module,
// the same way it would resolve for `import()`Or this: import { require } from 'node:module'
require('./foo.cjs') // Look ma, no `const require = createRequire(import.meta.url)`If it were somehow possible to create the |
|
I didn't plan for my last comment to be the end of the discussion here, so I'd like to first address the communication issues here, and then also give some further background into the cross-standard questions that may not be widely known, looking towards a hopeful path forward on the topic. Firstly to just say, if it were not for Marco, amongst many other things we would simply not have TypeScript support in Node.js. This is a huge accomplishment, and his contributions to the project are hugely valued. I have nothing but respect for his work and always enjoy seeing his contributions and I've said this to him personally. The last thing I would want to do here is cause contributor frictions from insensitive comments. To clarify my words - it is the specific approach and strategy to standards in this PR that I was questioning, and not Marco's character in any way. On to the background - Marco originally posted #55730 last year. My stance on that discussion was the same as it is here - that it is my opinion that execution primitives should be part of TC39. This ensures standard behaviours between runtimes and avoids us losing all that we won in the migration from CommonJS to ESM in having a standard module system. We want Now I don't expect everyone to agree with me on the technical details, and Marco does not need to agree on this, that is not what this discussion was about. This discussion was about the fact that Marco agreed to collaborate on Having taken I strongly believe Marco has since asked to no longer be a co-champion of the proposal, so this proposal is now seeking co-champions. I'd like to use this opportunity to ask anyone interested to please consider coming forward to assist in collaborating on the import.sync spec if they care about this feature, TC39 member or not. I'd be happy to collaborate with anyone seeking to help and provide follow-up presentations at the committee. I'm also actively involved in various modules implementation work as part of my role as a TC39 delegate at Cloudflare for workers and we may be interested in the feature too. We can get this over the line if someone cares. I'd also still be happy to collaborate with Marco as well if he chooses to pick this up again anytime in future. |
|
I can help with championing... but would really like to ask @marco-ippolito to reconsider. It's definitely good work that deserves to move forward. |
|
The issue here isn’t technical. I’m still open to collaborating, but I need to be clear that the way you addressed me wasn’t appropriate. As I mentioned in private, an acknowledgment of that would go a long way toward resetting the conversation so we can move forward productively. |
|
Sure, I can certainly publicly apologize for any insensitivity in the way I made my remark. To say "show some integrity" is indeed a very rough phrasing for what I was trying to convey, and I genuinely apologize for that and with sincerity for future collaboration. |
idk why but I was trying to open the PR again my fork but it keeps opening to nodejs/node regardless...
Anyways here we are gathering some early feedback before we follow the whole wintertc process... etc
Hopefully this will alias https://github.com/tc39/proposal-import-sync if it ever gets accepted