mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
6
.changeset/unlucky-starfishes-exercise.md
Normal file
6
.changeset/unlucky-starfishes-exercise.md
Normal file
@@ -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).
|
||||
@@ -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)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
cli/default-reporter/test/reportingDeprecations.ts
Normal file
53
cli/default-reporter/test/reportingDeprecations.ts
Normal file
@@ -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`)}`)
|
||||
},
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user