This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

20
node_modules/consola/src/browser.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import Consola from './consola.js'
import BrowserReporter from './reporters/browser.js'
import { LogLevel } from './logLevels'
function createConsola () {
const consola = new Consola({
reporters: [
new BrowserReporter()
]
})
// Expose constructors
consola.Consola = Consola
consola.LogLevel = LogLevel
consola.BrowserReporter = BrowserReporter
return consola
}
export default (typeof window !== 'undefined' && window.consola) || createConsola()

327
node_modules/consola/src/consola.js generated vendored Normal file
View File

@@ -0,0 +1,327 @@
import Types from './types.js'
import { isLogObj } from './utils/index.js'
let paused = false
const queue = []
class Consola {
constructor (options = {}) {
this._reporters = options.reporters || []
this._types = options.types || Types
this.level = options.level !== undefined ? options.level : 3
this._defaults = options.defaults || {}
this._async = options.async !== undefined ? options.async : undefined
this._stdout = options.stdout
this._stderr = options.stderr
this._mockFn = options.mockFn
this._throttle = options.throttle || 1000
this._throttleMin = options.throttleMin || 5
// Create logger functions for current instance
for (const type in this._types) {
const defaults = {
type,
...this._types[type],
...this._defaults
}
this[type] = this._wrapLogFn(defaults)
this[type].raw = this._wrapLogFn(defaults, true)
}
// Use _mockFn if is set
if (this._mockFn) {
this.mockTypes()
}
// Keep serialized version of last log
this._lastLogSerialized = undefined
this._lastLog = undefined
this._lastLogTime = undefined
this._lastLogCount = 0
this._throttleTimeout = undefined
}
get stdout () {
return this._stdout || console._stdout // eslint-disable-line no-console
}
get stderr () {
return this._stderr || console._stderr // eslint-disable-line no-console
}
create (options) {
return new Consola(Object.assign({
reporters: this._reporters,
level: this.level,
types: this._types,
defaults: this._defaults,
stdout: this._stdout,
stderr: this._stderr,
mockFn: this._mockFn
}, options))
}
withDefaults (defaults) {
return this.create({
defaults: Object.assign({}, this._defaults, defaults)
})
}
withTag (tag) {
return this.withDefaults({
tag: this._defaults.tag ? (this._defaults.tag + ':' + tag) : tag
})
}
addReporter (reporter) {
this._reporters.push(reporter)
return this
}
removeReporter (reporter) {
if (reporter) {
const i = this._reporters.indexOf(reporter)
if (i >= 0) {
return this._reporters.splice(i, 1)
}
} else {
this._reporters.splice(0)
}
return this
}
setReporters (reporters) {
this._reporters = Array.isArray(reporters)
? reporters
: [reporters]
return this
}
wrapAll () {
this.wrapConsole()
this.wrapStd()
}
restoreAll () {
this.restoreConsole()
this.restoreStd()
}
wrapConsole () {
for (const type in this._types) {
// Backup original value
if (!console['__' + type]) { // eslint-disable-line no-console
console['__' + type] = console[type] // eslint-disable-line no-console
}
// Override
console[type] = this[type].raw // eslint-disable-line no-console
}
}
restoreConsole () {
for (const type in this._types) {
// Restore if backup is available
if (console['__' + type]) { // eslint-disable-line no-console
console[type] = console['__' + type] // eslint-disable-line no-console
delete console['__' + type] // eslint-disable-line no-console
}
}
}
wrapStd () {
this._wrapStream(this.stdout, 'log')
this._wrapStream(this.stderr, 'log')
}
_wrapStream (stream, type) {
if (!stream) {
return
}
// Backup original value
if (!stream.__write) {
stream.__write = stream.write
}
// Override
stream.write = (data) => {
this[type].raw(String(data).trim())
}
}
restoreStd () {
this._restoreStream(this.stdout)
this._restoreStream(this.stderr)
}
_restoreStream (stream) {
if (!stream) {
return
}
if (stream.__write) {
stream.write = stream.__write
delete stream.__write
}
}
pauseLogs () {
paused = true
}
resumeLogs () {
paused = false
// Process queue
const _queue = queue.splice(0)
for (const item of _queue) {
item[0]._logFn(item[1], item[2])
}
}
mockTypes (mockFn) {
this._mockFn = mockFn || this._mockFn
if (typeof this._mockFn !== 'function') {
return
}
for (const type in this._types) {
this[type] = this._mockFn(type, this._types[type]) || this[type]
this[type].raw = this[type]
}
}
_wrapLogFn (defaults, isRaw) {
return (...args) => {
if (paused) {
queue.push([this, defaults, args, isRaw])
return
}
return this._logFn(defaults, args, isRaw)
}
}
_logFn (defaults, args, isRaw) {
if (defaults.level > this.level) {
return this._async ? Promise.resolve(false) : false
}
// Construct a new log object
const logObj = Object.assign({
date: new Date(),
args: []
}, defaults)
// Consume arguments
if (!isRaw && args.length === 1 && isLogObj(args[0])) {
Object.assign(logObj, args[0])
} else {
logObj.args = Array.from(args)
}
// Aliases
if (logObj.message) {
logObj.args.unshift(logObj.message)
delete logObj.message
}
if (logObj.additional) {
if (!Array.isArray(logObj.additional)) {
logObj.additional = logObj.additional.split('\n')
}
logObj.args.push('\n' + logObj.additional.join('\n'))
delete logObj.additional
}
// Normalize type and tag to lowercase
logObj.type = typeof logObj.type === 'string' ? logObj.type.toLowerCase() : ''
logObj.tag = typeof logObj.tag === 'string' ? logObj.tag.toLowerCase() : ''
// Resolve log
/**
* @param newLog false if the throttle expired and
* we don't want to log a duplicate
*/
const resolveLog = (newLog = false) => {
const repeated = this._lastLogCount - this._throttleMin
if (this._lastLog && repeated > 0) {
const args = [...this._lastLog.args]
if (repeated > 1) {
args.push(`(repeated ${repeated} times)`)
}
this._log({ ...this._lastLog, args })
this._lastLogCount = 1
}
// Log
if (newLog) {
this._lastLog = logObj
if (this._async) {
return this._logAsync(logObj)
} else {
this._log(logObj)
}
}
}
// Throttle
clearTimeout(this._throttleTimeout)
const diffTime = this._lastLogTime ? logObj.date - this._lastLogTime : 0
this._lastLogTime = logObj.date
if (diffTime < this._throttle) {
try {
const serializedLog = JSON.stringify([logObj.type, logObj.tag, logObj.args])
const isSameLog = this._lastLogSerialized === serializedLog
this._lastLogSerialized = serializedLog
if (isSameLog) {
this._lastLogCount++
if (this._lastLogCount > this._throttleMin) {
// Auto-resolve when throttle is timed out
this._throttleTimeout = setTimeout(resolveLog, this._throttle)
return // SPAM!
}
}
} catch (_) {
// Circular References
}
}
resolveLog(true)
}
_log (logObj) {
for (const reporter of this._reporters) {
reporter.log(logObj, {
async: false,
stdout: this.stdout,
stderr: this.stderr
})
}
}
_logAsync (logObj) {
return Promise.all(
this._reporters.map(reporter => reporter.log(logObj, {
async: true,
stdout: this.stdout,
stderr: this.stderr
}))
)
}
}
// Legacy support
Consola.prototype.add = Consola.prototype.addReporter
Consola.prototype.remove = Consola.prototype.removeReporter
Consola.prototype.clear = Consola.prototype.removeReporter
Consola.prototype.withScope = Consola.prototype.withTag
Consola.prototype.mock = Consola.prototype.mockTypes
Consola.prototype.pause = Consola.prototype.pauseLogs
Consola.prototype.resume = Consola.prototype.resumeLogs
// Export class
export default Consola

