Provide SourceTextModule sync versions of link and evaluate methodsΒ #59656
Copy link
Copy link
Closed
Copy link
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Description
What is the problem this feature will solve?
Allow to reimplement require(esm) logic with custom require. Current logic in jest covers only require(cjs) and native modules and to support require(esm) there is need of SourceTextModule sync version with sync link and evaluate methods.
What is the feature you are proposing to solve the problem?
linkSync and evaluateSync methods for SourceTextModule or another sync way to programmaticaly create and initialize module.
What alternatives have you considered?
Customization hooks but looks like, according to #56241, there is fundamental problem with implementing evaluation hook for esm modules.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
feature requestIssues requesting new Node.js features.Issues requesting new Node.js features.vmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
Type
Projects
- StatusShow more project fieldsAwaiting Triage
Activity
joyeecheung commentedon Aug 28, 2025
The synchronous linking method is implemented in #59000
I am not sure if evalauteSync is entirely necessary - evaluation is already synchronous if the module does not contain a top-level await and the returned promise would be synchronously fulfilled with undefined, as specified in ECMA262 (in this case, the promise is just like a maybe, you can just assume that it's already fulfilled in synchronous code).
legendecas commentedon Aug 29, 2025
I think to be able to implement userland
require(esm)on top ofvm.SourceTextModule, there must be a way to detect if the module graph is async (like, if it and its dependencies contain TLA or not), so that a userland framework can do:vm: expose hasTopLevelAwait on SourceTextModule
vm: expose hasTopLevelAwait on SourceTextModule
vm: expose hasTopLevelAwait on SourceTextModule
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous
benchmark: add benchmark for leaf source text modules
vm: make vm.Module.evaluate() conditionally synchronous