Skip to content

Commit

Permalink
fix(default-reporter): use loglevel to filter deprecation warnings (#…
Browse files Browse the repository at this point in the history
…4507)

close #4343

Co-authored-by: Zoltan Kochan <z@kochan.io>
  • Loading branch information
milahu and zkochan committed Apr 17, 2022
1 parent 870f55e commit 1f739b3
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .changeset/thirty-pigs-jump.md
@@ -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.
39 changes: 26 additions & 13 deletions packages/default-reporter/src/reporterForClient/index.ts
Expand Up @@ -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'
Expand Down Expand Up @@ -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$,
{
Expand All @@ -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 }),
Expand All @@ -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$))
}
Expand Down
Expand Up @@ -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,
Expand Down
61 changes: 61 additions & 0 deletions packages/default-reporter/test/index.ts
Expand Up @@ -5,6 +5,7 @@ import {
deprecationLogger,
hookLogger,
packageManifestLogger,
peerDependencyIssuesLogger,
rootLogger,
skippedOptionalDependencyLogger,
statsLogger,
Expand Down Expand Up @@ -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$({
Expand Down

0 comments on commit 1f739b3

Please sign in to comment.