Update jest preprocessor

parent 221163aa
......@@ -9,6 +9,6 @@
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-flow-strip-types",
"@babel/plugin-transform-regenerator",
"@babel/plugin-transform-runtime"
"@babel/plugin-transform-runtime",
]
}
/* eslint-disable global-require,import/no-extraneous-dependencies */
/**
* Copyright (c) 2015-present, Facebook, Inc.
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
......@@ -11,8 +10,9 @@
/* eslint-env node */
'use strict';
const { transformSync: babelTransformSync } = require('@babel/core');
const {transformSync: babelTransformSync} = require('@babel/core');
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
* found when Flow v0.54 was deployed. To see the error delete this comment and
* run Flow. */
......@@ -23,41 +23,41 @@ const babelRegisterOnly = require('metro-babel-register');
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
const generate = require('@babel/generator').default;
const nodeFiles = RegExp(
const nodeFiles = new RegExp(
[
'/local-cli/',
'/metro(?:-[^/]*)?/', // metro, metro-core, metro-source-map, metro-etc
'/metro(?:-[^/]*)?/', // metro, metro-core, metro-source-map, metro-etc.
].join('|'),
);
const nodeOptions = babelRegisterOnly.config([nodeFiles]);
babelRegisterOnly([]);
/* $FlowFixMe(site=react_native_oss) */
const transformer = require('metro/src/reactNativeTransformer');
const transformer = require('metro-react-native-babel-transformer');
module.exports = {
process(src /* : string */, file /* : string */) {
process(src /*: string */, file /*: string */) {
if (nodeFiles.test(file)) {
// node specific transforms only
return babelTransformSync(
src,
Object.assign(
{ filename: file },
{ sourceType: 'script', ...nodeOptions, ast: false },
),
).code;
return babelTransformSync(src, {
filename: file,
sourceType: 'script',
...nodeOptions,
ast: false,
}).code;
}
const { ast } = transformer.transform({
const {ast} = transformer.transform({
filename: file,
localPath: file,
options: {
ast: true, // needed for open source (?) https://github.com/facebook/react-native/commit/f8d6b97140cffe8d18b2558f94570c8d1b410d5c#r28647044
dev: true,
enableBabelRuntime: false,
experimentalImportSupport: false,
hot: false,
inlineRequires: true,
minify: false,
platform: '',
projectRoot: '',
publicPath: '/assets',
retainLines: true,
sourceType: 'unambiguous', // b7 required. detects module vs script mode
},
......@@ -70,7 +70,7 @@ module.exports = {
[
require('@babel/plugin-proposal-class-properties'),
// use `this.foo = bar` instead of `this.defineProperty('foo', ...)`
{ loose: true },
{loose: true},
],
[require('@babel/plugin-transform-computed-properties')],
[require('@babel/plugin-transform-destructuring')],
......@@ -84,7 +84,7 @@ module.exports = {
[require('@babel/plugin-transform-unicode-regex')],
[
require('@babel/plugin-transform-modules-commonjs'),
{ strict: false, allowTopLevelThis: true },
{strict: false, allowTopLevelThis: true},
],
[require('@babel/plugin-transform-classes')],
[require('@babel/plugin-transform-arrow-functions')],
......@@ -92,11 +92,11 @@ module.exports = {
[require('@babel/plugin-proposal-object-rest-spread')],
[
require('@babel/plugin-transform-template-literals'),
{ loose: true }, // dont 'a'.concat('b'), just use 'a'+'b'
{loose: true}, // dont 'a'.concat('b'), just use 'a'+'b'
],
[require('@babel/plugin-transform-exponentiation-operator')],
[require('@babel/plugin-transform-object-assign')],
[require('@babel/plugin-transform-for-of'), { loose: true }],
[require('@babel/plugin-transform-for-of'), {loose: true}],
[require('@babel/plugin-transform-react-display-name')],
[require('@babel/plugin-transform-react-jsx-source')],
// used to hoist jest mocks
......@@ -121,7 +121,7 @@ module.exports = {
getCacheKey: createCacheKeyFunction([
__filename,
require.resolve('metro/src/reactNativeTransformer'),
require.resolve('metro-react-native-babel-transformer'),
require.resolve('@babel/core/package.json'),
]),
};
......@@ -40,7 +40,7 @@
"^.+\\.js$": "<rootDir>/jest/preprocessor.js"
},
"transformIgnorePatterns": [
"node_modules/(?!react-native|react-navigation)/"
"node_modules/(?!react-native|react-navigation/)"
],
"moduleNameMapper": {
"react-i18next": "<rootDir>/__mocks__/react-i18next-mock.js"
......@@ -50,6 +50,7 @@
"i18next": "^11.4.0",
"i18next-react-native-language-detector": "^1.0.2",
"metro-react-native-babel-preset": "^0.52.0",
"metro-react-native-babel-transformer": "^0.52.0",
"moment": "^2.24.0",
"prop-types": "^15.7.2",
"react": "^16.8.2",
......
......@@ -1829,7 +1829,7 @@ babel-preset-es2015-node@^6.1.1:
babel-plugin-transform-es2015-unicode-regex "6.x"
semver "5.x"
babel-preset-fbjs@^3.0.0, babel-preset-fbjs@^3.0.1:
babel-preset-fbjs@^3.0.0, babel-preset-fbjs@^3.0.1, babel-preset-fbjs@^3.1.2:
version "3.2.0"
resolved "https://registry.yarnpkg.com/babel-preset-fbjs/-/babel-preset-fbjs-3.2.0.tgz#c0e6347d3e0379ed84b3c2434d3467567aa05297"
integrity sha512-5Jo+JeWiVz2wHUUyAlvb/sSYnXNig9r+HqGAOSfh5Fzxp7SnAaR/tEGRJ1ZX7C77kfk82658w6R5Z+uPATTD9g==
......@@ -5420,6 +5420,13 @@ metro-babel-register@^0.49.1:
core-js "^2.2.2"
escape-string-regexp "^1.0.5"
metro-babel-transformer@0.52.0:
version "0.52.0"
resolved "https://registry.yarnpkg.com/metro-babel-transformer/-/metro-babel-transformer-0.52.0.tgz#9aec370b77d0246155869e7ab51880f70dfa859e"
integrity sha512-1dHTbDd73YM5MhA4CqdHOnPCRMc0fQh+jMx1aH/JTjUVfARj8d4qNAbdS2KZBTAHlwtUMChANXGpRMzEL31O0w==
dependencies:
"@babel/core" "^7.0.0"
metro-babel7-plugin-react-transform@0.49.2:
version "0.49.2"
resolved "https://registry.yarnpkg.com/metro-babel7-plugin-react-transform/-/metro-babel7-plugin-react-transform-0.49.2.tgz#d4c43faa6f2b91cc1b244a36a5d708ae8d39dbb2"
......@@ -5518,7 +5525,7 @@ metro-react-native-babel-preset@0.49.2:
metro-babel7-plugin-react-transform "0.49.2"
react-transform-hmr "^1.0.4"
metro-react-native-babel-preset@^0.52.0:
metro-react-native-babel-preset@0.52.0, metro-react-native-babel-preset@^0.52.0:
version "0.52.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.52.0.tgz#2b261d97c13cd14a617ba0d6b03e00a0b2168722"
integrity sha512-Z/bWNIexZ5k4JXUjTjhmjoOpF1Cil+eEm1PNh4TVDvO3wEE3eKajMuuJCFa/a992OSpk3wUlFwQkYl7VO6NQSg==
......@@ -5560,6 +5567,16 @@ metro-react-native-babel-preset@^0.52.0:
metro-babel7-plugin-react-transform "0.52.0"
react-transform-hmr "^1.0.4"
metro-react-native-babel-transformer@^0.52.0:
version "0.52.0"
resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.52.0.tgz#627171c33a30953ef2cfd93ed3f5643569e46652"
integrity sha512-sePE4J6SfNUsIQApG2LbFEs1hLPLfYyRzbsTk709fXF7d300EGLDQSXdaD52o1kChIIeb+jLKEQ66XalDsy8QA==
dependencies:
"@babel/core" "^7.0.0"
babel-preset-fbjs "^3.1.2"
metro-babel-transformer "0.52.0"
metro-react-native-babel-preset "0.52.0"
metro-resolver@0.49.2:
version "0.49.2"
resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.49.2.tgz#b7580d7a24fdf96170a9d4099a66b29a18e6e5f8"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment