Skip to content

Commit f9ff378

Browse files
committed
Revert "wip(dom2): 优化错误日志与警告日志交叉"
This reverts commit 88d5510.
1 parent 88d5510 commit f9ff378

File tree

2 files changed

+21
-53
lines changed

2 files changed

+21
-53
lines changed

packages/uni-cli-shared/src/logs/index.ts

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -39,59 +39,35 @@ export interface CompileLogOptions {
3939
column?: number
4040
}
4141

42-
const suppressedCompileLogs: Array<() => void> = []
43-
44-
let isSuppressed = false
45-
46-
export function suppressVueCompileLog(suppressed: boolean) {
47-
isSuppressed = suppressed
48-
if (!suppressed) {
49-
suppressedCompileLogs.forEach((fn) => fn())
50-
suppressedCompileLogs.length = 0
51-
}
52-
}
53-
5442
export function onCompileLog(
5543
type: 'warn' | 'error',
5644
error: CompileLogError,
5745
code: string,
5846
relativeFileName: string,
5947
options?: CompileLogOptions
6048
) {
61-
if (isSuppressed) {
62-
// 不会导致内存泄漏吧?
63-
suppressedCompileLogs.push(print)
64-
return
65-
}
66-
print()
67-
function print() {
68-
const char =
69-
type === 'warn' ? SPECIAL_CHARS.WARN_BLOCK : SPECIAL_CHARS.ERROR_BLOCK
70-
if (options?.plugin) {
71-
// CSS 插件格式
72-
const colorFn = type === 'warn' ? colors.yellow : (s: string) => s
73-
console[type](
74-
char + colorFn(`[plugin:${options.plugin}] ${error.message}`)
75-
)
76-
let msg = formatAtFilename(relativeFileName, options.line, options.column)
77-
if (options.line && options.column) {
78-
msg += `\n${generateCodeFrame(code, {
79-
line: options.line,
80-
column: options.column,
81-
}).replace(/\t/g, ' ')}\n`
82-
}
83-
console.log(msg + char)
84-
} else {
85-
console[type](
86-
char + type + ': ' + error.message + (error.loc ? '' : char)
49+
const char =
50+
type === 'warn' ? SPECIAL_CHARS.WARN_BLOCK : SPECIAL_CHARS.ERROR_BLOCK
51+
if (options?.plugin) {
52+
// CSS 插件格式
53+
const colorFn = type === 'warn' ? colors.yellow : (s: string) => s
54+
console[type](char + colorFn(`[plugin:${options.plugin}] ${error.message}`))
55+
let msg = formatAtFilename(relativeFileName, options.line, options.column)
56+
if (options.line && options.column) {
57+
msg += `\n${generateCodeFrame(code, {
58+
line: options.line,
59+
column: options.column,
60+
}).replace(/\t/g, ' ')}\n`
61+
}
62+
console.log(msg + char)
63+
} else {
64+
console[type](char + type + ': ' + error.message + (error.loc ? '' : char))
65+
if (error.loc) {
66+
const start = error.loc.start
67+
console.log(
68+
'at ' + relativeFileName + ':' + start.line + ':' + start.column
8769
)
88-
if (error.loc) {
89-
const start = error.loc.start
90-
console.log(
91-
'at ' + relativeFileName + ':' + start.line + ':' + start.column
92-
)
93-
console.log(generateCodeFrameColumns(code, error.loc) + char)
94-
}
70+
console.log(generateCodeFrameColumns(code, error.loc) + char)
9571
}
9672
}
9773
}

packages/vite-plugin-uni/src/cli/action.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
isInHBuilderX,
1111
output,
1212
runByHBuilderX,
13-
suppressVueCompileLog,
1413
} from '@dcloudio/uni-cli-shared'
1514
import type { CliOptions } from '.'
1615
import { build, buildSSR } from './build'
@@ -53,12 +52,8 @@ export async function runDev(options: CliOptions & ServerOptions) {
5352
initEasycom()
5453
let isFirstStart = true
5554
let isFirstEnd = true
56-
const isDom2 = process.env.UNI_APP_X_DOM2 === 'true'
5755
await build(options, async (event) => {
5856
if (event.code === 'BUNDLE_START') {
59-
if (isDom2) {
60-
suppressVueCompileLog(false)
61-
}
6257
if (isFirstStart) {
6358
isFirstStart = false
6459
return
@@ -151,9 +146,6 @@ export async function runDev(options: CliOptions & ServerOptions) {
151146
}, 2000)
152147
}
153148
} else if (event.code === 'ERROR') {
154-
if (isDom2) {
155-
suppressVueCompileLog(true)
156-
}
157149
if (runByHBuilderX()) {
158150
setTimeout(() => {
159151
console.error(`Build failed with errors.`)

0 commit comments

Comments
 (0)