-
-
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
close #6707
- Loading branch information
Showing
2 changed files
with
35 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
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: `${chalk.red('deprecated subdeps')}: ${deprecatedSubdeps.map(log => `${log.pkgName}@${log.pkgVersion}`).join(', ')}`, | ||
})) | ||
} | ||
return Rx.EMPTY | ||
}) | ||
) | ||
) | ||
} |