Skip to content

Support async pre/post in plugins #16860

@timofei-iatsenko

Description

@timofei-iatsenko

💻

  • Would you like to work on this feature?

What problem are you trying to solve?

Ecosystem moving towards native ECMAScript modules and even babel itself is finally supporting plugins/preset written in ESM. However, there still babel-plugin-macros which is used in numerous of application which is not supporting ESM and will not without this change.

I'm as a maintainer of Lingui want to modernize codebase and use native ESM modules, but support babel-macros is blocking the whole project of switching to ESM.

The babel-plugin-macros is working in the way that is looking for the imports satisfying a specific pattern and then load an associated module with macro code.

Because writing async visitor is impossible by many reasons, the logic of babel-plugin-macros could be changed.

Plugin could use regexp-based algorithm to find all modules it needs to load in the pre function, and then use loaded modules in the synchronous visitor.

I've found that discussion where it was mentioned that if there would be a good case, it might be considered to be supported. I believe unblocking module which has weekly downloads of 15 million times to use a ESM should be worth it.

Describe the solution you'd like

Make a pre/post async.

Describe alternatives you've considered

The solutions such as

https://github.com/addaleax/synchronous-worker
https://github.com/un-ts/synckit

Will not work when it comes to loading a ESM module, because they use structured clone algoritm, and modules could not be serialized using it.

Documentation, Adoption, Migration Strategy

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    i: needs triageoutdatedA closed issue/PR that is archived due to age. Recommended to make a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions