2016-01-15 03:32:17 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-02-27 21:14:34 +00:00
|
|
|
*
|
|
|
|
* @format
|
2016-01-15 03:32:17 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-02-27 21:14:34 +00:00
|
|
|
function resolvePlugins(plugins, prefix) {
|
|
|
|
return plugins.map(plugin => resolvePlugin(plugin, prefix));
|
2018-01-25 10:33:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Manually resolve a single Babel plugin.
|
|
|
|
*/
|
2018-02-27 21:14:34 +00:00
|
|
|
function resolvePlugin(plugin, prefix = 'babel-plugin-') {
|
2018-01-25 10:33:21 +00:00
|
|
|
// Normalise plugin to an array.
|
|
|
|
if (!Array.isArray(plugin)) {
|
|
|
|
plugin = [plugin];
|
|
|
|
}
|
|
|
|
// Only resolve the plugin if it's a string reference.
|
|
|
|
if (typeof plugin[0] === 'string') {
|
2018-02-27 21:14:34 +00:00
|
|
|
plugin[0] = require(prefix + plugin[0]);
|
2018-01-25 10:33:21 +00:00
|
|
|
plugin[0] = plugin[0].__esModule ? plugin[0].default : plugin[0];
|
|
|
|
}
|
|
|
|
return plugin;
|
2016-01-15 03:32:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = resolvePlugins;
|
2018-01-25 10:33:21 +00:00
|
|
|
module.exports.resolvePlugin = resolvePlugin;
|
2018-02-27 21:14:34 +00:00
|
|
|
module.exports.resolvePluginAs = (prefix, plugin) =>
|
|
|
|
resolvePlugin(plugin, prefix);
|
|
|
|
module.exports.resolvePluginsAs = (prefix, plugins) =>
|
|
|
|
resolvePlugins(plugins, prefix);
|