postcss-discard-unused
Advanced tools
Comparing version 2.2.3 to 4.0.0-nightly.2020.7.24
@@ -1,162 +0,193 @@ | ||
'use strict'; | ||
"use strict"; | ||
exports.__esModule = true; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
var _uniqs = _interopRequireDefault(require("uniqs")); | ||
var _uniqs = require('uniqs'); | ||
var _postcss = require("postcss"); | ||
var _uniqs2 = _interopRequireDefault(_uniqs); | ||
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser")); | ||
var _postcss = require('postcss'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var comma = _postcss.list.comma; | ||
var space = _postcss.list.space; | ||
const { | ||
comma, | ||
space | ||
} = _postcss.list; | ||
const atrule = 'atrule'; | ||
const decl = 'decl'; | ||
const rule = 'rule'; | ||
function addValues(cache, { | ||
value | ||
}) { | ||
return comma(value).reduce((memo, val) => [...memo, ...space(val)], cache); | ||
} | ||
var atrule = 'atrule'; | ||
var decl = 'decl'; | ||
var rule = 'rule'; | ||
function filterAtRule({ | ||
atRules, | ||
values | ||
}) { | ||
values = (0, _uniqs.default)(values); | ||
atRules.forEach(node => { | ||
const hasAtRule = values.some(value => value === node.params); | ||
function addValues(cache, _ref) { | ||
var value = _ref.value; | ||
if (!hasAtRule) { | ||
node.remove(); | ||
} | ||
}); | ||
} | ||
return comma(value).reduce(function (memo, val) { | ||
return [].concat(memo, space(val)); | ||
}, cache); | ||
function filterNamespace({ | ||
atRules, | ||
rules | ||
}) { | ||
rules = (0, _uniqs.default)(rules); | ||
atRules.forEach(atRule => { | ||
const { | ||
0: param, | ||
length: len | ||
} = atRule.params.split(' ').filter(Boolean); | ||
if (len === 1) { | ||
return; | ||
} | ||
const hasRule = rules.some(r => r === param || r === '*'); | ||
if (!hasRule) { | ||
atRule.remove(); | ||
} | ||
}); | ||
} | ||
function filterAtRule(_ref2) { | ||
var atRules = _ref2.atRules; | ||
var values = _ref2.values; | ||
function hasFont(fontFamily, cache) { | ||
return comma(fontFamily).some(font => cache.some(c => ~c.indexOf(font))); | ||
} // fonts have slightly different logic | ||
values = (0, _uniqs2.default)(values); | ||
atRules.forEach(function (node) { | ||
var hasAtRule = values.some(function (value) { | ||
return value === node.params; | ||
}); | ||
if (!hasAtRule) { | ||
node.remove(); | ||
} | ||
function filterFont({ | ||
atRules, | ||
values | ||
}) { | ||
values = (0, _uniqs.default)(values); | ||
atRules.forEach(r => { | ||
const families = r.nodes.filter(({ | ||
prop | ||
}) => prop === 'font-family'); // Discard the @font-face if it has no font-family | ||
if (!families.length) { | ||
return r.remove(); | ||
} | ||
families.forEach(family => { | ||
if (!hasFont(family.value.toLowerCase(), values)) { | ||
r.remove(); | ||
} | ||
}); | ||
}); | ||
} | ||
function filterNamespace(_ref3) { | ||
var atRules = _ref3.atRules; | ||
var rules = _ref3.rules; | ||
var _default = (0, _postcss.plugin)('postcss-discard-unused', opts => { | ||
const { | ||
fontFace, | ||
counterStyle, | ||
keyframes, | ||
namespace | ||
} = Object.assign({}, { | ||
fontFace: true, | ||
counterStyle: true, | ||
keyframes: true, | ||
namespace: true | ||
}, 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; | ||
rules = (0, _uniqs2.default)(rules); | ||
atRules.forEach(function (atRule) { | ||
var _atRule$params$split$ = atRule.params.split(' ').filter(Boolean); | ||
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]); | ||
} | ||
var param = _atRule$params$split$[0]; | ||
var len = _atRule$params$split$.length; | ||
return; | ||
} | ||
if (len === 1) { | ||
return; | ||
if (type === decl) { | ||
if (counterStyle && /list-style|system/.test(prop)) { | ||
counterStyleCache.values = addValues(counterStyleCache.values, node); | ||
} | ||
var hasRule = rules.some(function (r) { | ||
return r === param || r === '*'; | ||
}); | ||
if (!hasRule) { | ||
atRule.remove(); | ||
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) { | ||
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase())); | ||
} | ||
}); | ||
} | ||
function hasFont(fontFamily, cache) { | ||
return comma(fontFamily).some(function (font) { | ||
return cache.some(function (c) { | ||
return ~c.indexOf(font); | ||
}); | ||
}); | ||
} | ||
if (keyframes && /animation/.test(prop)) { | ||
keyframesCache.values = addValues(keyframesCache.values, node); | ||
} | ||
// fonts have slightly different logic | ||
function filterFont(_ref4) { | ||
var atRules = _ref4.atRules; | ||
var values = _ref4.values; | ||
return; | ||
} | ||
values = (0, _uniqs2.default)(values); | ||
atRules.forEach(function (r) { | ||
var families = r.nodes.filter(function (_ref5) { | ||
var prop = _ref5.prop; | ||
return prop === 'font-family'; | ||
}); | ||
// Discard the @font-face if it has no font-family | ||
if (!families.length) { | ||
return r.remove(); | ||
if (type === atrule) { | ||
if (counterStyle && /counter-style/.test(name)) { | ||
counterStyleCache.atRules.push(node); | ||
} | ||
families.forEach(function (family) { | ||
if (!hasFont(family.value.toLowerCase(), values)) { | ||
r.remove(); | ||
} | ||
}); | ||
}); | ||
} | ||
exports.default = (0, _postcss.plugin)('postcss-discard-unused', function (opts) { | ||
var _fontFace$counterStyl = _extends({ | ||
fontFace: true, | ||
counterStyle: true, | ||
keyframes: true, | ||
namespace: true | ||
}, opts); | ||
if (fontFace && name === 'font-face' && node.nodes) { | ||
fontCache.atRules.push(node); | ||
} | ||
var fontFace = _fontFace$counterStyl.fontFace; | ||
var counterStyle = _fontFace$counterStyl.counterStyle; | ||
var keyframes = _fontFace$counterStyl.keyframes; | ||
var namespace = _fontFace$counterStyl.namespace; | ||
if (keyframes && /keyframes/.test(name)) { | ||
keyframesCache.atRules.push(node); | ||
} | ||
return function (css) { | ||
var counterStyleCache = { atRules: [], values: [] }; | ||
var keyframesCache = { atRules: [], values: [] }; | ||
var namespaceCache = { atRules: [], rules: [] }; | ||
var fontCache = { atRules: [], values: [] }; | ||
css.walk(function (node) { | ||
var type = node.type; | ||
var prop = node.prop; | ||
var selector = node.selector; | ||
var name = node.name; | ||
if (namespace && name === 'namespace') { | ||
namespaceCache.atRules.push(node); | ||
} | ||
if (type === rule && namespace && ~selector.indexOf('|')) { | ||
namespaceCache.rules = namespaceCache.rules.concat(selector.split('|')[0]); | ||
return; | ||
} | ||
if (type === decl) { | ||
if (counterStyle && /list-style|system/.test(prop)) { | ||
counterStyleCache.values = addValues(counterStyleCache.values, node); | ||
} | ||
if (fontFace && node.parent.type === rule && /font(|-family)/.test(prop)) { | ||
fontCache.values = fontCache.values.concat(comma(node.value.toLowerCase())); | ||
} | ||
if (keyframes && /animation/.test(prop)) { | ||
keyframesCache.values = addValues(keyframesCache.values, node); | ||
} | ||
return; | ||
} | ||
if (type === atrule) { | ||
if (counterStyle && /counter-style/.test(name)) { | ||
counterStyleCache.atRules.push(node); | ||
} | ||
if (fontFace && name === 'font-face' && node.nodes) { | ||
fontCache.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); | ||
keyframes && filterAtRule(keyframesCache); | ||
namespace && filterNamespace(namespaceCache); | ||
}; | ||
return; | ||
} | ||
}); | ||
counterStyle && filterAtRule(counterStyleCache); | ||
fontFace && filterFont(fontCache); | ||
keyframes && filterAtRule(keyframesCache); | ||
namespace && filterNamespace(namespaceCache); | ||
}; | ||
}); | ||
module.exports = exports['default']; | ||
exports.default = _default; | ||
module.exports = exports.default; |
{ | ||
"name": "postcss-discard-unused", | ||
"version": "2.2.3", | ||
"version": "4.0.0-nightly.2020.7.24", | ||
"description": "Discard unused counter styles, keyframes and fonts.", | ||
@@ -12,8 +12,5 @@ "main": "dist/index.js", | ||
"scripts": { | ||
"contributorAdd": "all-contributors add", | ||
"contributorGenerate": "all-contributors generate", | ||
"prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", | ||
"pretest": "eslint src", | ||
"test": "ava src/__tests__", | ||
"test-012": "ava src/__tests__" | ||
"prebuild": "", | ||
"build": "cross-env BABEL_ENV=publish babel src --config-file ../../babel.config.js --out-dir dist --ignore \"**/__tests__/\"", | ||
"prepublish": "" | ||
}, | ||
@@ -29,19 +26,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"devDependencies": { | ||
"all-contributors-cli": "^3.0.5", | ||
"ava": "^0.16.0", | ||
"babel-cli": "^6.4.5", | ||
"babel-core": "^6.4.5", | ||
"babel-plugin-add-module-exports": "^0.2.0", | ||
"babel-preset-es2015": "^6.3.13", | ||
"babel-preset-es2015-loose": "^7.0.0", | ||
"babel-preset-stage-0": "^6.3.13", | ||
"babel-register": "^6.9.0", | ||
"del-cli": "^0.2.0", | ||
"eslint": "^3.0.0", | ||
"eslint-config-cssnano": "^3.0.0", | ||
"eslint-plugin-babel": "^3.3.0", | ||
"eslint-plugin-import": "^2.0.1" | ||
}, | ||
"homepage": "https://github.com/ben-eb/postcss-discard-unused", | ||
"homepage": "https://github.com/cssnano/cssnano", | ||
"author": { | ||
@@ -52,13 +33,14 @@ "name": "Ben Briggs", | ||
}, | ||
"repository": "ben-eb/postcss-discard-unused", | ||
"repository": "cssnano/cssnano", | ||
"dependencies": { | ||
"postcss": "^5.0.14", | ||
"postcss": "^7.0.16", | ||
"postcss-selector-parser": "^3.1.1", | ||
"uniqs": "^2.0.0" | ||
}, | ||
"ava": { | ||
"require": "babel-register" | ||
"bugs": { | ||
"url": "https://github.com/cssnano/cssnano/issues" | ||
}, | ||
"eslintConfig": { | ||
"extends": "cssnano" | ||
"engines": { | ||
"node": ">=6.9.0" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# [postcss][postcss]-discard-unused [![Build Status](https://travis-ci.org/ben-eb/postcss-discard-unused.svg?branch=master)][ci] [![NPM version](https://badge.fury.io/js/postcss-discard-unused.svg)][npm] [![Dependency Status](https://gemnasium.com/ben-eb/postcss-discard-unused.svg)][deps] | ||
# [postcss][postcss]-discard-unused | ||
@@ -68,3 +68,3 @@ > Discard unused counter styles, keyframes and fonts. | ||
*before* this plugin, which will take care of normalising quotes, and | ||
deduplicating. For more examples, see the [tests](test.js). | ||
deduplicating. For more examples, see the [tests](src/__tests__/index.js). | ||
@@ -113,13 +113,10 @@ | ||
## Contributors | ||
## Usage | ||
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | ||
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for | ||
examples for your environment. | ||
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> | ||
| [<img src="https://avatars.githubusercontent.com/u/1282980?v=3" width="100px;"/><br /><sub>Ben Briggs</sub>](http://beneb.info)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=ben-eb) [📖](https://github.com/ben-eb/postcss-discard-unused/commits?author=ben-eb) 👀 [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=ben-eb) | [<img src="https://avatars.githubusercontent.com/u/5635476?v=3" width="100px;"/><br /><sub>Bogdan Chadkin</sub>](https://github.com/TrySound)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=TrySound) [📖](https://github.com/ben-eb/postcss-discard-unused/commits?author=TrySound) 👀 [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=TrySound) | [<img src="https://avatars.githubusercontent.com/u/770675?v=3" width="100px;"/><br /><sub>Paweł Lesiecki</sub>](https://github.com/plesiecki)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=plesiecki) [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=plesiecki) | [<img src="https://avatars.githubusercontent.com/u/197928?v=3" width="100px;"/><br /><sub>Thomas McDonald</sub>](https://github.com/thomas-mcdonald)<br />[💻](https://github.com/ben-eb/postcss-discard-unused/commits?author=thomas-mcdonald) [⚠️](https://github.com/ben-eb/postcss-discard-unused/commits?author=thomas-mcdonald) | | ||
| :---: | :---: | :---: | :---: | | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
## Contributors | ||
This project follows the [all-contributors] specification. Contributions of | ||
any kind welcome! | ||
See [CONTRIBUTORS.md](https://github.com/cssnano/cssnano/blob/master/CONTRIBUTORS.md). | ||
@@ -131,7 +128,3 @@ ## License | ||
[all-contributors]: https://github.com/kentcdodds/all-contributors | ||
[ci]: https://travis-ci.org/ben-eb/postcss-discard-unused | ||
[deps]: https://gemnasium.com/ben-eb/postcss-discard-unused | ||
[npm]: http://badge.fury.io/js/postcss-discard-unused | ||
[postcss]: https://github.com/postcss/postcss | ||
[mfv]: https://github.com/trysound/postcss-minify-font-values |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
0
161
0
8792
3
4
128
2
+ Addeddot-prop@5.3.0(transitive)
+ Addedindexes-of@1.0.1(transitive)
+ Addedis-obj@2.0.0(transitive)
+ Addedpicocolors@0.2.1(transitive)
+ Addedpostcss@7.0.39(transitive)
+ Addedpostcss-selector-parser@3.1.2(transitive)
+ Addedsource-map@0.6.1(transitive)
+ Addeduniq@1.0.1(transitive)
- Removedansi-regex@2.1.1(transitive)
- Removedansi-styles@2.2.1(transitive)
- Removedchalk@1.1.3(transitive)
- Removedescape-string-regexp@1.0.5(transitive)
- Removedhas-ansi@2.0.0(transitive)
- Removedhas-flag@1.0.0(transitive)
- Removedjs-base64@2.6.4(transitive)
- Removedpostcss@5.2.18(transitive)
- Removedsource-map@0.5.7(transitive)
- Removedstrip-ansi@3.0.1(transitive)
- Removedsupports-color@2.0.03.2.3(transitive)
Updatedpostcss@^7.0.16