mirror of https://github.com/status-im/metro.git
Stop pulling resolvePlugins from babel-bridge
Reviewed By: mjesun Differential Revision: D7788851 fbshipit-source-id: 8b2a5f9927a434042b1c0a8f27e40acfe2600820
This commit is contained in:
parent
e4198ec268
commit
cfbb4377f3
|
@ -14,38 +14,9 @@
|
||||||
// This is a temporary migration bridge to switch between babel 6 and 7
|
// This is a temporary migration bridge to switch between babel 6 and 7
|
||||||
|
|
||||||
const makeHMRConfig7 = makeMakeHMRConfig7();
|
const makeHMRConfig7 = makeMakeHMRConfig7();
|
||||||
function resolvePlugins7(plugins: Array<any>) {
|
|
||||||
/**
|
|
||||||
* 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 = {
|
module.exports = {
|
||||||
makeHMRConfig: makeHMRConfig7,
|
makeHMRConfig: makeHMRConfig7,
|
||||||
resolvePlugins: resolvePlugins7,
|
|
||||||
getPreset,
|
getPreset,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -20,12 +20,13 @@ const path = require('path');
|
||||||
|
|
||||||
const {getPreset} = require('./babel-bridge');
|
const {getPreset} = require('./babel-bridge');
|
||||||
const {makeHMRConfig} = require('./babel-bridge');
|
const {makeHMRConfig} = require('./babel-bridge');
|
||||||
const {resolvePlugins} = require('./babel-bridge');
|
|
||||||
const {transformSync} = require('@babel/core');
|
const {transformSync} = require('@babel/core');
|
||||||
|
|
||||||
import type {Transformer, TransformOptions} from './JSTransformer/worker';
|
import type {Transformer, TransformOptions} from './JSTransformer/worker';
|
||||||
import type {Plugins as BabelPlugins} from 'babel-core';
|
import type {Plugins as BabelPlugins} from 'babel-core';
|
||||||
|
|
||||||
|
type ModuleES6 = {__esModule?: boolean, default?: {}};
|
||||||
|
|
||||||
const cacheKeyParts = [
|
const cacheKeyParts = [
|
||||||
fs.readFileSync(__filename),
|
fs.readFileSync(__filename),
|
||||||
require('babel-plugin-external-helpers/package.json').version,
|
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
|
// Require the babel-preset's listed in the default babel config
|
||||||
babelRC.presets = babelRC.presets.map(getPreset);
|
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 {
|
} else {
|
||||||
// if we find a .babelrc file we tell babel to use it
|
// if we find a .babelrc file we tell babel to use it
|
||||||
babelRC.extends = projectBabelRCPath;
|
babelRC.extends = projectBabelRCPath;
|
||||||
|
|
Loading…
Reference in New Issue