Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

babel-preset-env

Package Overview
Dependencies
Maintainers
6
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

babel-preset-env - npm Package Compare versions

Comparing version 2.0.0-alpha.17 to 2.0.0-alpha.18

lib/available-plugins.js

15

lib/index.js

@@ -43,2 +43,6 @@ "use strict";

var _availablePlugins = require("./available-plugins");
var _availablePlugins2 = _interopRequireDefault(_availablePlugins);
var _utils = require("./utils");

@@ -136,5 +140,7 @@

var _normalizeOptions = (0, _normalizeOptions3.default)(opts),
configPath = _normalizeOptions.configPath,
debug = _normalizeOptions.debug,
optionsExclude = _normalizeOptions.exclude,
forceAllTransforms = _normalizeOptions.forceAllTransforms,
ignoreBrowserslistConfig = _normalizeOptions.ignoreBrowserslistConfig,
optionsInclude = _normalizeOptions.include,

@@ -159,3 +165,6 @@ loose = _normalizeOptions.loose,

var targets = (0, _targetsParser2.default)(optionsTargets);
var targets = (0, _targetsParser2.default)(optionsTargets, {
ignoreBrowserslistConfig,
configPath
});
var include = transformIncludesAndExcludes(optionsInclude);

@@ -176,3 +185,3 @@ var exclude = transformIncludesAndExcludes(optionsExclude);

