/
reporterForServer.ts
40 lines (38 loc) · 1.08 KB
/
reporterForServer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { type Config } from '@pnpm/config'
import { type Log } from '@pnpm/core-loggers'
import type * as Rx from 'rxjs'
import chalk from 'chalk'
import { reportError } from './reportError'
export function reporterForServer (
log$: Rx.Observable<Log>,
config?: Config
) {
return log$.subscribe({
complete: () => undefined,
error: () => undefined,
next (log) {
if (log.name === 'pnpm:fetching-progress') {
console.log(`${chalk.cyan(`fetching_${log.status}`)} ${log.packageId}`)
return
}
switch (log.level) {
case 'warn':
console.log(formatWarn(log['message']))
return
case 'error':
console.log(reportError(log, config))
return
case 'debug':
return
default:
console.log(log['message'])
}
},
})
}
function formatWarn (message: string) {
// The \u2009 is the "thin space" unicode character
// It is used instead of ' ' because chalk (as of version 2.1.0)
// trims whitespace at the beginning
return `${chalk.bgYellow.black('\u2009WARN\u2009')} ${message}`
}