Skip to content

Commit

Permalink
Fix Jest cache for transform-react-version-pragma
Browse files Browse the repository at this point in the history
  • Loading branch information
tyao1 committed Nov 19, 2022
1 parent c08d8b8 commit 8b4a6ba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
20 changes: 0 additions & 20 deletions scripts/jest/devtools/preprocessor.js

This file was deleted.

36 changes: 25 additions & 11 deletions scripts/jest/preprocessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const coffee = require('coffee-script');

const tsPreprocessor = require('./typescript/preprocessor');
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
const {getDevToolsPlugins} = require('./devtools/preprocessor.js');

const pathToBabel = path.join(
require.resolve('@babel/core'),
Expand All @@ -26,6 +25,9 @@ const pathToTransformInfiniteLoops = require.resolve(
const pathToTransformTestGatePragma = require.resolve(
'../babel/transform-test-gate-pragma'
);
const pathToTransformReactVersionPragma = require.resolve(
'../babel/transform-react-version-pragma'
);
const pathToBabelrc = path.join(__dirname, '..', '..', 'babel.config.js');
const pathToErrorCodes = require.resolve('../error-codes/codes.json');

Expand Down Expand Up @@ -83,8 +85,13 @@ module.exports = {
const plugins = (isTestFile ? testOnlyPlugins : sourceOnlyPlugins).concat(
babelOptions.plugins
);
if (isTestFile && isInDevToolsPackages) {
plugins.push(...getDevToolsPlugins(filePath));
if (
isTestFile &&
isInDevToolsPackages &&
(process.env.REACT_VERSION ||
filePath.match(/\/transform-react-version-pragma-test/))
) {
plugins.push(pathToTransformReactVersionPragma);
}
return babel.transform(
src,
Expand All @@ -103,12 +110,19 @@ module.exports = {
return src;
},

getCacheKey: createCacheKeyFunction([
__filename,
pathToBabel,
pathToBabelrc,
pathToTransformInfiniteLoops,
pathToTransformTestGatePragma,
pathToErrorCodes,
]),
getCacheKey: createCacheKeyFunction(
[
__filename,
pathToBabel,
pathToBabelrc,
pathToTransformInfiniteLoops,
pathToTransformTestGatePragma,
pathToTransformReactVersionPragma,
pathToErrorCodes,
],
[
(process.env.REACT_VERSION != null).toString(),
(process.env.NODE_ENV === 'development').toString(),
]
),
};

0 comments on commit 8b4a6ba

Please sign in to comment.