From f64ed1369edc514c18f7bb1b6e2807f8daea7281 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Mon, 30 Apr 2018 04:00:51 -0700 Subject: [PATCH] Move the getBabelRegisterConfig function to the one file that uses it Reviewed By: rubennorte Differential Revision: D7788532 fbshipit-source-id: 1d08d159574247366492c036f5c530c982ec67b3 --- packages/metro/src/babel-bridge.js | 50 ------------------- .../lib/polyfills/__tests__/require-test.js | 49 +++++++++++++++++- 2 files changed, 48 insertions(+), 51 deletions(-) diff --git a/packages/metro/src/babel-bridge.js b/packages/metro/src/babel-bridge.js index e6781e8c..04d83b6b 100644 --- a/packages/metro/src/babel-bridge.js +++ b/packages/metro/src/babel-bridge.js @@ -47,8 +47,6 @@ function resolvePlugins7(plugins: Array) { } 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) { - /* $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; -} diff --git a/packages/metro/src/lib/polyfills/__tests__/require-test.js b/packages/metro/src/lib/polyfills/__tests__/require-test.js index fca0f82a..c2f3e179 100644 --- a/packages/metro/src/lib/polyfills/__tests__/require-test.js +++ b/packages/metro/src/lib/polyfills/__tests__/require-test.js @@ -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) { + /* $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([]);