Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(default-reporter): use loglevel to filter deprecation warnings (#4343) #4507

Merged
merged 8 commits into from Apr 17, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
35 changes: 23 additions & 12 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,13 @@ 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 +81,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 +90,28 @@ 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(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
35 changes: 35 additions & 0 deletions packages/default-reporter/test/index.ts
Expand Up @@ -210,6 +210,41 @@ ${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(),
})

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