summaryrefslogtreecommitdiff
path: root/node_modules/postcss-reporter/lib/reporter.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-10-14 20:57:16 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-10-14 20:57:16 +0800
commit924a88fab5466307aba0b76d36b30ab06b11dcb5 (patch)
tree088b6e0beeef92d55e2b2ca523af3501b27a2830 /node_modules/postcss-reporter/lib/reporter.js
parenta240fe4a4810b7f0c678a8519832fa37afaad265 (diff)
updates
Diffstat (limited to 'node_modules/postcss-reporter/lib/reporter.js')
-rw-r--r--node_modules/postcss-reporter/lib/reporter.js134
1 files changed, 77 insertions, 57 deletions
diff --git a/node_modules/postcss-reporter/lib/reporter.js b/node_modules/postcss-reporter/lib/reporter.js
index 70781fba..71872a97 100644
--- a/node_modules/postcss-reporter/lib/reporter.js
+++ b/node_modules/postcss-reporter/lib/reporter.js
@@ -1,81 +1,101 @@
-var chalk = require('chalk');
-var _ = require('lodash');
var defaultFormatter = require('./formatter');
+var pico = require('picocolors');
var util = require('./util');
-module.exports = function(opts) {
- var options = opts || {};
-
- var formatter = options.formatter || defaultFormatter({
- sortByPosition: (typeof options.sortByPosition !== 'undefined') ? options.sortByPosition : true,
- positionless: options.positionless || 'first',
- noIcon: options.noIcon,
- noPlugin: options.noPlugin,
- });
+module.exports = function (opts = {}) {
+ var formatter =
+ opts.formatter ||
+ defaultFormatter({
+ noIcon: opts.noIcon,
+ noPlugin: opts.noPlugin,
+ });
var pluginFilter;
- if (!options.plugins) {
+ if (!opts.plugins) {
// Every plugin
- pluginFilter = function() { return true; };
- } else if (options.plugins.every(function(plugin) { return plugin[0] === '!'; })) {
- // Blacklist
- pluginFilter = function(message) {
- return options.plugins.indexOf('!' + message.plugin) === -1;
+ pluginFilter = function () {
+ return true;
+ };
+ } else if (
+ opts.plugins.every(function (plugin) {
+ return plugin[0] === '!';
+ })
+ ) {
+ // Deny list
+ pluginFilter = function (message) {
+ return opts.plugins.indexOf('!' + message.plugin) === -1;
};
} else {
- // Whitelist
- pluginFilter = function(message) {
- return options.plugins.indexOf(message.plugin) !== -1;
+ // Allow list
+ pluginFilter = function (message) {
+ return opts.plugins.indexOf(message.plugin) !== -1;
};
}
- var messageFilter = options.filter || function(message) { return (message.type === 'warning'); };
+ var messageFilter = opts.filter || ((message) => message.type === 'warning');
- return function(css, result) {
- var messagesToLog = result.messages
- .filter(pluginFilter)
- .filter(messageFilter);
+ return {
+ postcssPlugin: 'postcss-reporter',
+ OnceExit(css, { result }) {
+ var messagesToLog = result.messages
+ .filter(pluginFilter)
+ .filter(messageFilter);
- var resultSource = (!result.root.source) ? ''
- : result.root.source.input.file || result.root.source.input.id
+ var resultSource = !result.root.source
+ ? ''
+ : result.root.source.input.file || result.root.source.input.id;
- var sourceGroupedMessages = _.groupBy(messagesToLog, function(message) {
- return util.getLocation(message).file || resultSource;
- });
+ var sourceGroupedMessages = messagesToLog.reduce((grouped, message) => {
+ const key = util.getLocation(message).file || resultSource;
- var report = '';
- _.forOwn(sourceGroupedMessages, function(messages, source) {
- report += formatter({
- messages: messages,
- source: source,
- });
- });
+ if (!grouped.hasOwnProperty(key)) {
+ grouped[key] = [];
+ }
+
+ grouped[key].push(message);
+
+ return grouped;
+ }, {});
- if (options.clearReportedMessages) {
- result.messages = _.difference(result.messages, messagesToLog);
- }
+ var report = '';
+ for (const source in sourceGroupedMessages) {
+ if (sourceGroupedMessages.hasOwnProperty(source)) {
+ report += formatter({
+ messages: sourceGroupedMessages[source],
+ source: source,
+ });
+ }
+ }
- if (options.clearAllMessages) {
- var messagesToClear = result.messages.filter(pluginFilter);
- result.messages = _.difference(result.messages, messagesToClear);
- }
+ if (opts.clearReportedMessages) {
+ result.messages = result.messages.filter(message => !messagesToLog.includes(message));
+ }
+ if (opts.clearAllMessages) {
+ var messagesToClear = result.messages.filter(pluginFilter);
+ result.messages = result.messages.filter(message => !messagesToClear.includes(message));
+ }
- if (!report) return;
+ if (!report) return;
- console.log(report);
+ console.log(report);
- if (options.throwError && shouldThrowError()) {
- throw new Error(chalk.red.bold('\n** postcss-reporter: warnings or errors were found **'));
- }
+ if (opts.throwError && shouldThrowError()) {
+ throw new Error(
+ pico.red(
+ pico.bold('\n** postcss-reporter: warnings or errors were found **')
+ )
+ );
+ }
- function shouldThrowError() {
- return (
- messagesToLog.length
- && messagesToLog.some(function(message) {
- return message.type === 'warning' || message.type === 'error';
- })
- );
- }
+ function shouldThrowError() {
+ return (
+ messagesToLog.length &&
+ messagesToLog.some((message) => {
+ return message.type === 'warning' || message.type === 'error';
+ })
+ );
+ }
+ },
};
};