7
node_modules/consola/src/index.js generated vendored Normal file
View File

@@ -0,0 +1,7 @@
export { default as Consola } from './consola'
export { default as Types } from './types'
export { LogLevel } from './logLevels'
export { isLogObj } from './utils'
export { assignGlobalConsola } from './utils/global'
export * from './reporters'

11
node_modules/consola/src/logLevels.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
export const LogLevel = {}
LogLevel[LogLevel.Fatal = 0] = 'Fatal'
LogLevel[LogLevel.Error = 0] = 'Error'
LogLevel[LogLevel.Warn = 1] = 'Warn'
LogLevel[LogLevel.Log = 2] = 'Log'
LogLevel[LogLevel.Info = 3] = 'Info'
LogLevel[LogLevel.Success = 3] = 'Success'
LogLevel[LogLevel.Debug = 4] = 'Debug'
LogLevel[LogLevel.Trace = 5] = 'Trace'
LogLevel[LogLevel.Silent = -Infinity] = 'Silent'
LogLevel[LogLevel.Verbose = Infinity] = 'Verbose'

36
node_modules/consola/src/node.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
import env from 'std-env'
import { Consola, BasicReporter, FancyReporter, JSONReporter, WinstonReporter, LogLevel } from '.'
function createConsola () {
// Log level
let level = env.debug ? 4 : 3
if (process.env.CONSOLA_LEVEL) {
level = parseInt(process.env.CONSOLA_LEVEL) || level
}
// Create new consola instance
const consola = new Consola({
level,
reporters: [
(env.ci || env.test)
? new BasicReporter()
: new FancyReporter()
]
})
// Expose constructors
consola.Consola = Consola
consola.BasicReporter = BasicReporter
consola.FancyReporter = FancyReporter
consola.JSONReporter = JSONReporter
consola.WinstonReporter = WinstonReporter
consola.LogLevel = LogLevel
return consola
}
if (!global.consola) {
global.consola = createConsola()
}
export default global.consola

