Skip to content

feature request: add calling thread ID to loader resolve() context #49472

@cjihrig

Description

@cjihrig

What is the problem this feature will solve?

Some loaders, such as a mocking loader, should be aware of the thread initiating the operation. For example, it is common for ESM mocking to pass a list of export names to the loader thread, and later resolve those exports on an application thread. If a module is mocked from one application thread, and another thread tries to import the same module, it will be unaware of the export values. The export values themselves cannot be passed between threads because some values, such as function, do not serialize.

What is the feature you are proposing to solve the problem?

The resolve() loader hook already has a context object, which includes the parentURL. I am requesting that the thread ID also be included. If the thread ID were in the context, the resolve() hook could identify the proper mock (or real) implementation to use, depending on the thread.

What alternatives have you considered?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.loadersIssues and PRs related to ES module loaders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions