Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Support asynchronous createTransformer #13759

Closed
lachrist opened this issue Jan 12, 2023 · 4 comments · Fixed by #13762
Closed

[Feature]: Support asynchronous createTransformer #13759

lachrist opened this issue Jan 12, 2023 · 4 comments · Fixed by #13762

Comments

@lachrist
Copy link
Contributor

🚀 Feature Proposal

Support asynchronous functions for createTransformer in the transformer API.

Motivation

Support asynchronous operations in createTransformer. In my case, I need to perform some pre/post processing around an existing transformer which is an esm modules.

Example

export const createTransformer = async (options) => {
  const { process } = await import(options.path);
  return {
    process: (content, path, options) => {
      console.log("pre-processing here");
      const result = process(content, path, options);
      console.log("post-processing here");
      return result;
    },
  };
};

Pitch

Currently there is now way to perform asynchronous operations in createTransformer which is needlessly restrictive. Indeed, it seems this would only require but minimal code changes because the createTransformer is already called inside an asynchronous function.

packages/jest-transform/src/ScriptTransformer.ts#L272

transformer = transformer.createTransformer(transformerConfig);
transformer = await transformer.createTransformer(transformerConfig);
@SimenB
Copy link
Member

SimenB commented Jan 12, 2023

PR very much welcome! As you mention, support should be fairly trivial

@lachrist
Copy link
Contributor Author

Hi @SimenB thanks for the swift reply.
I will try to get that done today.

Cheers

@SimenB
Copy link
Member

SimenB commented Jan 24, 2023

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants