Stop pulling getPreset from babel-bridge

Reviewed By: mjesun

Differential Revision: D7788849

fbshipit-source-id: 8db2b69f7d82b9feb9d339dc40363ba25c49d0ee
This commit is contained in:
Peter van der Zee 2018-05-02 10:06:50 -07:00 committed by Facebook Github Bot
parent cfbb4377f3
commit 6ddbbfbae1
2 changed files with 15 additions and 17 deletions

View File

@ -17,7 +17,6 @@ const makeHMRConfig7 = makeMakeHMRConfig7();
module.exports = { module.exports = {
makeHMRConfig: makeHMRConfig7, makeHMRConfig: makeHMRConfig7,
getPreset,
}; };
function makeMakeHMRConfig7() { function makeMakeHMRConfig7() {
@ -62,17 +61,3 @@ function makeMakeHMRConfig7() {
}; };
}; };
} }
function getPreset(name: string) {
if (!/^(?:@babel\/|babel-)preset-/.test(name)) {
try {
name = require.resolve(`babel-preset-${name}`);
} catch (error) {
if (error && error.conde === 'MODULE_NOT_FOUND') {
name = require.resolve(`@babel/preset-${name}`);
}
}
}
//$FlowFixMe: TODO t26372934 this has to be dynamic
return require(name);
}

View File

@ -18,7 +18,6 @@ const inlineRequiresPlugin = require('babel-preset-fbjs/plugins/inline-requires'
const json5 = require('json5'); const json5 = require('json5');
const path = require('path'); const path = require('path');
const {getPreset} = require('./babel-bridge');
const {makeHMRConfig} = require('./babel-bridge'); const {makeHMRConfig} = require('./babel-bridge');
const {transformSync} = require('@babel/core'); const {transformSync} = require('@babel/core');
@ -65,7 +64,21 @@ 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((name: string) => {
if (!/^(?:@babel\/|babel-)preset-/.test(name)) {
try {
name = require.resolve(`babel-preset-${name}`);
} catch (error) {
if (error && error.conde === 'MODULE_NOT_FOUND') {
name = require.resolve(`@babel/preset-${name}`);
} else {
throw new Error(error);
}
}
}
//$FlowFixMe: TODO t26372934 this has to be dynamic
return require(name);
});
babelRC.plugins = babelRC.plugins.map(plugin => { babelRC.plugins = babelRC.plugins.map(plugin => {
// Manually resolve all default Babel plugins. // Manually resolve all default Babel plugins.
// `babel.transform` will attempt to resolve all base plugins relative to // `babel.transform` will attempt to resolve all base plugins relative to