Skip to content

Commit

Permalink
feat: print a summary about deprecated subdeps
Browse files Browse the repository at this point in the history
close #6707
  • Loading branch information
zkochan committed Sep 14, 2023
1 parent 3ed5a7c commit 8a81537
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
5 changes: 4 additions & 1 deletion cli/default-reporter/src/reporterForClient/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ export function reporterForClient (
if (logLevelNumber >= LOG_LEVEL_NUMBER.warn) {
outputs.push(
reportPeerDependencyIssues(log$),
reportDeprecations(log$.deprecation, { cwd, isRecursive: opts.isRecursive }),
reportDeprecations({
deprecation: log$.deprecation,
stage: log$.stage,
}, { cwd, isRecursive: opts.isRecursive }),
reportRequestRetry(log$.requestRetry)
)
}
Expand Down
42 changes: 31 additions & 11 deletions cli/default-reporter/src/reporterForClient/reportDeprecations.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,47 @@
import { type DeprecationLog } from '@pnpm/core-loggers'
import { type DeprecationLog, type StageLog } from '@pnpm/core-loggers'
import * as Rx from 'rxjs'
import { map } from 'rxjs/operators'
import { map, filter, buffer, switchMap } from 'rxjs/operators'
import chalk from 'chalk'
import { formatWarn } from './utils/formatWarn'
import { zoomOut } from './utils/zooming'

export function reportDeprecations (
deprecation$: Rx.Observable<DeprecationLog>,
log$: {
deprecation: Rx.Observable<DeprecationLog>
stage: Rx.Observable<StageLog>
},
opts: {
cwd: string
isRecursive: boolean
}
) {
return deprecation$.pipe(
map((log) => {
if (!opts.isRecursive && log.prefix === opts.cwd) {
const [deprecatedDirectDeps$, deprecatedSubdeps$] = Rx.partition(log$.deprecation, (log) => log.depth === 0)
const resolutionDone$ = log$.stage.pipe(
filter((log) => log.stage === 'resolution_done')
)
return Rx.merge(
deprecatedDirectDeps$.pipe(
map((log) => {
if (!opts.isRecursive && log.prefix === opts.cwd) {
return Rx.of({
msg: formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}: ${log.deprecated}`),
})
}
return Rx.of({
msg: formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}: ${log.deprecated}`),
msg: zoomOut(opts.cwd, log.prefix, formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}`)),
})
}
return Rx.of({
msg: zoomOut(opts.cwd, log.prefix, formatWarn(`${chalk.red('deprecated')} ${log.pkgName}@${log.pkgVersion}`)),
})
})
),
deprecatedSubdeps$.pipe(
buffer(resolutionDone$),
switchMap(deprecatedSubdeps => {
if (deprecatedSubdeps.length > 0) {
return Rx.of(Rx.of({
msg: `${chalk.red('deprecated subdeps')}: ${deprecatedSubdeps.map(log => `${log.pkgName}@${log.pkgVersion}`).join(', ')}`,
}))
}
return Rx.EMPTY
})
)
)
}

0 comments on commit 8a81537

Please sign in to comment.