|
3 | 3 | *
|
4 | 4 | * This source code is licensed under the MIT license found in the
|
5 | 5 | * LICENSE file in the root directory of this source tree.
|
| 6 | + * |
| 7 | + * @format |
6 | 8 | */
|
7 | 9 | 'use strict';
|
8 | 10 |
|
|
12 | 14 | * the file it's compiling. This makes sure that we're using the plugins
|
13 | 15 | * installed in the react-native package.
|
14 | 16 | */
|
15 |
| -function resolvePlugins(plugins) { |
16 |
| - return plugins.map(resolvePlugin); |
| 17 | +function resolvePlugins(plugins, prefix) { |
| 18 | + return plugins.map(plugin => resolvePlugin(plugin, prefix)); |
17 | 19 | }
|
18 | 20 |
|
19 | 21 | /**
|
20 | 22 | * Manually resolve a single Babel plugin.
|
21 | 23 | */
|
22 |
| -function resolvePlugin(plugin) { |
| 24 | +function resolvePlugin(plugin, prefix = 'babel-plugin-') { |
23 | 25 | // Normalise plugin to an array.
|
24 | 26 | if (!Array.isArray(plugin)) {
|
25 | 27 | plugin = [plugin];
|
26 | 28 | }
|
27 | 29 | // Only resolve the plugin if it's a string reference.
|
28 | 30 | if (typeof plugin[0] === 'string') {
|
29 |
| - plugin[0] = require('babel-plugin-' + plugin[0]); |
| 31 | + plugin[0] = require(prefix + plugin[0]); |
30 | 32 | plugin[0] = plugin[0].__esModule ? plugin[0].default : plugin[0];
|
31 | 33 | }
|
32 | 34 | return plugin;
|
33 | 35 | }
|
34 | 36 |
|
35 | 37 | module.exports = resolvePlugins;
|
36 | 38 | module.exports.resolvePlugin = resolvePlugin;
|
| 39 | +module.exports.resolvePluginAs = (prefix, plugin) => |
| 40 | + resolvePlugin(plugin, prefix); |
| 41 | +module.exports.resolvePluginsAs = (prefix, plugins) => |
| 42 | + resolvePlugins(plugins, prefix); |
0 commit comments