diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:10:59 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2026-05-18 23:41:44 +0800 |
| commit | fc87c009806dcc98867f6b58efe29b042aa01dee (patch) | |
| tree | 8f59b3f4a5b66e9dfef2d40c8d318e258a521228 /node_modules/postcss-reporter/lib | |
| parent | 3336b2356ee6152d9c6ae59bd9b87ccbc0958407 (diff) | |
node: updatemain
Diffstat (limited to 'node_modules/postcss-reporter/lib')
| -rw-r--r-- | node_modules/postcss-reporter/lib/formatter.js | 93 | ||||
| -rw-r--r-- | node_modules/postcss-reporter/lib/reporter.js | 111 | ||||
| -rw-r--r-- | node_modules/postcss-reporter/lib/util.js | 31 |
3 files changed, 0 insertions, 235 deletions
diff --git a/node_modules/postcss-reporter/lib/formatter.js b/node_modules/postcss-reporter/lib/formatter.js deleted file mode 100644 index 300efad7..00000000 --- a/node_modules/postcss-reporter/lib/formatter.js +++ /dev/null @@ -1,93 +0,0 @@ -var pico = require('picocolors'); -var path = require('path'); -var firstBy = require('thenby'); -var util = require('./util'); - -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 positionless = options.positionless || 'first'; - - 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 = messages.sort(sortFunction); - - var output = '\n'; - - if (source) { - output += pico.bold(pico.underline(logFrom(source))) + '\n'; - } - - orderedMessages.forEach(function (w) { - output += messageToString(w) + '\n'; - }); - - return output; - - function messageToString(message) { - var location = util.getLocation(message); - var str = ''; - - if (location.line) { - str += pico.bold(location.line); - } - - if (location.column) { - str += pico.bold(':' + location.column); - } - - if (location.line || location.column) { - str += '\t'; - } - - if (!options.noIcon) { - if (message.type === 'warning') { - str += pico.yellow(util.warningSymbol + ' '); - } else if (message.type === 'error') { - str += pico.red(util.errorSymbol + ' '); - } - } - - str += message.text; - if (!options.noPlugin) { - str += pico.yellow(' [' + message.plugin + ']'); - } - return str; - } - - function logFrom(fromValue) { - if (fromValue.charAt(0) === '<') return fromValue; - return path.relative(process.cwd(), fromValue).split(path.sep).join('/'); - } - }; -}; diff --git a/node_modules/postcss-reporter/lib/reporter.js b/node_modules/postcss-reporter/lib/reporter.js deleted file mode 100644 index ae709c7d..00000000 --- a/node_modules/postcss-reporter/lib/reporter.js +++ /dev/null @@ -1,111 +0,0 @@ -var defaultFormatter = require('./formatter'); -var pico = require('picocolors'); -var util = require('./util'); - -module.exports = function (opts = {}) { - var formatter = - opts.formatter || - defaultFormatter({ - noIcon: opts.noIcon, - noPlugin: opts.noPlugin, - }); - - var pluginFilter; - if (!opts.plugins) { - // Every plugin - 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 { - // Allow list - pluginFilter = function (message) { - return opts.plugins.indexOf(message.plugin) !== -1; - }; - } - - var messageFilter = opts.filter || ((message) => message.type === 'warning' || message.type === 'error'); - - 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; - - let errorCount = 0; - let warningCount = 0; - - var sourceGroupedMessages = messagesToLog.reduce((grouped, message) => { - const key = util.getLocation(message).file || resultSource; - - if (!grouped.hasOwnProperty(key)) { - grouped[key] = []; - } - - if (message.type === 'error') { - errorCount++; - } else if (message.type === 'warning') { - warningCount++; - } - - grouped[key].push(message); - - return grouped; - }, {}); - - var report = ''; - for (const source in sourceGroupedMessages) { - if (sourceGroupedMessages.hasOwnProperty(source)) { - report += formatter({ - messages: sourceGroupedMessages[source], - source: source, - }); - } - } - - 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; - - const summaryColor = errorCount > 0 ? 'red' : 'yellow'; - const summarySymbol = errorCount > 0 ? util.errorSymbol : util.warningSymbol; - const summary = `${summarySymbol} ${messagesToLog.length} ${util.plur('problem', messagesToLog.length)} (${errorCount} ${util.plur('error')}, ${warningCount} ${util.plur('warning')})` - - report += `\n ${pico[summaryColor](pico.bold(summary))}\n`; - - console.log(report); - - if (shouldThrowError()) { - throw new Error( - pico.red( - pico.bold('\n** postcss-reporter: warnings or errors were found **') - ) - ); - } - - function shouldThrowError() { - return opts.throwError || errorCount > 0; - } - }, - }; -}; diff --git a/node_modules/postcss-reporter/lib/util.js b/node_modules/postcss-reporter/lib/util.js deleted file mode 100644 index 54334913..00000000 --- a/node_modules/postcss-reporter/lib/util.js +++ /dev/null @@ -1,31 +0,0 @@ -var supportsLargeCharset = - process.platform !== 'win32' || - process.env.CI || - process.env.TERM === 'xterm-256color'; - -exports.getLocation = function (message) { - var messageNode = message.node; - - var location = { - line: message.line, - column: message.column, - }; - - var messageInput = messageNode && messageNode.source && messageNode.source.input; - - if (!messageInput) return location; - - var originLocation = - messageInput.origin && messageInput.origin(message.line, message.column); - if (originLocation) return originLocation; - - location.file = messageInput.file || messageInput.id; - return location; -}; - -exports.plur = function plur(word, count) { - return (count === 1 ? word : `${word}s`); -} - -exports.warningSymbol = supportsLargeCharset ? '⚠' : '!!'; -exports.errorSymbol = supportsLargeCharset ? '✖' : 'xx'; |
