mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
fix(default-reporter): use loglevel to filter deprecation warnings (#4507)
close #4343 Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
8
.changeset/thirty-pigs-jump.md
Normal file
8
.changeset/thirty-pigs-jump.md
Normal file
@@ -0,0 +1,8 @@
|
||||
---
|
||||
"@pnpm/default-reporter": patch
|
||||
"pnpm": patch
|
||||
---
|
||||
|
||||
Hide "WARN deprecated" messages on loglevel error [#4507](https://github.com/pnpm/pnpm/pull/4507)
|
||||
|
||||
Don't show the progress bar when loglevel is set to warn or error.
|
||||
@@ -9,7 +9,7 @@ import reportDeprecations from './reportDeprecations'
|
||||
import reportHooks from './reportHooks'
|
||||
import reportInstallChecks from './reportInstallChecks'
|
||||
import reportLifecycleScripts from './reportLifecycleScripts'
|
||||
import reportMisc from './reportMisc'
|
||||
import reportMisc, { LOG_LEVEL_NUMBER } from './reportMisc'
|
||||
import reportPeerDependencyIssues from './reportPeerDependencyIssues'
|
||||
import reportProgress from './reportProgress'
|
||||
import reportRequestRetry from './reportRequestRetry'
|
||||
@@ -64,18 +64,12 @@ export default function (
|
||||
: undefined
|
||||
|
||||
const outputs: Array<Rx.Observable<Rx.Observable<{msg: string}>>> = [
|
||||
reportProgress(log$, {
|
||||
cwd,
|
||||
throttle,
|
||||
}),
|
||||
reportPeerDependencyIssues(log$),
|
||||
reportLifecycleScripts(log$, {
|
||||
appendOnly: opts.appendOnly === true || opts.streamLifecycleOutput,
|
||||
aggregateOutput: opts.aggregateOutput,
|
||||
cwd,
|
||||
width,
|
||||
}),
|
||||
reportDeprecations(log$.deprecation, { cwd, isRecursive: opts.isRecursive }),
|
||||
reportMisc(
|
||||
log$,
|
||||
{
|
||||
@@ -86,12 +80,6 @@ export default function (
|
||||
zoomOutCurrent: opts.isRecursive,
|
||||
}
|
||||
),
|
||||
...reportStats(log$, {
|
||||
cmd: opts.cmd,
|
||||
cwd,
|
||||
isRecursive: opts.isRecursive,
|
||||
width,
|
||||
}),
|
||||
reportInstallChecks(log$.installCheck, { cwd }),
|
||||
reportRequestRetry(log$.requestRetry),
|
||||
reportScope(log$.scope, { isRecursive: opts.isRecursive, cmd: opts.cmd }),
|
||||
@@ -101,6 +89,31 @@ export default function (
|
||||
reportUpdateCheck(log$.updateCheck),
|
||||
]
|
||||
|
||||
// logLevelNumber: 0123 = error warn info debug
|
||||
const logLevelNumber = LOG_LEVEL_NUMBER[opts.logLevel ?? 'info'] ?? LOG_LEVEL_NUMBER['info']
|
||||
|
||||
if (logLevelNumber >= LOG_LEVEL_NUMBER.warn) {
|
||||
outputs.push(
|
||||
reportPeerDependencyIssues(log$),
|
||||
reportDeprecations(log$.deprecation, { cwd, isRecursive: opts.isRecursive })
|
||||
)
|
||||
}
|
||||
|
||||
if (logLevelNumber >= LOG_LEVEL_NUMBER.info) {
|
||||
outputs.push(
|
||||
reportProgress(log$, {
|
||||
cwd,
|
||||
throttle,
|
||||
}),
|
||||
...reportStats(log$, {
|
||||
cmd: opts.cmd,
|
||||
cwd,
|
||||
isRecursive: opts.isRecursive,
|
||||
width,
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
if (!opts.appendOnly) {
|
||||
outputs.push(reportBigTarballsProgress(log$))
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import formatWarn from './utils/formatWarn'
|
||||
import { autozoom } from './utils/zooming'
|
||||
|
||||
// eslint-disable:object-literal-sort-keys
|
||||
const LOG_LEVEL_NUMBER: Record<LogLevel, number> = {
|
||||
export const LOG_LEVEL_NUMBER: Record<LogLevel, number> = {
|
||||
error: 0,
|
||||
warn: 1,
|
||||
info: 2,
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
deprecationLogger,
|
||||
hookLogger,
|
||||
packageManifestLogger,
|
||||
peerDependencyIssuesLogger,
|
||||
rootLogger,
|
||||
skippedOptionalDependencyLogger,
|
||||
statsLogger,
|
||||
@@ -210,6 +211,66 @@ ${ADD} is-linked2 ${chalk.grey(`<- ${path.relative(prefix, '/src/is-linked2')}`)
|
||||
})
|
||||
})
|
||||
|
||||
test('does not print deprecation message when log level is set to error', (done) => {
|
||||
const prefix = '/home/jane/project'
|
||||
const output$ = toOutput$({
|
||||
context: {
|
||||
argv: ['install'],
|
||||
config: { dir: prefix } as Config,
|
||||
},
|
||||
reportingOptions: {
|
||||
logLevel: 'error',
|
||||
},
|
||||
streamParser: createStreamParser(),
|
||||
})
|
||||
|
||||
peerDependencyIssuesLogger.debug({
|
||||
issuesByProjects: {
|
||||
'.': {
|
||||
missing: {},
|
||||
bad: {
|
||||
a: [
|
||||
{
|
||||
parents: [
|
||||
{
|
||||
name: 'b',
|
||||
version: '1.0.0',
|
||||
},
|
||||
],
|
||||
foundVersion: '2',
|
||||
resolvedFrom: [],
|
||||
optional: false,
|
||||
wantedRange: '3',
|
||||
},
|
||||
],
|
||||
},
|
||||
conflicts: [],
|
||||
intersections: {},
|
||||
},
|
||||
},
|
||||
})
|
||||
deprecationLogger.debug({
|
||||
deprecated: 'This package was deprecated because bla bla bla',
|
||||
depth: 0,
|
||||
pkgId: 'registry.npmjs.org/bar/2.0.0',
|
||||
pkgName: 'bar',
|
||||
pkgVersion: '2.0.0',
|
||||
prefix,
|
||||
})
|
||||
const err = new PnpmError('SOME_CODE', 'some error')
|
||||
logger.error(err, err)
|
||||
|
||||
expect.assertions(1)
|
||||
|
||||
output$.pipe(take(1), map(normalizeNewline)).subscribe({
|
||||
complete: () => done(),
|
||||
error: done,
|
||||
next: output => {
|
||||
expect(output).toBe(formatError('ERR_PNPM_SOME_CODE', 'some error'))
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
test('prints summary for global installation', (done) => {
|
||||
const prefix = '/home/jane/.nvs/node/10.0.0/x64/pnpm-global/1'
|
||||
const output$ = toOutput$({
|
||||
|
||||
Reference in New Issue
Block a user