mirror of
https://github.com/status-im/metro.git
synced 2025-02-10 18:17:12 +00:00
Refactor the babel config generator function to what it actually does
Reviewed By: rubennorte Differential Revision: D7788527 fbshipit-source-id: 4daed4d75b44b9c55a676881982cdab0034a27cc
This commit is contained in:
parent
7ab8d08f89
commit
dfc30f0352
@ -12,64 +12,33 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
require('metro-babel-register/src/node-polyfills');
|
||||||
|
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
const {transformSync} = require('@babel/core');
|
const {transformSync} = require('@babel/core');
|
||||||
|
|
||||||
const babelConfig = getBabelRegisterConfig();
|
// from: metro/packages/metro-babel-register/babel-register.js
|
||||||
|
|
||||||
function getBabelRegisterConfig() {
|
const PLUGINS = [
|
||||||
// from: metro/packages/metro-babel-register/babel-register.js
|
'@babel/plugin-transform-flow-strip-types',
|
||||||
// (dont use babel-register anymore, it obsoleted with babel 7)
|
'@babel/plugin-proposal-object-rest-spread',
|
||||||
|
'@babel/plugin-proposal-class-properties',
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
function createBabelConfig() {
|
||||||
* Copyright (c) 2015-present, Facebook, Inc.
|
return {
|
||||||
*
|
presets: [],
|
||||||
* This source code is licensed under the MIT license found in the
|
plugins: PLUGINS.map(require),
|
||||||
* LICENSE file in the root directory of this source tree.
|
retainLines: true,
|
||||||
*
|
sourceMaps: 'inline',
|
||||||
* @format
|
babelrc: false,
|
||||||
*/
|
};
|
||||||
'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', () => {
|
describe('require', () => {
|
||||||
const moduleSystemCode = (() => {
|
const moduleSystemCode = (() => {
|
||||||
const {only, ...config} = babelConfig([]);
|
const config = createBabelConfig();
|
||||||
only;
|
|
||||||
const rawCode = fs.readFileSync(require.resolve('../require'), 'utf8');
|
const rawCode = fs.readFileSync(require.resolve('../require'), 'utf8');
|
||||||
return transformSync(rawCode, config).code;
|
return transformSync(rawCode, config).code;
|
||||||
})();
|
})();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user