[Feature]: Add jest version to TransformOptions
🚀 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:
- Everyone must release a new major version of their transformers.
- 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.
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)
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.
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.
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.
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.
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.