Update 5/11/2018: The Dynamic Modules implementation is now complete in v8, pending further review (at https://chromium-review.googlesource.com/c/v8/v8/+/1303725). This means we can have named exports in transparent interop of ESM from CJS
As you know, I've been pushing a Dynamic Modules specification for ensuring named exports on CommonJS while retaining a correct execution order in transparent initerop. This spec has been carefully worked out at https://github.com/guybedford/proposal-dynamic-modules.
While transparent interop remains a possibility, I believe this specification and work is important to follow so we can provide the best experience to users.
Initially this was created as a Stage 1 TC39 proposal, but it turns out the model is better served by having a Node-specific module record specification implemented in V8, just like Web Assembly will be its own module specification outside of TC39.
This way only a few ECMA262 specification changes are needed to support dynamic modules - https://github.com/tc39/ecma262/pull/1306.
This PR was discussed at the latest TC39 meeting, and it was determined that it should only land following implementation work / feedback.
Thus, the next steps on Dynamic Modules here are:
While this work all rests on a hypothetical, I hope we can all appreciate it is an important consideration on that hypothetical, and should be pushed regardless.
i'd be happy to help with the v8 impl.
I've done some work on import.meta in V8 in the past. Happy to help!
Thanks @jkrems, whats the best way to reach you to discuss the details further?
Most likely email or GChat ([email protected]) or Twitter DM (@jankrems). The former definitely is the more reliable way of reaching me quickly.
@jkrems ok I believe I've sent you an invite there, but let me know if you don't see it.
I'm not seeing an invite (including in my spam). Just in case you can also try my personal email ([email protected]).
Let me know if there's any communication method you'd prefer in case this doesn't work out. :)
To further update on the spec and implementation here:
The API can be seen in the test case here using HostExecuteDynamicModuleCallback and module->SetExport.
The following implementation steps are pending:
@jkrems @devsnek thanks both of you for feedback so far, do try it out again if you can!
Nice work! I played around with the test case to try some more module graphs (e.g. multiple imports of the same dynamic import) and it worked without a hitch. :)
(There's a single else on its own line in api.cc but I think the V8 code formatter should be able to take care of that..?)
@guybedford nice work! i have some feedback on the v8 internals that i can put up once you have a CL.
@jkrems awesome to hear it didn't immediately break :)
@devsnek that would be great - feel free to leave feedback at the repo there in the mean time, as it will probably take me a few more days yet to get to items 1 - 3.
Further update on dynamic modules - the implementation at https://github.com/guybedford/v8/compare/master...guybedford:dynamic-modules is now fully spec-complete, and just needs some refactoring work on the data structure and module class side.
@devsnek you mentioned you had some ideas for how to handle the script metadata part of dynamic modules - would value your thoughts on that as I'm starting work on that now.
PR for review at https://github.com/guybedford/v8/pull/2. Comments welcome.
The implementation of dynamic modules was finally completed to spec (and the spec worked out as written). Review at https://chromium-review.googlesource.com/c/v8/v8/+/1303725.
I'd like us to discuss this one more time in tomorrow's meeting and ensure we have explicit consensus from our group that we want this moving forward.
Sure, I'd be happy to provide an update here on how last week's TC39 went.
As per the meeting, I've posted a Node.js issue with a status update at https://github.com/nodejs/node/issues/24894.
Most helpful comment
The implementation of dynamic modules was finally completed to spec (and the spec worked out as written). Review at https://chromium-review.googlesource.com/c/v8/v8/+/1303725.