Skip to content

Commit

Permalink
feat: print a summary about deprecated subdeps (#7090)
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 61b9ca1
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 12 deletions.
6 changes: 6 additions & 0 deletions .changeset/unlucky-starfishes-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/default-reporter": patch
"pnpm": patch
---

Don't print out each deprecated subdependency separately with its deprecation message. Just print out a summary of all the deprecated subdependencies [#6707](https://github.com/pnpm/pnpm/issues/6707).
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: formatWarn(`${chalk.red(`${deprecatedSubdeps.length} deprecated subdependencies found:`)} ${deprecatedSubdeps.map(log => `${log.pkgName}@${log.pkgVersion}`).sort().join(', ')}`),
}))
}
return Rx.EMPTY
})
)
)
}
53 changes: 53 additions & 0 deletions cli/default-reporter/test/reportingDeprecations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { type Config } from '@pnpm/config'
import {
deprecationLogger,
stageLogger,
} from '@pnpm/core-loggers'
import { toOutput$ } from '@pnpm/default-reporter'
import { createStreamParser } from '@pnpm/logger'
import { map, take } from 'rxjs/operators'
import chalk from 'chalk'
import normalizeNewline from 'normalize-newline'
import { formatWarn } from '../src/reporterForClient/utils/formatWarn'

test('prints summary of deprecated subdependencies', (done) => {
const prefix = '/home/jane/project'
const output$ = toOutput$({
context: {
argv: ['install'],
config: { dir: prefix } as Config,
},
streamParser: createStreamParser(),
})

deprecationLogger.debug({
deprecated: 'This package was deprecated because bla bla bla',
depth: 1,
pkgId: 'registry.npmjs.org/bar/2.0.0',
pkgName: 'bar',
pkgVersion: '2.0.0',
prefix,
})
deprecationLogger.debug({
deprecated: 'This package was deprecated because bla bla bla',
depth: 2,
pkgId: 'registry.npmjs.org/qar/3.0.0',
pkgName: 'qar',
pkgVersion: '3.0.0',
prefix,
})
stageLogger.debug({
prefix,
stage: 'resolution_done',
})

expect.assertions(1)

output$.pipe(take(1), map(normalizeNewline)).subscribe({
complete: () => done(),
error: done,
next: output => {
expect(output).toBe(`${formatWarn(`${chalk.red('2 deprecated subdependencies found:')} bar@2.0.0, qar@3.0.0`)}`)
},
})
})

0 comments on commit 61b9ca1

Please sign in to comment.