72
node_modules/consola/src/reporters/basic.js generated vendored Normal file
View File

@@ -0,0 +1,72 @@
import util from 'util'
import { parseStack } from '../utils/error'
import { writeStream } from '../utils/stream'
import { formatDate } from '../utils/date'
const DEFAULTS = {
dateFormat: 'HH:mm:ss',
formatOptions: {
date: true,
colors: false,
compact: true
}
}
const bracket = x => x ? `[${x}]` : ''
export default class BasicReporter {
constructor (options) {
this.options = Object.assign({}, DEFAULTS, options)
}
formatStack (stack) {
return ' ' + parseStack(stack).join('\n ')
}
formatArgs (args) {
const _args = args.map(arg => {
if (arg && typeof arg.stack === 'string') {
return arg.message + '\n' + this.formatStack(arg.stack)
}
return arg
})
// Only supported with Node >= 10
// https://nodejs.org/api/util.html#util_util_inspect_object_options
if (typeof util.formatWithOptions === 'function') {
return util.formatWithOptions(this.options.formatOptions, ..._args)
} else {
return util.format(..._args)
}
}
formatDate (date) {
return this.options.formatOptions.date ? formatDate(this.options.dateFormat, date) : ''
}
filterAndJoin (arr) {
return arr.filter(x => x).join(' ')
}
formatLogObj (logObj) {
const message = this.formatArgs(logObj.args)
return this.filterAndJoin([
bracket(logObj.type),
bracket(logObj.tag),
message
])
}
log (logObj, { async, stdout, stderr } = {}) {
const line = this.formatLogObj(logObj, {
width: stdout.columns || 0
})
return writeStream(
line + '\n',
logObj.level < 2 ? stderr : stdout,
async ? 'async' : 'default'
)
}
}

54
node_modules/consola/src/reporters/browser.js generated vendored Normal file
View File

