Move the getBabelRegisterConfig function to the one file that uses it

Reviewed By: rubennorte

Differential Revision: D7788532

fbshipit-source-id: 1d08d159574247366492c036f5c530c982ec67b3
This commit is contained in:
Peter van der Zee 2018-04-30 04:00:51 -07:00 committed by Facebook Github Bot
parent 86e1a086aa
commit f64ed1369e
2 changed files with 48 additions and 51 deletions

View File

@ -47,8 +47,6 @@ function resolvePlugins7(plugins: Array<any>) {
}
module.exports = {
getBabelRegisterConfig: getBabelRegisterConfig7,
externalHelpersPlugin: externalHelpersPlugin7,
inlineRequiresPlugin: inlineRequiresPlugin7,
makeHMRConfig: makeHMRConfig7,
@ -112,51 +110,3 @@ function getPreset(name: string) {
//$FlowFixMe: TODO t26372934 this has to be dynamic
return require(name);
}
function getBabelRegisterConfig7() {
// from: metro/packages/metro-babel-register/babel-register.js
// (dont use babel-register anymore, it obsoleted with babel 7)
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
require('metro-babel-register/src/node-polyfills');
var _only = [];
const PLUGINS = [
'transform-flow-strip-types',
'proposal-object-rest-spread',
'proposal-class-properties',
];
function config(onlyList: Array<string>) {
/* $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. */
_only = _only.concat(onlyList);
return {
presets: [],
/* $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. */
plugins: PLUGINS.map(pluginName =>
// $FlowFixMe TODO t26372934 plugin require
require(`@babel/plugin-${pluginName}`),
),
only: _only,
retainLines: true,
sourceMaps: 'inline',
babelrc: false,
};
}
return config;
}

View File

@ -14,11 +14,58 @@
const fs = require('fs');
const {getBabelRegisterConfig} = require('../../../babel-bridge');
const {transformSync} = require('@babel/core');
const babelConfig = getBabelRegisterConfig();
function getBabelRegisterConfig() {
// from: metro/packages/metro-babel-register/babel-register.js
// (dont use babel-register anymore, it obsoleted with babel 7)
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
require('metro-babel-register/src/node-polyfills');
var _only = [];
const PLUGINS = [
'transform-flow-strip-types',
'proposal-object-rest-spread',
'proposal-class-properties',
];
function config(onlyList: Array<string>) {
/* $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. */
_only = _only.concat(onlyList);
return {
presets: [],
/* $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. */
plugins: PLUGINS.map(pluginName =>
// $FlowFixMe TODO t26372934 plugin require
require(`@babel/plugin-${pluginName}`),
),
only: _only,
retainLines: true,
sourceMaps: 'inline',
babelrc: false,
};
}
return config;
}
describe('require', () => {
const moduleSystemCode = (() => {
const {only, ...config} = babelConfig([]);