Skip to content

Commit 2dc559d

Browse files
Peter van der Zeefacebook-github-bot
Peter van der Zee
authored andcommitted
Add possibility to add custom plugin prefix
Summary: The problem with a fixed prefix is that babel 7 uses a scoped packages and every (standard) plugin is now part of that scope so the prefix is no longer `babel-plugin-` but instead `babel/plugin-`. There are more changes. This one will at least fix most of them. Reviewed By: davidaurelio Differential Revision: D7085102 fbshipit-source-id: b927998c611b71b3265e1cb3f6df537b14f9cb25
1 parent 6c353fd commit 2dc559d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

Diff for: babel-preset/lib/resolvePlugins.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
*
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
68
*/
79
'use strict';
810

@@ -12,25 +14,29 @@
1214
* the file it's compiling. This makes sure that we're using the plugins
1315
* installed in the react-native package.
1416
*/
15-
function resolvePlugins(plugins) {
16-
return plugins.map(resolvePlugin);
17+
function resolvePlugins(plugins, prefix) {
18+
return plugins.map(plugin => resolvePlugin(plugin, prefix));
1719
}
1820

1921
/**
2022
* Manually resolve a single Babel plugin.
2123
*/
22-
function resolvePlugin(plugin) {
24+
function resolvePlugin(plugin, prefix = 'babel-plugin-') {
2325
// Normalise plugin to an array.
2426
if (!Array.isArray(plugin)) {
2527
plugin = [plugin];
2628
}
2729
// Only resolve the plugin if it's a string reference.
2830
if (typeof plugin[0] === 'string') {
29-
plugin[0] = require('babel-plugin-' + plugin[0]);
31+
plugin[0] = require(prefix + plugin[0]);
3032
plugin[0] = plugin[0].__esModule ? plugin[0].default : plugin[0];
3133
}
3234
return plugin;
3335
}
3436

3537
module.exports = resolvePlugins;
3638
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

Comments
 (0)