if (modules !== false && _moduleTransformations2.default[modules]) {
plugins.push([require(`babel-plugin-${_moduleTransformations2.default[modules]}`), {
plugins.push([_availablePlugins2.default[_moduleTransformations2.default[modules]], {
loose

@@ -185,3 +194,3 @@ }]);

transformations.forEach(function (pluginName) {
return plugins.push([require(`babel-plugin-${pluginName}`), {
return plugins.push([_availablePlugins2.default[pluginName], {
spec,

@@ -188,0 +197,0 @@ loose

34

lib/normalize-options.js
"use strict";
exports.__esModule = true;
exports.validateUseBuiltInsOption = exports.validateModulesOption = exports.validateForceAllTransformsOption = exports.validateSpecOption = exports.validateLooseOption = exports.validateBoolOption = exports.checkDuplicateIncludeExcludes = exports.normalizePluginNames = exports.normalizePluginName = exports.validateIncludesAndExcludes = undefined;
exports.validateUseBuiltInsOption = exports.objectToBrowserslist = exports.validateModulesOption = exports.validateIgnoreBrowserslistConfig = exports.validateForceAllTransformsOption = exports.validateSpecOption = exports.validateLooseOption = exports.validateBoolOption = exports.validateConfigPathOption = exports.checkDuplicateIncludeExcludes = exports.normalizePluginNames = exports.normalizePluginName = exports.validateIncludesAndExcludes = undefined;
exports.default = normalizeOptions;

@@ -11,2 +11,6 @@

var _browserslist = require("browserslist");
var _browserslist2 = _interopRequireDefault(_browserslist);
var _builtIns = require("../data/built-ins.json");

@@ -46,2 +50,4 @@

var validBrowserslistTargets = [].concat(Object.keys(_browserslist2.default.data), Object.keys(_browserslist2.default.aliases));
var normalizePluginName = exports.normalizePluginName = function normalizePluginName(plugin) {

@@ -71,2 +77,11 @@ return plugin.replace(/^babel-plugin-/, "");

var validateConfigPathOption = exports.validateConfigPathOption = function validateConfigPathOption(configPath) {
if (configPath === void 0) {
configPath = process.cwd();
}
(0, _invariant2.default)(typeof configPath === "string", `Invalid Option: The configPath option '${configPath}' is invalid, only strings are allowed.`);
return configPath;
};
var validateBoolOption = exports.validateBoolOption = function validateBoolOption(name, value, defaultValue) {

@@ -96,2 +111,6 @@ if (typeof value === "undefined") {

var validateIgnoreBrowserslistConfig = exports.validateIgnoreBrowserslistConfig = function validateIgnoreBrowserslistConfig(ignoreBrowserslistConfig) {
return validateBoolOption("ignoreBrowserslistConfig", ignoreBrowserslistConfig, false);
};
var validateModulesOption = exports.validateModulesOption = function validateModulesOption(modulesOpt) {

@@ -107,2 +126,13 @@ if (modulesOpt === void 0) {

var objectToBrowserslist = exports.objectToBrowserslist = function objectToBrowserslist(object) {
return Object.keys(object).reduce(function (list, targetName) {
if (validBrowserslistTargets.indexOf(targetName) >= 0) {
var targetVersion = object[targetName];
return list.concat(`${targetName} ${targetVersion}`);
}
return list;
}, []);
};
var validateUseBuiltInsOption = exports.validateUseBuiltInsOption = function validateUseBuiltInsOption(builtInsOpt) {

@@ -131,5 +161,7 @@ if (builtInsOpt === void 0) {

return {
configPath: validateConfigPathOption(opts.configPath),
debug: opts.debug,
exclude: validateIncludesAndExcludes(opts.exclude, "exclude"),
forceAllTransforms: validateForceAllTransformsOption(opts.forceAllTransforms),
ignoreBrowserslistConfig: validateIgnoreBrowserslistConfig(opts.ignoreBrowserslistConfig),
include: validateIncludesAndExcludes(opts.include, "include"),

@@ -136,0 +168,0 @@ loose: validateLooseOption(opts.loose),

@@ -15,2 +15,4 @@ "use strict";

var _normalizeOptions = require("./normalize-options");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -36,2 +38,12 @@

var mergeBrowsers = function mergeBrowsers(fromQuery, fromTarget) {
return Object.keys(fromTarget).reduce(function (queryObj, targKey) {
if (targKey !== "browsers") {
queryObj[targKey] = fromTarget[targKey];
}
return queryObj;
}, fromQuery);
};
var getLowestVersions = function getLowestVersions(browsers) {

@@ -89,3 +101,3 @@ return browsers.reduce(function (all, browser) {

var getTargets = function getTargets(targets) {
var getTargets = function getTargets(targets, options) {
if (targets === void 0) {

@@ -95,10 +107,22 @@ targets = {};

var targetOpts = {}; // Parse browsers target via browserslist
if (options === void 0) {
options = {};
}
if (isBrowsersQueryValid(targets.browsers)) {
targetOpts = getLowestVersions((0, _browserslist2.default)(targets.browsers));
var targetOpts = {}; // Parse browsers target via browserslist;
var queryIsValid = isBrowsersQueryValid(targets.browsers);
var browsersquery = queryIsValid ? targets.browsers : null;
if (queryIsValid || !options.ignoreBrowserslistConfig) {
_browserslist2.default.defaults = (0, _normalizeOptions.objectToBrowserslist)(targets);
var browsers = (0, _browserslist2.default)(browsersquery, {
path: options.configPath
});
var queryBrowsers = getLowestVersions(browsers);
targets = mergeBrowsers(queryBrowsers, targets);
} // Parse remaining targets
var parsed = Object.keys(targets).reduce(function (results, target) {
var parsed = Object.keys(targets).sort().reduce(function (results, target) {
if (target !== "browsers") {

@@ -105,0 +129,0 @@ var value = targets[target]; // Warn when specifying minor/patch as a decimal

{
"name": "babel-preset-env",
"version": "2.0.0-alpha.17",
"version": "2.0.0-alpha.18",
"description": "A Babel preset for each environment.",

@@ -28,29 +28,29 @@ "author": "Henry Zhu <hi@henryzoo.com>",

"dependencies": {
"babel-plugin-check-es2015-constants": "7.0.0-alpha.17",
"babel-plugin-syntax-trailing-function-commas": "7.0.0-alpha.17",
"babel-plugin-transform-async-to-generator": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-arrow-functions": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-block-scoped-functions": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-block-scoping": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-classes": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-computed-properties": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-destructuring": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-duplicate-keys": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-for-of": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-function-name": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-literals": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-modules-amd": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-modules-commonjs": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-modules-systemjs": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-modules-umd": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-object-super": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-parameters": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-shorthand-properties": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-spread": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-sticky-regex": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-template-literals": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-typeof-symbol": "7.0.0-alpha.17",
"babel-plugin-transform-es2015-unicode-regex": "7.0.0-alpha.17",
"babel-plugin-transform-exponentiation-operator": "7.0.0-alpha.17",
"babel-plugin-transform-regenerator": "7.0.0-alpha.17",
"babel-plugin-check-es2015-constants": "7.0.0-alpha.18",
"babel-plugin-syntax-trailing-function-commas": "7.0.0-alpha.18",
"babel-plugin-transform-async-to-generator": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-arrow-functions": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-block-scoped-functions": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-block-scoping": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-classes": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-computed-properties": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-destructuring": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-duplicate-keys": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-for-of": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-function-name": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-literals": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-modules-amd": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-modules-commonjs": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-modules-systemjs": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-modules-umd": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-object-super": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-parameters": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-shorthand-properties": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-spread": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-sticky-regex": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-template-literals": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-typeof-symbol": "7.0.0-alpha.18",
"babel-plugin-transform-es2015-unicode-regex": "7.0.0-alpha.18",
"babel-plugin-transform-exponentiation-operator": "7.0.0-alpha.18",
"babel-plugin-transform-regenerator": "7.0.0-alpha.18",
"browserslist": "^2.1.2",

@@ -61,10 +61,10 @@ "invariant": "^2.2.2",

"devDependencies": {
"babel-cli": "7.0.0-alpha.17",
"babel-cli": "7.0.0-alpha.16",
"babel-eslint": "^7.1.1",
"babel-helper-fixtures": "7.0.0-alpha.17",
"babel-helper-plugin-test-runner": "7.0.0-alpha.17",
"babel-helper-fixtures": "7.0.0-alpha.16",
"babel-helper-plugin-test-runner": "7.0.0-alpha.16",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-transform-flow-strip-types": "7.0.0-alpha.17",
"babel-plugin-transform-flow-strip-types": "7.0.0-alpha.16",
"babel-preset-env": "2.0.0-alpha.16",
"babel-register": "7.0.0-alpha.17",
"babel-register": "7.0.0-alpha.16",
"chai": "^4.0.2",

@@ -71,0 +71,0 @@ "codecov": "^2.2.0",

@@ -63,3 +63,3 @@ # babel-preset-env [![npm](https://img.shields.io/npm/v/babel-preset-env.svg)](https://www.npmjs.com/package/babel-preset-env) [![travis](https://img.shields.io/travis/babel/babel-preset-env/master.svg)](https://travis-ci.org/babel/babel-preset-env) [![npm-downloads](https://img.shields.io/npm/dm/babel-preset-env.svg)](https://www.npmjs.com/package/babel-preset-env) [![codecov](https://img.shields.io/codecov/c/github/babel/babel-preset-env/master.svg?maxAge=43200)](https://codecov.io/github/babel/babel-preset-env)

### Support a `browsers` option like autoprefixer
### Support a `browsers` option like autoprefixer.

@@ -70,2 +70,44 @@ Use [browserslist](https://github.com/ai/browserslist) to declare supported environments by performing queries like `> 1%, last 2 versions`.

### Browserslist support.
[Browserslist](https://github.com/ai/browserslist) is a library used to share a supported list of browsers between different front-end tools like [autoprefixer](https://github.com/postcss/autoprefixer), [stylelint](https://stylelint.io/), [eslint-plugin-compat](https://github.com/amilajack/eslint-plugin-compat) and many others.
By default, babel-preset-env will use [browserslist config sources](https://github.com/ai/browserslist#queries).
For example, to enable only the polyfills and plugins needed for a project targeting *last 2 versions* and *IE10*:
**.babelrc**
```json
{
"presets": [
["env", {
"useBuiltIns": true
}]
]
}
```
**browserslist**
```
Last 2 versions
IE 10
```
or
**package.json**
```
"browserslist": "last 2 versions, ie 10"
```
Browserslist config will be ignored if: 1) `targets.browsers` was specified 2) or with `ignoreBrowserslistConfig: true` option ([see more](#ignoreBrowserslistConfig)):
#### Targets merging.
1. If [targets.browsers](#browsers) is defined - the browserslist config will be ignored. The browsers specified in `targets` will be merged with [any other explicitly defined targets](#targets). If merged, targets defined explicitly will override the same targets received from `targets.browsers`.
2. If [targets.browsers](#browsers) is _not_ defined - the program will search browserslist file or `package.json` with `browserslist` field. The search will start from the working directory of the process or from the path specified by the `configPath` option, and go up to the system root. If both a browserslist file and configuration inside a `package.json` are found, an exception will be thrown.
3. If a browserslist config was found and other targets are defined (but not [targets.browsers](#browsers)), the targets will be merged in the same way as `targets` defined explicitly with `targets.browsers`.
## Install

@@ -295,2 +337,14 @@

### `configPath`
`string`, defaults to `process.cwd()`
The starting point where the config search for browserslist will start, and ascend to the system root until found.
### `ignoreBrowserslistConfig`
`boolean`, defaults to `false`
Toggles whether or not [browserslist config sources](https://github.com/ai/browserslist#queries) are used, which includes searching for any browserslist files or referencing the browserslist key inside package.json. This is useful for projects that use a browserslist config for files that won't be compiled with Babel.
---

@@ -297,0 +351,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc