-
-
Notifications
You must be signed in to change notification settings - Fork 934
/
index.ts
147 lines (136 loc) · 4.87 KB
/
index.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { Config } from '@pnpm/config'
import * as logs from '@pnpm/core-loggers'
import { LogLevel } from '@pnpm/logger'
import * as Rx from 'rxjs'
import { throttleTime } from 'rxjs/operators'
import { reportBigTarballProgress } from './reportBigTarballsProgress'
import { reportContext } from './reportContext'
import { reportExecutionTime } from './reportExecutionTime'
import { reportDeprecations } from './reportDeprecations'
import { reportHooks } from './reportHooks'
import { reportInstallChecks } from './reportInstallChecks'
import { reportLifecycleScripts } from './reportLifecycleScripts'
import { reportMisc, LOG_LEVEL_NUMBER } from './reportMisc'
import { reportPeerDependencyIssues } from './reportPeerDependencyIssues'
import { reportProgress } from './reportProgress'
import { reportRequestRetry } from './reportRequestRetry'
import { reportScope } from './reportScope'
import { reportSkippedOptionalDependencies } from './reportSkippedOptionalDependencies'
import { reportStats } from './reportStats'
import { reportSummary } from './reportSummary'
import { reportUpdateCheck } from './reportUpdateCheck'
const PRINT_EXECUTION_TIME_IN_COMMANDS = {
install: true,
update: true,
add: true,
remove: true,
}
export function reporterForClient (
log$: {
context: Rx.Observable<logs.ContextLog>
fetchingProgress: Rx.Observable<logs.FetchingProgressLog>
executionTime: Rx.Observable<logs.ExecutionTimeLog>
progress: Rx.Observable<logs.ProgressLog>
stage: Rx.Observable<logs.StageLog>
deprecation: Rx.Observable<logs.DeprecationLog>
summary: Rx.Observable<logs.SummaryLog>
lifecycle: Rx.Observable<logs.LifecycleLog>
stats: Rx.Observable<logs.StatsLog>
installCheck: Rx.Observable<logs.InstallCheckLog>
registry: Rx.Observable<logs.RegistryLog>
root: Rx.Observable<logs.RootLog>
packageManifest: Rx.Observable<logs.PackageManifestLog>
peerDependencyIssues: Rx.Observable<logs.PeerDependencyIssuesLog>
requestRetry: Rx.Observable<logs.RequestRetryLog>
link: Rx.Observable<logs.LinkLog>
other: Rx.Observable<logs.Log>
hook: Rx.Observable<logs.HookLog>
scope: Rx.Observable<logs.ScopeLog>
skippedOptionalDependency: Rx.Observable<logs.SkippedOptionalDependencyLog>
packageImportMethod: Rx.Observable<logs.PackageImportMethodLog>
updateCheck: Rx.Observable<logs.UpdateCheckLog>
},
opts: {
appendOnly?: boolean
cmd: string
config?: Config
env: NodeJS.ProcessEnv
process: NodeJS.Process
isRecursive: boolean
logLevel?: LogLevel
pnpmConfig?: Config
streamLifecycleOutput?: boolean
aggregateOutput?: boolean
throttleProgress?: number
width?: number
}
): Array<Rx.Observable<Rx.Observable<{ msg: string }>>> {
const width = opts.width ?? process.stdout.columns ?? 80
const cwd = opts.pnpmConfig?.dir ?? process.cwd()
const throttle = typeof opts.throttleProgress === 'number' && opts.throttleProgress > 0
? throttleTime(opts.throttleProgress, undefined, { leading: true, trailing: true })
: undefined
const outputs: Array<Rx.Observable<Rx.Observable<{ msg: string }>>> = [
reportLifecycleScripts(log$, {
appendOnly: opts.appendOnly === true || opts.streamLifecycleOutput,
aggregateOutput: opts.aggregateOutput,
cwd,
width,
}),
reportMisc(
log$,
{
appendOnly: opts.appendOnly === true,
config: opts.config,
cwd,
logLevel: opts.logLevel,
zoomOutCurrent: opts.isRecursive,
}
),
reportInstallChecks(log$.installCheck, { cwd }),
reportScope(log$.scope, { isRecursive: opts.isRecursive, cmd: opts.cmd }),
reportSkippedOptionalDependencies(log$.skippedOptionalDependency, { cwd }),
reportHooks(log$.hook, { cwd, isRecursive: opts.isRecursive }),
reportUpdateCheck(log$.updateCheck, opts),
]
if (opts.cmd !== 'dlx') {
outputs.push(reportContext(log$, { cwd }))
}
if (PRINT_EXECUTION_TIME_IN_COMMANDS[opts.cmd]) {
outputs.push(reportExecutionTime(log$.executionTime))
}
// logLevelNumber: 0123 = error warn info debug
const logLevelNumber = LOG_LEVEL_NUMBER[opts.logLevel ?? 'info'] ?? LOG_LEVEL_NUMBER['info']
if (logLevelNumber >= LOG_LEVEL_NUMBER.warn) {
outputs.push(
reportPeerDependencyIssues(log$),
reportDeprecations(log$.deprecation, { cwd, isRecursive: opts.isRecursive }),
reportRequestRetry(log$.requestRetry)
)
}
if (logLevelNumber >= LOG_LEVEL_NUMBER.info) {
outputs.push(
reportProgress(log$, {
cwd,
throttle,
}),
...reportStats(log$, {
cmd: opts.cmd,
cwd,
isRecursive: opts.isRecursive,
width,
})
)
}
if (!opts.appendOnly) {
outputs.push(reportBigTarballProgress(log$))
}
if (!opts.isRecursive) {
outputs.push(reportSummary(log$, {
cwd,
env: opts.env,
pnpmConfig: opts.pnpmConfig,
}))
}
return outputs
}