nodejs/node

`vm.compileFunction` is missing `importModuleDynamically`

SimenB opened this issue ยท 3 comments

Is your feature request related to a problem? Please describe.

I'm currently working on implementing support for native ES Modules in Jest. While both vm.SourceTextModule and vm.Script allows us to define an importModuleDynamically option, this is missing from vm.compileFunction. The option is also present in runInContext and runInThisContext.

(I'm aware that vm's ESM APIs are experimental - I'm just playing with the APIs to see if they fit with Jest's use cases for them. It's currently looking really good! ๐Ÿ™‚)

Describe the solution you'd like

The option should be added to compileFunction as well, to have parity with the other vm functions/constructs.

Describe alternatives you've considered

Not using compileFunction and sticking to vm.Script for CommonJS. I'd really like to avoid that as we just migrated to compileFunction which made V8 code coverage mapping from source maps way easier than the old manual module wrapper we use in vm.Scripts. Also, it's a bit cleaner on our side when we can avoid manually creating the module wrapper.

@devsnek hey ๐Ÿ‘‹ Starting to land ESM support in Jest now, and was looking into supporting import() in CJS, and hit this again (forgot I filed it ๐Ÿ˜…). I would offer to help, but I've never done any C++ except for simplistic school assignments some years ago. Looking at #22381 it seems like it's almost entirely C++, but if I can do anything else to help I'd love to!

(As an aside, Jest 25.4 includes primitive support for ESM - I'm really digging the APIs! Thanks for all your hard work on this.)

Ah thank you!

Reopening as this was reverted due to #33166.