pax_global_header00006660000000000000000000000064127745034640014526gustar00rootroot0000000000000052 comment=1e5d52336e0e5fbf8b25815eadeeefde80803b2e postcss-filter-plugins-2.0.2/000077500000000000000000000000001277450346400161675ustar00rootroot00000000000000postcss-filter-plugins-2.0.2/.all-contributorsrc000066400000000000000000000016271277450346400220260ustar00rootroot00000000000000{ "projectName": "postcss-filter-plugins", "projectOwner": "postcss", "files": [ "README.md" ], "imageSize": 100, "commit": false, "contributors": [ { "login": "ben-eb", "name": "Ben Briggs", "avatar_url": "https://avatars.githubusercontent.com/u/1282980?v=3", "profile": "http://beneb.info", "contributions": [ "code", "doc", "review", "test" ] }, { "login": "MoOx", "name": "Maxime Thirouin", "avatar_url": "https://avatars.githubusercontent.com/u/157534?v=3", "profile": "https://moox.io/", "contributions": [ "doc" ] }, { "login": "papandreou", "name": "Andreas Lind", "avatar_url": "https://avatars.githubusercontent.com/u/373545?v=3", "profile": "https://github.com/papandreou", "contributions": [ "code" ] } ] } postcss-filter-plugins-2.0.2/.babelrc000066400000000000000000000002321277450346400175570ustar00rootroot00000000000000{ "presets": ["es2015-loose", "stage-0"], "plugins": ["add-module-exports"], "env": { "development": { "sourceMaps": "inline" } } } postcss-filter-plugins-2.0.2/.editorconfig000066400000000000000000000003571277450346400206510ustar00rootroot00000000000000# editorconfig.org root = true [*] indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.{json,yml}] indent_size = 2 [*.md] trim_trailing_whitespace = false postcss-filter-plugins-2.0.2/.gitignore000066400000000000000000000000401277450346400201510ustar00rootroot00000000000000node_modules npm-debug.log dist postcss-filter-plugins-2.0.2/.travis.yml000066400000000000000000000002771277450346400203060ustar00rootroot00000000000000language: node_js matrix: include: - node_js: '5' - node_js: '4' - node_js: '0.12' env: NO_ESLINT=true script: "[[ $NO_ESLINT == true ]] && npm run test-012 || npm test" postcss-filter-plugins-2.0.2/CHANGELOG.md000066400000000000000000000004501277450346400177770ustar00rootroot00000000000000# 2.0.2 * Bumped uniqid to `4.0.0`. # 2.0.1 * Bumped uniqid to `3.0.0` (thanks to @papandreou). # 2.0.0 * Upgraded to PostCSS 5. # 1.0.1 * Fixes an integration issue with cssnano & cssnext, caused by processors that do not expose a `postcssPlugin` property. # 1.0.0 * Initial release. postcss-filter-plugins-2.0.2/LICENSE-MIT000066400000000000000000000021041277450346400176200ustar00rootroot00000000000000Copyright (c) Ben Briggs (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. postcss-filter-plugins-2.0.2/README.md000066400000000000000000000073551277450346400174600ustar00rootroot00000000000000# [postcss][postcss]-filter-plugins [![Build Status](https://travis-ci.org/postcss/postcss-filter-plugins.svg?branch=master)][ci] > Exclude/warn on duplicated PostCSS plugins. ## Install With [npm](https://npmjs.org/package/postcss-filter-plugins) do: ```console $ npm install postcss-filter-plugins --save ``` ## Example Note that this plugin does not actually transform your CSS; instead, it ensures that plugins in the PostCSS instance are not duplicated. It is intended to be used by plugin packs such as [cssnano] or [cssnext]. ```js var counter = postcss.plugin('counter', function () { return function (css) { css.eachDecl('foo', function (decl) { let value = parseInt(decl.value, 10); value += 1; decl.value = String(value); }); } }); var css = 'h1 { foo: 1 }'; var out = postcss([ filter(), counter(), counter() ]).process(css).css; console.log(out); // => h1 { foo: 2 } // Note that you will get a PostCSS warning in the message registry ``` ## API ### filterPlugins([options]) #### options ##### direction Type: `string` Default: `'both'` Pass `'forward'`, `'backward'`, or `'both'` to customise the direction in which the plugin will look in the plugins array. See the [tests] for examples on how this works. ```js postcss([ filter({ direction: 'forward' }) ]).process(css).css); ``` ##### exclude Type: `array` Default: `[] (empty)` Plugins that should be excluded from the filter. Pass an array of plugin names. ```js postcss([ filter({ exclude: ['postcss-cssstats'] }) ]).process(css).css); ``` ##### silent Type: `boolean` Default: `false` Set this to true to disable the plugin from emitting any PostCSS warnings. ```js postcss([ filter({ silent: true }) ]).process(css).css); ``` ##### template Type: `function` Default: `format function` This function will be passed each PostCSS plugin object. You are expected to return a string from each call, which is then used to warn the user about her duplicated plugins. ```js postcss([ filter({ template: function (plugin) { return 'Duplicate plugin found: ' + plugin.postcssPlugin; } }) ]).process(css).css); ``` ## Usage See the [PostCSS documentation](https://github.com/postcss/postcss#usage) for examples for your environment. ## Contributors Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): | [
Ben Briggs](http://beneb.info)
[💻](https://github.com/postcss/postcss-filter-plugins/commits?author=ben-eb) [📖](https://github.com/postcss/postcss-filter-plugins/commits?author=ben-eb) 👀 [⚠️](https://github.com/postcss/postcss-filter-plugins/commits?author=ben-eb) | [
Maxime Thirouin](https://moox.io/)
[📖](https://github.com/postcss/postcss-filter-plugins/commits?author=MoOx) | [
Andreas Lind](https://github.com/papandreou)
[💻](https://github.com/postcss/postcss-filter-plugins/commits?author=papandreou) | | :---: | :---: | :---: | This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! ## License MIT © [Ben Briggs](http://beneb.info) [ci]: https://travis-ci.org/postcss/postcss-filter-plugins [cssnano]: http://cssnano.co [cssnext]: http://cssnext.io [postcss]: https://github.com/postcss/postcss [tests]: src/__tests__ postcss-filter-plugins-2.0.2/package.json000066400000000000000000000027571277450346400204700ustar00rootroot00000000000000{ "name": "postcss-filter-plugins", "version": "2.0.2", "description": "Exclude/warn on duplicated PostCSS plugins.", "main": "dist/index.js", "scripts": { "contributorAdd": "all-contributors add", "contributorGenerate": "all-contributors generate", "pretest": "eslint src", "prepublish": "del-cli dist && BABEL_ENV=publish babel src --out-dir dist --ignore /__tests__/", "test": "ava src/__tests__/", "test-012": "ava src/__tests__/" }, "files": [ "LICENSE-MIT", "dist" ], "keywords": [ "css", "postcss", "postcss-plugin" ], "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": "^1.10.2" }, "homepage": "https://github.com/postcss/postcss-filter-plugins", "author": { "name": "Ben Briggs", "email": "beneb.info@gmail.com", "url": "http://beneb.info" }, "repository": "postcss/postcss-filter-plugins", "dependencies": { "postcss": "^5.0.4", "uniqid": "^4.0.0" }, "ava": { "require": "babel-register" }, "eslintConfig": { "extends": "cssnano" } } postcss-filter-plugins-2.0.2/src/000077500000000000000000000000001277450346400167565ustar00rootroot00000000000000postcss-filter-plugins-2.0.2/src/__tests__/000077500000000000000000000000001277450346400207145ustar00rootroot00000000000000postcss-filter-plugins-2.0.2/src/__tests__/index.js000066400000000000000000000064121277450346400223640ustar00rootroot00000000000000import test from 'ava'; import postcss from 'postcss'; import {name} from '../../package.json'; import filter from '../'; function getWarnings (filters) { return postcss(filters).process('h1{}').warnings(); } const fontWeight = postcss.plugin('fontWeight', () => { return function (css) { css.walkDecls('font-weight', decl => { const {value} = decl; decl.value = value === 'normal' ? '400' : value === 'bold' ? '700' : value; }); }; }); test('readme example code', t => { const counter = postcss.plugin('counter', () => { return css => { css.walkDecls('foo', decl => { let value = parseInt(decl.value, 10); value += 1; decl.value = String(value); }); }; }); const css = 'h1 { foo: 1 }'; const out = postcss([ filter(), counter(), counter() ]).process(css).css; t.is(out, 'h1 { foo: 2 }'); }); test('should handle processors without the postcssPlugin property', t => { const foo = () => css => css.walkDecls('foo', f => f.remove()); const css = 'h1 { foo: bar; font-weight: normal }'; return postcss([ foo(), fontWeight(), filter(), foo(), fontWeight() ]).process(css).then(result => { t.is(result.css, 'h1 { font-weight: 400 }'); t.is(result.processor.plugins.length, 4); }); }); test('should warn if plugin exists', t => { const plugins = [ fontWeight(), filter(), fontWeight(), ]; const warnings = getWarnings(plugins); t.is(warnings.length, 1); t.is(warnings[0].text, 'Found duplicate plugin: fontWeight'); }); test('should warn if plugin exists, with a custom message', t => { const template = ({postcssPlugin}) => `Uh-oh: ${postcssPlugin}`; const plugins = [ fontWeight(), filter({template}), fontWeight(), ]; const warnings = getWarnings(plugins); t.is(warnings.length, 1); t.is(warnings[0].text, 'Uh-oh: fontWeight'); }); test('should not warn when silent', t => { const plugins = [ fontWeight(), filter({silent: true}), fontWeight(), ]; t.is(getWarnings(plugins).length, 0); }); test('should not warn if the plugin is excluded from the filter', t => { const plugins = [ fontWeight(), filter({exclude: ['fontWeight']}), fontWeight(), ]; t.is(getWarnings(plugins).length, 0); }); test('should operate forward from the filter instance', t => { const plugins = [ fontWeight(), filter({direction: 'forward'}), fontWeight(), fontWeight(), ]; t.is(getWarnings(plugins).length, 1); }); test('should operate backward from the filter instance', t => { const plugins = [ fontWeight(), fontWeight(), filter({direction: 'backward'}), fontWeight(), ]; t.is(getWarnings(plugins).length, 1); }); test('should not filter itself when there are multiple instances', t => { const plugins = [ filter(), filter(), filter(), filter() ]; t.falsy(getWarnings(plugins).length); }); test('should use the postcss plugin api', t => { t.truthy(filter().postcssVersion, 'should be able to access version'); t.deepEqual(filter().postcssPlugin, name, 'should be able to access name'); }); postcss-filter-plugins-2.0.2/src/index.js000066400000000000000000000042271277450346400204300ustar00rootroot00000000000000import postcss from 'postcss'; import uniqid from 'uniqid'; export default postcss.plugin('postcss-filter-plugins', ({ template = ({postcssPlugin}) => `Found duplicate plugin: ${postcssPlugin}`, silent = false, exclude = [], direction = 'both', } = {}) => { const id = uniqid(); let prev, next, both; switch (direction) { case 'both': both = true; break; case 'backward': prev = true; break; case 'forward': next = true; break; } const processor = (css, result) => { const previousPlugins = []; const nextPlugins = []; const bothPlugins = []; let filter = false; let position = 0; const detect = (list, plugin) => { const name = plugin.postcssPlugin; if (typeof name === 'undefined') { position++; return; } if (~list.indexOf(name)) { if (!silent) { result.warn(template(plugin)); } result.processor.plugins.splice(position, 1); } else { list.push(name); position ++; } }; while (position < result.processor.plugins.length) { const plugin = result.processor.plugins[position]; if (~exclude.indexOf(plugin.postcssPlugin)) { position ++; continue; } if (plugin._id === id) { position ++; filter = true; continue; } else if (plugin.postcssPlugin === 'postcss-filter-plugins') { position ++; continue; } if (both) { detect(bothPlugins, plugin); continue; } if (filter && next) { detect(nextPlugins, plugin); continue; } if (!filter && prev) { detect(previousPlugins, plugin); continue; } position ++; } }; processor._id = id; return processor; });