diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 20:57:16 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2023-10-14 20:57:16 +0800 |
| commit | 924a88fab5466307aba0b76d36b30ab06b11dcb5 (patch) | |
| tree | 088b6e0beeef92d55e2b2ca523af3501b27a2830 /node_modules/postcss-reporter/lib/formatter.js | |
| parent | a240fe4a4810b7f0c678a8519832fa37afaad265 (diff) | |
updates
Diffstat (limited to 'node_modules/postcss-reporter/lib/formatter.js')
| -rw-r--r-- | node_modules/postcss-reporter/lib/formatter.js | 75 |
1 files changed, 45 insertions, 30 deletions
diff --git a/node_modules/postcss-reporter/lib/formatter.js b/node_modules/postcss-reporter/lib/formatter.js index b5719b8f..7358cc61 100644 --- a/node_modules/postcss-reporter/lib/formatter.js +++ b/node_modules/postcss-reporter/lib/formatter.js @@ -1,45 +1,60 @@ -var chalk = require('chalk'); +var pico = require('picocolors'); var path = require('path'); -var symbols = require('log-symbols'); -var _ = require('lodash'); +var firstBy = require('thenby'); var util = require('./util'); -module.exports = function(opts) { +var supportsLargeCharset = + process.platform !== 'win32' || + process.env.CI || + process.env.TERM === 'xterm-256color'; +var warningSymbol = supportsLargeCharset ? '⚠' : '!!'; + +function createSortFunction(positionless, sortByPosition) { + var positionValue = 0 + + if (positionless === 'any') { positionValue = 1; } + if (positionless === 'first') { positionValue = 2; } + if (positionless === 'last') { positionValue = 0; } + + var sortFunction = firstBy((m) => { + if (!m.line) return 1; + return positionValue; + }) + + if (sortByPosition) { + sortFunction = sortFunction.thenBy('line').thenBy('column'); + } + + return sortFunction; +} + +module.exports = function (opts) { var options = opts || {}; - var sortByPosition = (typeof options.sortByPosition !== 'undefined') ? options.sortByPosition : true; + var sortByPosition = + typeof options.sortByPosition !== 'undefined' + ? options.sortByPosition + : true; var positionless = options.positionless || 'first'; - return function(input) { - var messages = input.messages; + var sortFunction = createSortFunction(positionless, sortByPosition); + + return function (input) { + var messages = input.messages.filter(function (message) { + return typeof message.text === 'string'; + }); var source = input.source; if (!messages.length) return ''; - var orderedMessages = _.sortBy( - messages, - function(m) { - if (!m.line) return 1; - if (positionless === 'any') return 1; - if (positionless === 'first') return 2; - if (positionless === 'last') return 0; - }, - function(m) { - if (!sortByPosition) return 1; - return m.line; - }, - function(m) { - if (!sortByPosition) return 1; - return m.column; - } - ); + var orderedMessages = messages.sort(sortFunction); var output = '\n'; if (source) { - output += chalk.bold.underline(logFrom(source)) + '\n'; + output += pico.bold(pico.underline(logFrom(source))) + '\n'; } - orderedMessages.forEach(function(w) { + orderedMessages.forEach(function (w) { output += messageToString(w) + '\n'; }); @@ -50,11 +65,11 @@ module.exports = function(opts) { var str = ''; if (location.line) { - str += chalk.bold(location.line); + str += pico.bold(location.line); } if (location.column) { - str += chalk.bold(':' + location.column) + str += pico.bold(':' + location.column); } if (location.line || location.column) { @@ -62,12 +77,12 @@ module.exports = function(opts) { } if (!options.noIcon && message.type === 'warning') { - str += chalk.yellow(symbols.warning + ' '); + str += pico.yellow(warningSymbol + ' '); } str += message.text; if (!options.noPlugin) { - str += chalk.yellow(' [' + message.plugin + ']'); + str += pico.yellow(' [' + message.plugin + ']'); } return str; } |