@@ -0,0 +1,54 @@
export default class BrowserReporter {
constructor (options) {
this.options = Object.assign({}, options)
this.defaultColor = '#7f8c8d' // Gray
this.levelColorMap = {
0: '#c0392b', // Red
1: '#f39c12', // Yellow
3: '#00BCD4' // Cyan
}
this.typeColorMap = {
success: '#2ecc71' // Green
}
}
log (logObj) {
const consoleLogFn = logObj.level < 1
// eslint-disable-next-line no-console
? (console.__error || console.error)
// eslint-disable-next-line no-console
: logObj.level === 1 && console.warn ? (console.__warn || console.warn) : (console.__log || console.log)
// Type
const type = logObj.type !== 'log' ? logObj.type : ''
// Tag
const tag = logObj.tag ? logObj.tag : ''
// Styles
const color = this.typeColorMap[logObj.type] || this.levelColorMap[logObj.level] || this.defaultColor
const style = `
background: ${color};
border-radius: 0.5em;
color: white;
font-weight: bold;
padding: 2px 0.5em;
`
const badge = `%c${[tag, type].filter(Boolean).join(':')}`
// Log to the console
if (typeof logObj.args[0] === 'string') {
consoleLogFn(
`${badge}%c ${logObj.args[0]}`,
style,
// Empty string as style resets to default console style
'',
...logObj.args.slice(1)
)
} else {
consoleLogFn(badge, style, ...logObj.args)
}
}
}

87
node_modules/consola/src/reporters/fancy.js generated vendored Normal file
View File

