From 2da1cc508e4c3b4fefb52cab2bba4b56b457e743 Mon Sep 17 00:00:00 2001 From: Boopathi Rajaa Date: Mon, 29 Aug 2016 21:59:47 +0200 Subject: [PATCH] Throw upgrade error when babel version is less than 6.14.0 (#116) * Throw upgrade error when babel version is less than 6.14.0 + (Close #70) + related #114 * Update error message * Simplify --- packages/babel-preset-babili/src/index.js | 66 ++++++++++++++++------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/packages/babel-preset-babili/src/index.js b/packages/babel-preset-babili/src/index.js index 7419328e8..a812457fa 100644 --- a/packages/babel-preset-babili/src/index.js +++ b/packages/babel-preset-babili/src/index.js @@ -1,20 +1,50 @@ +const err = new Error("Babili requires babel-core>=6.14.0. Upgrade babel-core or tools dependent on babel-core to recent versions"); + +function isVersion(versionStr) { + const version = versionStr.split(".").map((p) => parseInt(p)); + return version[0] >= 6 && version[1] >= 14; +} + module.exports = { - minified: true, - plugins: [ - require("babel-plugin-minify-constant-folding"), - require("babel-plugin-minify-dead-code-elimination"), - require("babel-plugin-minify-flip-comparisons"), - require("babel-plugin-minify-guarded-expressions"), - require("babel-plugin-minify-infinity"), - require("babel-plugin-minify-mangle-names"), - require("babel-plugin-minify-replace"), - require("babel-plugin-minify-simplify"), - require("babel-plugin-minify-type-constructors"), - require("babel-plugin-transform-member-expression-literals"), - require("babel-plugin-transform-merge-sibling-variables"), - require("babel-plugin-transform-minify-booleans"), - require("babel-plugin-transform-property-literals"), - require("babel-plugin-transform-simplify-comparison-operators"), - require("babel-plugin-transform-undefined-to-void"), - ], + plugins: [function({version}) { + if (!isVersion(version)) { + throw err; + } + return { + visitor: {} + }; + }], }; + +Object.defineProperty(module.exports, "buildPreset", { + configurable: true, + writable: true, + enumerable: false, + value: preset +}); + +function preset(context) { + if (!isVersion(context.version)) { + throw err; + } + return { + minified: true, + plugins: [ + require("babel-plugin-minify-constant-folding"), + require("babel-plugin-minify-dead-code-elimination"), + require("babel-plugin-minify-flip-comparisons"), + require("babel-plugin-minify-guarded-expressions"), + require("babel-plugin-minify-infinity"), + require("babel-plugin-minify-mangle-names"), + require("babel-plugin-minify-replace"), + require("babel-plugin-minify-simplify"), + require("babel-plugin-minify-type-constructors"), + require("babel-plugin-transform-member-expression-literals"), + require("babel-plugin-transform-merge-sibling-variables"), + require("babel-plugin-transform-minify-booleans"), + require("babel-plugin-transform-property-literals"), + require("babel-plugin-transform-simplify-comparison-operators"), + require("babel-plugin-transform-undefined-to-void"), + ], + }; +}