jest icon indicating copy to clipboard operation
jest copied to clipboard

[Feature]: Add jest version to TransformOptions

Open barak007 opened this issue 3 years ago • 2 comments

🚀 Feature Proposal

Add current running jest major version to TransformOptions.

Motivation

https://github.com/facebook/jest/pull/12638 introduced a breaking change to the jest transformers API. In general I think that this change does not worth it, and I would consider reverting it.

It has cupule awkward side effects:

  1. Everyone must release a new major version of their transformers.
  2. You must maintain two codebases* to support jest <27 and jest >28 for such a simple condition.

This proposal will provide a way to mitigated the bad effects by allowing the transformer author to take the jest version into consideration.

If TransformOptions would have the jest version (or the "transformers API version") one would able query what to return. This way you will able to keep a single codebase to support both major versions.

This is the least amount of work I can think of from jest side.

*(entries | major versions | files)

Example

function createTransformer() {
  return {
    process(sourceText, sourcePath, options) {
      if (options.version > 27) {
        return {
          code: sourceText,
        };
      } else {
        return sourceText;
      }
    },
  };
}

Pitch

The transform system belongs to jest.

barak007 avatar Sep 07 '22 19:09 barak007

In this specific case it's not needed as jest supports {code: string} since #2290 released more than 5 years ago and you can just use the "new" format.


However, I'm not opposed to adding the Jest version in the options - would you be up for sending a PR? I don't think this is currently passed through, but adding it as part of GlobalConfig or something seems sensible (and not allow the user to set it)

SimenB avatar Sep 08 '22 09:09 SimenB

Actually I didn't notice when this feature introduced. for my use case only >2% of our projects uses older version then 22. Now I just return the object. problem solved for me.

I still think it can be helpful to know in what version you are currently running, unfortunately I will not able to open PR soon.

barak007 avatar Sep 08 '22 21:09 barak007

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Oct 08 '22 21:10 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Nov 07 '22 21:11 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. Please open a new issue if the issue is still relevant, linking to this one.

github-actions[bot] avatar Nov 07 '22 21:11 github-actions[bot]

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[bot] avatar Dec 08 '22 00:12 github-actions[bot]