@@ -0,0 +1,87 @@
import stringWidth from 'string-width'
import figures from 'figures'
import chalk from 'chalk'
import BasicReporter from './basic'
import { parseStack } from '../utils/error'
import { chalkColor, chalkBgColor } from '../utils/chalk'
import { TYPE_COLOR_MAP, LEVEL_COLOR_MAP } from '../utils/fancy'
const DEFAULTS = {
secondaryColor: 'grey',
formatOptions: {
date: true,
colors: true,
compact: false
}
}
const TYPE_ICONS = {
info: figures(''),
success: figures('✔'),
debug: figures(''),
trace: figures(''),
log: ''
}
export default class FancyReporter extends BasicReporter {
constructor (options) {
super(Object.assign({}, DEFAULTS, options))
}
formatStack (stack) {
const grey = chalkColor('grey')
const cyan = chalkColor('cyan')
return '\n' + parseStack(stack)
.map(line => ' ' + line
.replace(/^at +/, m => grey(m))
.replace(/\((.+)\)/, (_, m) => `(${cyan(m)})`)
)
.join('\n')
}
formatType (logObj, isBadge) {
const typeColor = TYPE_COLOR_MAP[logObj.type] ||
LEVEL_COLOR_MAP[logObj.level] ||
this.options.secondaryColor
if (isBadge) {
return chalkBgColor(typeColor).black(` ${logObj.type.toUpperCase()} `)
}
const _type = typeof TYPE_ICONS[logObj.type] === 'string' ? TYPE_ICONS[logObj.type] : (logObj.icon || logObj.type)
return _type ? chalkColor(typeColor)(_type) : ''
}
formatLogObj (logObj, { width }) {
const [message, ...additional] = this.formatArgs(logObj.args).split('\n')
const isBadge = typeof logObj.badge !== 'undefined' ? Boolean(logObj.badge) : logObj.level < 2
const secondaryColor = chalkColor(this.options.secondaryColor)
const date = this.formatDate(logObj.date)
const coloredDate = date && secondaryColor(date)
const type = this.formatType(logObj, isBadge)
const tag = logObj.tag ? secondaryColor(logObj.tag) : ''
const formattedMessage = message.replace(/`([^`]+)`/g, (_, m) => chalk.cyan(m))
let line
const left = this.filterAndJoin([type, formattedMessage])
const right = this.filterAndJoin([tag, coloredDate])
const space = width - stringWidth(left) - stringWidth(right) - 2
if (space > 0 && width >= 80) {
line = left + ' '.repeat(space) + right
} else {
line = left
}
line += additional.length ? '\n' + additional.join('\n') : ''
return isBadge ? '\n' + line + '\n' : line
}
}

5
node_modules/consola/src/reporters/index.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
export { default as BasicReporter } from './basic'
export { default as BrowserReporter } from './browser'
export { default as FancyReporter } from './fancy'
export { default as JSONReporter } from './json'
export { default as WinstonReporter } from './winston'

9
node_modules/consola/src/reporters/json.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
export default class JSONReporter {
constructor ({ stream } = {}) {
this.stream = stream || process.stdout
}
log (logObj) {
this.stream.write(JSON.stringify(logObj) + '\n')
}
}

45
node_modules/consola/src/reporters/winston.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
// This reporter is compatible with Winston 3
// https://github.com/winstonjs/winston
// eslint-disable-next-line
const _require = typeof __non_webpack_require__ !== 'undefined' ? __non_webpack_require__ : require // bypass webpack
export default class WinstonReporter {
constructor (logger) {
if (logger && logger.log) {
this.logger = logger
} else {
const winston = _require('winston')
this.logger = winston.createLogger(Object.assign({
level: 'info',
format: winston.format.simple(),
transports: [
new winston.transports.Console()
]
}, logger))
}
}
log (logObj) {
const args = [].concat(logObj.args)
const arg0 = args.shift()
this.logger.log({
level: levels[logObj.level] || 'info',
label: logObj.tag,
message: arg0,
args: args,
timestamp: logObj.date.getTime() / 1000
})
}
}
const levels = {
0: 'error',
1: 'warn',
2: 'info',
3: 'verbose',
4: 'debug',
5: 'silly'
}

50
node_modules/consola/src/types.js generated vendored Normal file
View File

@@ -0,0 +1,50 @@
import { LogLevel } from './logLevels'
export default {
// Silent
silent: {
level: -1
},
// Level 0
fatal: {
level: LogLevel.Fatal
},
error: {
level: LogLevel.Error
},
// Level 1
warn: {
level: LogLevel.Warn
},
// Level 2
log: {
level: LogLevel.Log
},
// Level 3
info: {
level: LogLevel.Info
},
success: {
level: LogLevel.Success
},
// Level 4
debug: {
level: LogLevel.Debug
},
// Level 5
trace: {
level: LogLevel.Trace
},
// Verbose
verbose: {
level: LogLevel.Trace
},
// Legacy
ready: {
level: LogLevel.Info
},
start: {
level: LogLevel.Info
}
}

37
node_modules/consola/src/utils/chalk.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
import chalk from 'chalk'
const _colorCache = {}
export function chalkColor (name) {
let color = _colorCache[name]
if (color) {
return color
}
if (name[0] === '#') {
color = chalk.hex(name)
} else {
color = chalk[name] || chalk.keyword(name)
}
_colorCache[name] = color
return color
}
const _bgColorCache = {}
export function chalkBgColor (name) {
let color = _bgColorCache[name]
if (color) {
return color
}
if (name[0] === '#') {
color = chalk.bgHex(name)
} else {
color = chalk['bg' + name[0].toUpperCase() + name.slice(1)] || chalk.bgKeyword(name)
}
_bgColorCache[name] = color
return color
}

5
node_modules/consola/src/utils/date.js generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import dayjs from 'dayjs'
export function formatDate (timeFormat, date) {
return dayjs(date).format(timeFormat)
}

16
node_modules/consola/src/utils/error.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { sep } from 'path'
export function parseStack (stack) {
const cwd = process.cwd() + sep
const lines = stack
.split('\n')
.splice(1)
.map(l => l
.trim()
.replace('file://', '')
.replace(cwd, '')
)
return lines
}

10
node_modules/consola/src/utils/fancy.js generated vendored Normal file
View File

@@ -0,0 +1,10 @@
export const TYPE_COLOR_MAP = {
info: 'cyan'
}
export const LEVEL_COLOR_MAP = {
0: 'red',
1: 'yellow',
2: 'white',
3: 'green'
}

30
node_modules/consola/src/utils/format.js generated vendored Normal file
View File

@@ -0,0 +1,30 @@
import { vsprintf } from 'printj'
const FORMAT_ARGS = [
['additional', 5],
['message', 4],
['type', 2],
['date', 1],
['tag', 3]
] // .sort((a, b) => b[0].length - a[0].length)
const _compileCache = {}
// process.on('beforeExit', () => { console.log(_compileCache) })
export function compileFormat (format) {
if (_compileCache[format]) {
return _compileCache[format]
}
let _format = format
for (const arg of FORMAT_ARGS) {
_format = _format.replace(new RegExp('([%-])' + arg[0], 'g'), '$1' + arg[1])
}
_compileCache[format] = _format
return _format
}
export function formatString (format, argv) {
return vsprintf(compileFormat(format), argv)
}

38
node_modules/consola/src/utils/global.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
export function assignGlobalReference (newInstance, referenceKey) {
if (!newInstance.constructor || (global[referenceKey] && !global[referenceKey].constructor)) {
throw new Error('Assigning to global reference is only supported for class instances')
} else if (newInstance.constructor && !global[referenceKey]) {
global[referenceKey] = newInstance
} else if (!(
newInstance instanceof global[referenceKey].constructor ||
global[referenceKey] instanceof newInstance.constructor
)) {
throw new Error(`Not a ${global[referenceKey].constructor.name} instance`)
}
const oldInstance = Object.create(global[referenceKey])
for (const prop in global[referenceKey]) {
oldInstance[prop] = global[referenceKey][prop]
delete global[referenceKey][prop]
}
for (const prop of Object.getOwnPropertySymbols(global[referenceKey])) {
oldInstance[prop] = global[referenceKey][prop]
delete global[referenceKey][prop]
}
for (const prop in newInstance) {
global[referenceKey][prop] = newInstance[prop]
}
for (const prop of Object.getOwnPropertySymbols(newInstance)) {
global[referenceKey][prop] = newInstance[prop]
}
return oldInstance
}
export function assignGlobalConsola (newConsola) {
return assignGlobalReference(newConsola, 'consola')
}

23
node_modules/consola/src/utils/index.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
export function isPlainObject (obj) {
return Object.prototype.toString.call(obj) === '[object Object]'
}
// TODO: remove for consola@3
export function isLogObj (arg) {
// Should be plain object
if (!isPlainObject(arg)) {
return false
}
// Should contains either 'message' or 'args' field
if (!arg.message && !arg.args) {
return false
}
// Handle non-standard error objects
if (arg.stack) {
return false
}
return true
}

20
node_modules/consola/src/utils/stream.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import { writeSync } from 'fs'
export function writeStream (data, stream, mode = 'default') {
const write = stream.__write || stream.write
switch (mode) {
case 'async':
return new Promise((resolve) => {
if (write.call(stream, data) === true) {
resolve()
} else {
stream.once('drain', () => { resolve() })
}
})
case 'sync':
return writeSync(stream.fd, data)
default:
return write.call(stream, data)
}
}

41
node_modules/consola/src/utils/string.js generated vendored Normal file
View File

@@ -0,0 +1,41 @@
export function centerAlign (str, len, space = ' ') {
const free = len - str.length
if (free <= 0) {
return str
}
const freeLeft = Math.floor(free / 2)
let _str = ''
for (let i = 0; i < len; i++) {
_str += (i < freeLeft || i >= freeLeft + str.length) ? space : str[i - freeLeft]
}
return _str
}
export function rightAlign (str, len, space = ' ') {
const free = len - str.length
if (free <= 0) {
return str
}
let _str = ''
for (let i = 0; i < len; i++) {
_str += i < free ? space : str[i - free]
}
return _str
}
export function leftAlign (str, len, space = ' ') {
let _str = ''
for (let i = 0; i < len; i++) {
_str += i < str.length ? str[i] : space
}
return _str
}
export function align (alignment, str, len, space = ' ') {
switch (alignment) {
case 'left': return leftAlign(str, len, space)
case 'right': return rightAlign(str, len, space)
case 'center': return centerAlign(str, len, space)
default: return str
}
}