Skip to content

Support an async "preload" phase for source transformers #11081

@nicolo-ribaudo

Description

@nicolo-ribaudo

🚀 Feature Proposal

Source transformers (such as babel-jest) should be allowed to have a one-time asynchronous initialization step, to load external resources or dependencies.

This step must be executed before compiling, so that require() calls can still be intercepted and handled synchronously.

Motivation

We are exploring publishing Babel as ESM starting from Babel 8. This means that would not be possible to synchronously require("@babel/core") anymore, but babel-jest would need to load it with await import("@babel/core").

Note that if Babel will be the only reason to implement this feature, we should wait until we are 100% sure that Babel will be released as ESM.

Example

I don't know how the source transformers API works 😅 If anyone can suggest an example, I can edit this description

Pitch

Why does this feature belong in the Jest core platform?

Transformers are already part of the core platform, and it's impossible to implement it externally.

Ref #9504 (comment), cc @ahnpnl

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions