postcss-merge-rules
Advanced tools
Comparing version 2.0.11 to 2.1.0
@@ -0,1 +1,10 @@ | ||
# 2.1.0 | ||
* Rules are now merged based on supported browsers, which uses `browserslist` | ||
& `caniuse-api`. The browsers should be supplied by the standard means of | ||
[configuring `browserslist`][browserslist], either using config files or | ||
via environment variables. | ||
[browserslist]: https://github.com/ai/browserslist#config-file | ||
# 2.0.11 | ||
@@ -2,0 +11,0 @@ |
@@ -7,2 +7,6 @@ 'use strict'; | ||
var _browserslist = require('browserslist'); | ||
var _browserslist2 = _interopRequireDefault(_browserslist); | ||
var _postcss = require('postcss'); | ||
@@ -20,6 +24,8 @@ | ||
var _ensureCompatibility = require('./lib/ensureCompatibility'); | ||
var _ensureCompatibility2 = _interopRequireDefault(_ensureCompatibility); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var list = _postcss2.default.list; | ||
var prefixes = _vendors2.default.map(function (v) { | ||
@@ -64,6 +70,12 @@ return '-' + v + '-'; | ||
function canMerge(ruleA, ruleB) { | ||
var a = list.comma(ruleA.selector); | ||
var b = list.comma(ruleB.selector); | ||
function canMerge(ruleA, ruleB, browsers) { | ||
var a = ruleA.selectors; | ||
var b = ruleB.selectors; | ||
var selectors = a.concat(b); | ||
if (!(0, _ensureCompatibility2.default)(selectors, browsers)) { | ||
return false; | ||
} | ||
var parent = sameParent(ruleA, ruleB); | ||
@@ -75,3 +87,3 @@ var name = ruleA.parent.name; | ||
} | ||
return parent && (a.concat(b).every(noVendor) || sameVendor(a, b)); | ||
return parent && (selectors.every(noVendor) || sameVendor(a, b)); | ||
} | ||
@@ -209,3 +221,3 @@ | ||
function selectorMerger() { | ||
function selectorMerger(browsers) { | ||
var cache = null; | ||
@@ -215,3 +227,3 @@ return function (rule) { | ||
// safe to merge both declarations before continuing | ||
if (!cache || !canMerge(rule, cache)) { | ||
if (!cache || !canMerge(rule, cache, browsers)) { | ||
cache = rule; | ||
@@ -260,6 +272,13 @@ return; | ||
exports.default = _postcss2.default.plugin('postcss-merge-rules', function () { | ||
return function (css) { | ||
return css.walkRules(selectorMerger()); | ||
return function (css, result) { | ||
var opts = result.opts; | ||
var browsers = (0, _browserslist2.default)(null, { | ||
stats: opts && opts.stats, | ||
path: opts && opts.from, | ||
env: opts && opts.env | ||
}); | ||
css.walkRules(selectorMerger(browsers)); | ||
}; | ||
}); | ||
module.exports = exports['default']; |
{ | ||
"name": "postcss-merge-rules", | ||
"version": "2.0.11", | ||
"version": "2.1.0", | ||
"description": "Merge CSS rules with PostCSS.", | ||
@@ -34,2 +34,3 @@ "main": "dist/index.js", | ||
"babel-register": "^6.9.0", | ||
"browserslist": "^1.5.2", | ||
"cross-env": "^2.0.1", | ||
@@ -53,3 +54,5 @@ "del-cli": "^0.2.0", | ||
"dependencies": { | ||
"caniuse-api": "^1.5.2", | ||
"postcss": "^5.0.4", | ||
"postcss-selector-parser": "^2.2.2", | ||
"vendors": "^1.0.0" | ||
@@ -66,3 +69,17 @@ }, | ||
"instrument": false | ||
}, | ||
"browserslist": { | ||
"chrome58": [ | ||
"Chrome 58" | ||
], | ||
"edge15": [ | ||
"Edge 15" | ||
], | ||
"ie6": [ | ||
"IE 6" | ||
], | ||
"ie7": [ | ||
"IE 7" | ||
] | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22459
7
380
4
19
+ Addedcaniuse-api@^1.5.2
+ Addedbrowserslist@1.7.7(transitive)
+ Addedcaniuse-api@1.6.1(transitive)
+ Addedcaniuse-db@1.0.30001680(transitive)
+ Addedelectron-to-chromium@1.5.62(transitive)
+ Addedflatten@1.0.3(transitive)
+ Addedindexes-of@1.0.1(transitive)
+ Addedlodash.memoize@4.1.2(transitive)
+ Addedlodash.uniq@4.5.0(transitive)
+ Addedpostcss-selector-parser@2.2.3(transitive)
+ Addeduniq@1.0.1(transitive)