postcss-discard-unused
Advanced tools
Comparing version 4.0.0-nightly.2020.1.9 to 4.0.0-nightly.2020.1.11
@@ -8,6 +8,2 @@ "use strict"; | ||
var _uniqs = _interopRequireDefault(require("uniqs")); | ||
var _postcss = require("postcss"); | ||
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser")); | ||
@@ -17,6 +13,2 @@ | ||
const { | ||
comma, | ||
space | ||
} = _postcss.list; | ||
const atrule = 'atrule'; | ||
@@ -26,5 +18,11 @@ const decl = 'decl'; | ||
function uniqs(items) { | ||
return items.filter(function (item, i) { | ||
return i === items.indexOf(item); | ||
}); | ||
} | ||
function addValues(cache, { | ||
value | ||
}) { | ||
}, comma, space) { | ||
return comma(value).reduce((memo, val) => [...memo, ...space(val)], cache); | ||
@@ -37,3 +35,3 @@ } | ||
}) { | ||
values = (0, _uniqs.default)(values); | ||
values = uniqs(values); | ||
atRules.forEach(node => { | ||
@@ -52,3 +50,3 @@ const hasAtRule = values.some(value => value === node.params); | ||
}) { | ||
rules = (0, _uniqs.default)(rules); | ||
rules = uniqs(rules); | ||
atRules.forEach(atRule => { | ||
@@ -72,3 +70,3 @@ const { | ||
function hasFont(fontFamily, cache) { | ||
function hasFont(fontFamily, cache, comma) { | ||
return comma(fontFamily).some(font => cache.some(c => ~c.indexOf(font))); | ||
@@ -81,4 +79,4 @@ } // fonts have slightly different logic | ||
values | ||
}) { | ||
values = (0, _uniqs.default)(values); | ||
}, comma) { | ||
values = uniqs(values); | ||
atRules.forEach(r => { | ||
@@ -94,3 +92,3 @@ const families = r.nodes.filter(({ | ||
families.forEach(family => { | ||
if (!hasFont(family.value.toLowerCase(), values)) { | ||
if (!hasFont(family.value.toLowerCase(), values, comma)) { | ||
r.remove(); | ||
@@ -102,3 +100,3 @@ } | ||
var _default = (0, _postcss.plugin)('postcss-discard-unused', opts => { | ||
function pluginCreator(opts) { | ||
const { | ||
@@ -115,89 +113,107 @@ fontFace, | ||
}, opts); | ||
return css => { | ||
const counterStyleCache = { | ||
atRules: [], | ||
values: [] | ||
}; | ||
const keyframesCache = { | ||
atRules: [], | ||
values: [] | ||
}; | ||
const namespaceCache = { | ||
atRules: [], | ||
rules: [] | ||
}; | ||
const fontCache = { | ||
atRules: [], | ||
values: [] | ||
}; | ||
css.walk(node => { | ||
const { | ||
type, | ||
prop, | ||
selector, | ||
name | ||
} = node; | ||
return { | ||
postcssPlugin: 'postcss-discard-unused', | ||
if (type === rule && namespace && ~selector.indexOf('|')) { | ||
if (~selector.indexOf('[')) { | ||
// Attribute selector, so we should parse further. | ||
(0, _postcssSelectorParser.default)(ast => { | ||
ast.walkAttributes(({ | ||
namespace: ns | ||
}) => { | ||
namespaceCache.rules = namespaceCache.rules.concat(ns); | ||
}); | ||
}).process(selector); | ||
} else { | ||
// Use a simple split function for the namespace | ||
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]); | ||
} | ||
prepare() { | ||
const counterStyleCache = { | ||
atRules: [], | ||
values: [] | ||
}; | ||
const keyframesCache = { | ||
atRules: [], | ||
values: [] | ||
}; | ||
const namespaceCache = { | ||
atRules: [], | ||
rules: [] | ||
}; | ||
const fontCache = { | ||
atRules: [], | ||
values: [] | ||
}; | ||
return { | ||
OnceExit(css, { | ||
list | ||
}) { | ||
const { | ||
comma, | ||
space | ||
} = list; | ||
css.walk(node => { | ||
const { | ||
type, | ||
prop, | ||
selector, | ||
name | ||
} = node; | ||
return; | ||
} | ||
if (type === rule && namespace && ~selector.indexOf('|')) { | ||
if (~selector.indexOf('[')) { | ||
// Attribute selector, so we should parse further. | ||
(0, _postcssSelectorParser.default)(ast => { | ||
ast.walkAttributes(({ | ||
namespace: ns | ||
}) => { | ||
namespaceCache.rules = namespaceCache.rules.concat(ns); | ||
}); | ||
}).process(selector); | ||
} else { | ||
// Use a simple split function for the namespace | ||
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]); | ||
} | ||
if (type === decl) { | ||
if (counterStyle && /list-style|system/.test(prop)) { | ||
counterStyleCache.values = addValues(counterStyleCache.values, node); | ||
} | ||
return; | ||
} | ||
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) { | ||
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase())); | ||
} | ||
if (type === decl) { | ||
if (counterStyle && /list-style|system/.test(prop)) { | ||
counterStyleCache.values = addValues(counterStyleCache.values, node, comma, space); | ||
} | ||
if (keyframes && /animation/.test(prop)) { | ||
keyframesCache.values = addValues(keyframesCache.values, node); | ||
} | ||
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) { | ||
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase())); | ||
} | ||
return; | ||
} | ||
if (keyframes && /animation/.test(prop)) { | ||
keyframesCache.values = addValues(keyframesCache.values, node, comma, space); | ||
} | ||
if (type === atrule) { | ||
if (counterStyle && /counter-style/.test(name)) { | ||
counterStyleCache.atRules.push(node); | ||
} | ||
return; | ||
} | ||
if (fontFace && name === 'font-face' && node.nodes) { | ||
fontCache.atRules.push(node); | ||
} | ||
if (type === atrule) { | ||
if (counterStyle && /counter-style/.test(name)) { | ||
counterStyleCache.atRules.push(node); | ||
} | ||
if (keyframes && /keyframes/.test(name)) { | ||
keyframesCache.atRules.push(node); | ||
} | ||
if (fontFace && name === 'font-face' && node.nodes) { | ||
fontCache.atRules.push(node); | ||
} | ||
if (namespace && name === 'namespace') { | ||
namespaceCache.atRules.push(node); | ||
if (keyframes && /keyframes/.test(name)) { | ||
keyframesCache.atRules.push(node); | ||
} | ||
if (namespace && name === 'namespace') { | ||
namespaceCache.atRules.push(node); | ||
} | ||
return; | ||
} | ||
}); | ||
counterStyle && filterAtRule(counterStyleCache); | ||
fontFace && filterFont(fontCache, comma); | ||
keyframes && filterAtRule(keyframesCache); | ||
namespace && filterNamespace(namespaceCache); | ||
} | ||
return; | ||
} | ||
}); | ||
counterStyle && filterAtRule(counterStyleCache); | ||
fontFace && filterFont(fontCache); | ||
keyframes && filterAtRule(keyframesCache); | ||
namespace && filterNamespace(namespaceCache); | ||
}; | ||
} | ||
}; | ||
}); | ||
} | ||
pluginCreator.postcss = true; | ||
var _default = pluginCreator; | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-discard-unused", | ||
"version": "4.0.0-nightly.2020.1.9", | ||
"version": "4.0.0-nightly.2020.1.11", | ||
"description": "Discard unused counter styles, keyframes and fonts.", | ||
@@ -33,5 +33,3 @@ "main": "dist/index.js", | ||
"dependencies": { | ||
"postcss": "^7.0.16", | ||
"postcss-selector-parser": "^3.1.1", | ||
"uniqs": "^2.0.0" | ||
"postcss-selector-parser": "^6.0.4" | ||
}, | ||
@@ -43,3 +41,9 @@ "bugs": { | ||
"node": ">=10.13.0" | ||
}, | ||
"devDependencies": { | ||
"postcss": "^8.2.1" | ||
}, | ||
"peerDependencies": { | ||
"postcss": "^8.2.1" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
9459
2
175
0
1
+ Addedcssesc@3.0.0(transitive)
+ Addednanoid@3.3.8(transitive)
+ Addedpicocolors@1.1.1(transitive)
+ Addedpostcss@8.5.1(transitive)
+ Addedpostcss-selector-parser@6.1.2(transitive)
+ Addedsource-map-js@1.2.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
- Removedpostcss@^7.0.16
- Removeduniqs@^2.0.0
- Removeddot-prop@5.3.0(transitive)
- Removedindexes-of@1.0.1(transitive)
- Removedis-obj@2.0.0(transitive)
- Removedpicocolors@0.2.1(transitive)
- Removedpostcss@7.0.39(transitive)
- Removedpostcss-selector-parser@3.1.2(transitive)
- Removedsource-map@0.6.1(transitive)
- Removeduniq@1.0.1(transitive)
- Removeduniqs@2.0.0(transitive)