From 028c4eaffb19514ed63de723d2320cdc1abd05d1 Mon Sep 17 00:00:00 2001 From: Artem Yavorsky Date: Tue, 10 Jan 2017 19:03:07 +0200 Subject: [PATCH] Transformations before logs (#128) --- src/index.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 857f3cd5..27bb4134 100644 --- a/src/index.js +++ b/src/index.js @@ -228,6 +228,15 @@ const logPlugin = (plugin, targets, list) => { console.log(logStr); }; +const filterItem = (targets, exclusions, list, item) => { + const isDefault = defaultInclude.indexOf(item) >= 0; + const notExcluded = exclusions.indexOf(item) === -1; + + if (isDefault) return notExcluded; + const isRequired = isPluginRequired(targets, list[item]); + return isRequired && notExcluded; +}; + export default function buildPreset(context, opts = {}) { const loose = validateLooseOption(opts.loose); const moduleType = validateModulesOption(opts.modules); @@ -244,15 +253,18 @@ export default function buildPreset(context, opts = {}) { const debug = opts.debug; const useBuiltIns = opts.useBuiltIns; + const filterPlugins = filterItem.bind(null, targets, exclude.plugins, pluginList); let transformations = Object.keys(pluginList) - .filter((pluginName) => isPluginRequired(targets, pluginList[pluginName])); + .filter(filterPlugins) + .concat(include.plugins); let polyfills; if (useBuiltIns) { + const filterBuiltIns = filterItem.bind(null, targets, exclude.builtIns, builtInsList); + polyfills = Object.keys(builtInsList) - .filter((builtInName) => isPluginRequired(targets, builtInsList[builtInName])) .concat(defaultInclude) - .filter((plugin) => exclude.builtIns.indexOf(plugin) === -1) + .filter(filterBuiltIns) .concat(include.builtIns); } @@ -266,26 +278,22 @@ export default function buildPreset(context, opts = {}) { transformations.forEach((transform) => { logPlugin(transform, targets, pluginList); }); - console.log("\nUsing polyfills:"); if (useBuiltIns && polyfills.length) { + console.log("\nUsing polyfills:"); polyfills.forEach((polyfill) => { logPlugin(polyfill, targets, builtInsList); }); } } - const allTransformations = transformations - .filter((plugin) => exclude.plugins.indexOf(plugin) === -1) - .concat(include.plugins); - - const regenerator = allTransformations.indexOf("transform-regenerator") >= 0; + const regenerator = transformations.indexOf("transform-regenerator") >= 0; const modulePlugin = moduleType !== false && MODULE_TRANSFORMATIONS[moduleType]; const plugins = []; modulePlugin && plugins.push([require(`babel-plugin-${modulePlugin}`), { loose }]); - plugins.push(...allTransformations.map((pluginName) => + plugins.push(...transformations.map((pluginName) => [require(`babel-plugin-${pluginName}`), { loose }] ));