UNPKG

1.82 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-cssnext-warn-for-duplicates", function (_ref) {
27 var keys = _ref.keys,
28 messenger = _ref.console;
29
30 return function (style, result) {
31 var pluginNames = [];
32 result.processor.plugins.forEach(function (plugin) {
33 var name = plugin.postcssPlugin;
34 if (pluginNames.indexOf(name) > -1 &&
35 // warn for cssnext plugins only
36 keys.indexOf(name) > -1 &&
37 // show warning once
38 spotted.indexOf(name) === -1) {
39 messenger.log(_chalk2.default.yellow.bold(msg(name)));
40 spotted.push(name);
41 } else {
42 pluginNames.push(name);
43 }
44 });
45
46 if (spotted.length > 0 && shouldGlobalWarn) {
47 shouldGlobalWarn = false;
48 messenger.log(globalWarning);
49 }
50 };
51});
52
53exports.default = warnForDuplicates;
\No newline at end of file