diff --git a/packages/metro/src/babel-bridge.js b/packages/metro/src/babel-bridge.js index f4c4d361..1b5dae10 100644 --- a/packages/metro/src/babel-bridge.js +++ b/packages/metro/src/babel-bridge.js @@ -14,38 +14,9 @@ // This is a temporary migration bridge to switch between babel 6 and 7 const makeHMRConfig7 = makeMakeHMRConfig7(); -function resolvePlugins7(plugins: Array) { - /** - * from: babel-preset-react-native/lib/resolvePlugins - * "Ported" to Babel 7 - * - * Manually resolve all default Babel plugins. - * `babel.transform` will attempt to resolve all base plugins relative to - * the file it's compiling. This makes sure that we're using the plugins - * installed in the react-native package. - */ - type ModuleES6 = {__esModule?: boolean, default?: {}}; - /* $FlowFixMe(>=0.70.0 site=react_native_fb) This comment suppresses an - * error found when Flow v0.70 was deployed. To see the error delete this - * comment and run Flow. */ - return plugins.map(plugin => { - // Normalise plugin to an array. - plugin = Array.isArray(plugin) ? plugin : [plugin]; - // Only resolve the plugin if it's a string reference. - if (typeof plugin[0] === 'string') { - // $FlowFixMe TODO t26372934 plugin require - const required: ModuleES6 | {} = require('@babel/plugin-' + plugin[0]); - // es6 import default? - // $FlowFixMe should properly type this plugin structure - plugin[0] = required.__esModule ? required.default : required; - } - return plugin; - }); -} module.exports = { makeHMRConfig: makeHMRConfig7, - resolvePlugins: resolvePlugins7, getPreset, }; diff --git a/packages/metro/src/transformer.js b/packages/metro/src/transformer.js index 1475ef2b..910f1a99 100644 --- a/packages/metro/src/transformer.js +++ b/packages/metro/src/transformer.js @@ -20,12 +20,13 @@ const path = require('path'); const {getPreset} = require('./babel-bridge'); const {makeHMRConfig} = require('./babel-bridge'); -const {resolvePlugins} = require('./babel-bridge'); const {transformSync} = require('@babel/core'); import type {Transformer, TransformOptions} from './JSTransformer/worker'; import type {Plugins as BabelPlugins} from 'babel-core'; +type ModuleES6 = {__esModule?: boolean, default?: {}}; + const cacheKeyParts = [ fs.readFileSync(__filename), require('babel-plugin-external-helpers/package.json').version, @@ -65,7 +66,24 @@ const getBabelRC = (function() { // Require the babel-preset's listed in the default babel config babelRC.presets = babelRC.presets.map(getPreset); - babelRC.plugins = resolvePlugins(babelRC.plugins); + babelRC.plugins = babelRC.plugins.map(plugin => { + // Manually resolve all default Babel plugins. + // `babel.transform` will attempt to resolve all base plugins relative to + // the file it's compiling. This makes sure that we're using the plugins + // installed in the react-native package. + + // Normalise plugin to an array. + plugin = Array.isArray(plugin) ? plugin : [plugin]; + // Only resolve the plugin if it's a string reference. + if (typeof plugin[0] === 'string') { + // $FlowFixMe TODO t26372934 plugin require + const required: ModuleES6 | {} = require('@babel/plugin-' + + plugin[0]); + // es6 import default? + // $FlowFixMe should properly type this plugin structure + plugin[0] = required.__esModule ? required.default : required; + } + }); } else { // if we find a .babelrc file we tell babel to use it babelRC.extends = projectBabelRCPath;