UNPKG

1.9 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.spotted = undefined;
7
8var _postcss = require("postcss");
9
10var _postcss2 = _interopRequireDefault(_postcss);
11
12var _chalk = require("chalk");
13
14var _chalk2 = _interopRequireDefault(_chalk);
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18var msg = function msg(name) {
19 return "Warning: postcss-cssnext found a duplicate plugin ('" + name + "') " + "in your postcss plugins. " + ("This might be inefficient. You should remove '" + name + "' from your ") + "postcss plugin list since it's already included by postcss-cssnext.";
20};
21
22var shouldGlobalWarn = true;
23var globalWarning = "Note: If, for a really specific reason, postcss-cssnext warnings are " + "irrelevant for your use case, and you really know what you are doing, " + "you can disable this warnings by setting 'warnForDuplicates' option of " + "postcss-cssnext to 'false'.";
24var spotted = exports.spotted = [];
25
26var warnForDuplicates = _postcss2.default.plugin("postcss-warn-for-duplicates", function (options) {
27 return function (style, result) {
28 // https://github.com/postcss/postcss/issues/768
29 var keys = options.keys,
30 messenger = options.console;
31
32 var pluginNames = [];
33 result.processor.plugins.forEach(function (plugin) {
34 var name = plugin.postcssPlugin;
35 if (pluginNames.indexOf(name) > -1 &&
36 // warn for cssnext plugins only
37 keys.indexOf(name) > -1 &&
38 // show warning once
39 spotted.indexOf(name) === -1) {
40 messenger.log(_chalk2.default.yellow.bold(msg(name)));
41 spotted.push(name);
42 } else {
43 pluginNames.push(name);
44 }
45 });
46
47 if (spotted.length > 0 && shouldGlobalWarn) {
48 shouldGlobalWarn = false;
49 messenger.log(globalWarning);
50 }
51 };
52});
53
54exports.default = warnForDuplicates;
\No newline at end of file