提交 01ca3b8f 编写于 作者: 雪洛's avatar 雪洛

fix: ssr url order

上级 51427a3f
......@@ -17,6 +17,45 @@ const SIGNAL_H5_NETWORK = ' ➜ Network:'
const networkLogs: string[] = []
const ZERO_WIDTH_CHAR = {
NOTE: '',
WARNING: '\u200B',
ERROR: '\u200C',
backup0: '\u200D',
backup1: '\u200E',
backup2: '\u200F',
backup3: '\uFEFF',
} as const
type ZERO_WIDTH_CHAR_KEY = keyof typeof ZERO_WIDTH_CHAR
type ConsoleMethod = 'warn' | 'error'
function overridedConsole(
name: ConsoleMethod,
oldFn: (...args: any[]) => any,
char: typeof ZERO_WIDTH_CHAR[ZERO_WIDTH_CHAR_KEY]
) {
console[name] = function (...args) {
oldFn.apply(
this,
args.map((arg) => {
let item
if (typeof arg !== 'object') {
item = `${char}${arg}${char}`
} else {
item = `${char}${JSON.stringify(arg)}${char}`
}
return item
})
)
}
}
if (typeof console !== 'undefined') {
overridedConsole('warn', console.warn, ZERO_WIDTH_CHAR.WARNING)
// overridedConsole('error', console.error, ZERO_WIDTH_CHAR.ERROR)
}
export function formatAtFilename(
filename: string,
line?: number,
......@@ -39,7 +78,7 @@ export const h5ServeFormatter: Formatter = {
},
format(msg) {
if (msg.includes(SIGNAL_H5_NETWORK)) {
networkLogs.push(msg.replace('', ''))
networkLogs.push(msg.replace('', '*'))
process.nextTick(() => {
if (networkLogs.length) {
// 延迟打印所有 network,仅最后一个 network 替换 ➜ 为 -,通知 hbx
......@@ -51,7 +90,7 @@ export const h5ServeFormatter: Formatter = {
})
return ''
}
return msg.replace('', '-')
return msg.replace('', '*')
},
}
......
......@@ -204,11 +204,14 @@ function printServerUrls(
.map((detail) => {
const type = detail.address.includes('127.0.0.1')
? ' - Local: '
: ' Network: '
: ' - Network: '
const host = detail.address.replace('127.0.0.1', hostname.name)
const url = `${protocol}://${host}:${colors.bold(port)}${base}`
return `${type} ${colors.cyan(url)}`
})
.sort((msg1) => {
return msg1.indexOf('- Local') > -1 ? -1 : 1
})
.forEach((msg, index, arr) => {
if (arr.length - 1 === index) {
info(msg.replace('', '-'))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册