-
-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: print a summary about deprecated subdeps (#7090)
close #6707
- Loading branch information
Showing
4 changed files
with
94 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 31 additions & 11 deletions
42
cli/default-reporter/src/reporterForClient/reportDeprecations.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`)}`) | ||
}, | ||
}) | ||
}) |