提交 3b2b6982 编写于 作者: fxy060608's avatar fxy060608

chore: format logs

上级 a4d10805
import path from 'path'
process.env.UNI_HBUILDERX_PLUGINS =
process.env.UNI_HBUILDERX_PLUGINS ||
path.resolve(__dirname, '../../../../../../')
export * from './env'
export { initModuleAlias } from './alias'
import path from 'path'
import { normalizePath } from '../utils'
import { Formatter } from '../logs/format'
const SIGNAL_H5_LOCAL = ' > Local:'
......@@ -51,3 +53,41 @@ export const removeWarnFormatter: Formatter = {
return ''
},
}
const fileRE = /file:\s(.*):(\d+):(\d+)/
export const FilenameFormatter: Formatter = {
test(msg) {
return fileRE.test(msg)
},
format(msg) {
return msg.replace(fileRE, (_, filename, line, column) => {
return `file: ${filename.split('?')[0]}:${line}:${column}`
})
},
}
export const HBuilderXFileFormatter: Formatter = {
test(msg) {
return fileRE.test(msg)
},
format(msg) {
return (
msg
// remove color
.replace(/\x1B[[(?);]{0,2}(;?\d)*./g, '')
.replace(fileRE, (_, filename, line, column) => {
return (
'at ' +
normalizePath(
path.relative(process.env.UNI_INPUT_DIR, filename.split('?')[0])
) +
':' +
line +
':' +
column
)
})
)
},
}
import { once } from '@dcloudio/uni-shared'
import { isInHBuilderX } from '../hbx/env'
import { isInHBuilderX, runByHBuilderX } from '../hbx/env'
import { moduleAliasFormatter } from '../hbx/alias'
import {
h5ServeFormatter,
removeInfoFormatter,
removeWarnFormatter,
FilenameFormatter,
HBuilderXFileFormatter,
} from '../hbx/log'
export interface Formatter {
......@@ -21,6 +23,11 @@ const initErrFormattersOnce = once(() => {
if (isInHBuilderX()) {
errFormatters.push(moduleAliasFormatter)
}
if (runByHBuilderX()) {
errFormatters.push(HBuilderXFileFormatter)
} else {
errFormatters.push(FilenameFormatter)
}
})
const initInfoFormattersOnce = once(() => {
......
......@@ -41,7 +41,6 @@ export const transformIdentifier: NodeTransform = (node, context) => {
const { props } = node
let hasClassBinding = false
let hasStyleBinding = false
debugger
for (let i = 0; i < props.length; i++) {
const dir = props[i]
if (dir.type === NodeTypes.DIRECTIVE) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册