Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,43 @@
# 2.2.3
* Font lookup is now case-insensitive, preventing unwanted removal of fonts
that are used (thanks to @thomas-mcdonald).
# 2.2.2
* Removed a dependency on `flatten`.
* Performance tweaks; now performs a single AST pass instead of four.
# 2.2.1
* Now compiled with Babel 6.
# 2.2.0
* Added a new option to remove `@namespace` rules (thanks to @plesiecki).
# 2.1.0
* Added options to customise what the module discards (thanks to @TrySound).
# 2.0.0
* Upgraded to PostCSS 5.
# 1.0.3
* Improved performance by reducing the amount of AST iterations.
* Converted the codebase to ES6.
# 1.0.2
* Fixes an integration issue where the module would crash on `undefined`
`rule.nodes`.
# 1.0.1
* Fixes an issue where multiple animations were not being recognized.
# 1.0.0
* Initial release.

View File

@@ -0,0 +1,22 @@
Copyright (c) Ben Briggs <beneb.info@gmail.com> (http://beneb.info)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

View File

@@ -0,0 +1,134 @@
# [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]
> Discard unused counter styles, keyframes and fonts.
## Install
With [npm](https://npmjs.org/package/postcss-discard-unused) do:
```
npm install postcss-discard-unused --save
```
## Example
This module will discard unused at rules in your CSS file, if it cannot find
any selectors that make use of them. It works on `@counter-style`, `@keyframes`
and `@font-face`.
### Input
```css
@counter-style custom {
system: extends decimal;
suffix: "> "
}
@counter-style custom2 {
system: extends decimal;
suffix: "| "
}
a {
list-style: custom
}
```
### Output
```css
@counter-style custom {
system: extends decimal;
suffix: "> "
}
a {
list-style: custom
}
```
Note that this plugin is not responsible for normalising font families, as it
makes the assumption that you will write your font names consistently, such that
it considers these two declarations differently:
```css
h1 {
font-family: "Helvetica Neue"
}
h2 {
font-family: Helvetica Neue
}
```
However, you can mitigate this by including [postcss-minify-font-values][mfv]
*before* this plugin, which will take care of normalising quotes, and
deduplicating. For more examples, see the [tests](test.js).
## Usage
See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for
examples for your environment.
## API
### discardUnused([options])
#### options
##### fontFace
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused font face rules.
##### counterStyle
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused counter style rules.
##### keyframes
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused keyframe rules.
##### namespace
Type: `boolean`
Default: `true`
Pass `false` to disable discarding unused namespace rules.
## Contributors
Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
<!-- 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 -->
This project follows the [all-contributors] specification. Contributions of
any kind welcome!
## License
MIT © [Ben Briggs](http://beneb.info)
[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

View File

@@ -0,0 +1,162 @@
'use strict';
exports.__esModule = true;
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 = require('uniqs');
var _uniqs2 = _interopRequireDefault(_uniqs);
var _postcss = require('postcss');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var comma = _postcss.list.comma;
var space = _postcss.list.space;
var atrule = 'atrule';
var decl = 'decl';
var rule = 'rule';
function addValues(cache, _ref) {
var value = _ref.value;
return comma(value).reduce(function (memo, val) {
return [].concat(memo, space(val));
}, cache);
}
function filterAtRule(_ref2) {
var atRules = _ref2.atRules;
var values = _ref2.values;
values = (0, _uniqs2.default)(values);
atRules.forEach(function (node) {
var hasAtRule = values.some(function (value) {
return value === node.params;
});
if (!hasAtRule) {
node.remove();
}
});
}
function filterNamespace(_ref3) {
var atRules = _ref3.atRules;
var rules = _ref3.rules;
rules = (0, _uniqs2.default)(rules);
atRules.forEach(function (atRule) {
var _atRule$params$split$ = atRule.params.split(' ').filter(Boolean);
var param = _atRule$params$split$[0];
var len = _atRule$params$split$.length;
if (len === 1) {
return;
}
var hasRule = rules.some(function (r) {
return r === param || r === '*';
});
if (!hasRule) {
atRule.remove();
}
});
}
function hasFont(fontFamily, cache) {
return comma(fontFamily).some(function (font) {
return cache.some(function (c) {
return ~c.indexOf(font);
});
});
}
// fonts have slightly different logic
function filterFont(_ref4) {
var atRules = _ref4.atRules;
var values = _ref4.values;
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();
}
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);
var fontFace = _fontFace$counterStyl.fontFace;
var counterStyle = _fontFace$counterStyl.counterStyle;
var keyframes = _fontFace$counterStyl.keyframes;
var namespace = _fontFace$counterStyl.namespace;
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 (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);
};
});
module.exports = exports['default'];

View File

@@ -0,0 +1,95 @@
{
"_args": [
[
"postcss-discard-unused@2.2.3",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "postcss-discard-unused@2.2.3",
"_id": "postcss-discard-unused@2.2.3",
"_inBundle": false,
"_integrity": "sha1-vOMLLMWR/8Y0Mitfs0ZLbZNPRDM=",
"_location": "/css-loader/postcss-discard-unused",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "postcss-discard-unused@2.2.3",
"name": "postcss-discard-unused",
"escapedName": "postcss-discard-unused",
"rawSpec": "2.2.3",
"saveSpec": null,
"fetchSpec": "2.2.3"
},
"_requiredBy": [
"/css-loader/cssnano"
],
"_resolved": "https://registry.npmjs.org/postcss-discard-unused/-/postcss-discard-unused-2.2.3.tgz",
"_spec": "2.2.3",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"author": {
"name": "Ben Briggs",
"email": "beneb.info@gmail.com",
"url": "http://beneb.info"
},
"ava": {
"require": "babel-register"
},
"bugs": {
"url": "https://github.com/ben-eb/postcss-discard-unused/issues"
},
"dependencies": {
"postcss": "^5.0.14",
"uniqs": "^2.0.0"
},
"description": "Discard unused counter styles, keyframes and fonts.",
"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"
},
"eslintConfig": {
"extends": "cssnano"
},
"files": [
"bin",
"LICENSE-MIT",
"dist"
],
"homepage": "https://github.com/ben-eb/postcss-discard-unused",
"keywords": [
"css",
"minify",
"optimise",
"postcss",
"postcss-plugin",
"unused"
],
"license": "MIT",
"main": "dist/index.js",
"name": "postcss-discard-unused",
"repository": {
"type": "git",
"url": "git+https://github.com/ben-eb/postcss-discard-unused.git"
},
"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__"
},
"version": "2.2.3"
}