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

Support the newer pino-pretty as well as the older in v6.x #1117

Merged
merged 1 commit into from Sep 6, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/tools.js
Expand Up @@ -180,7 +180,7 @@ function getPrettyStream (opts, prettifier, dest, instance) {
return prettifierMetaWrapper(prettifier(opts), dest, opts)
}
try {
const prettyFactory = require('pino-pretty')
const prettyFactory = require('pino-pretty').prettyFactory || require('pino-pretty')
prettyFactory.asMetaWrapper = prettifierMetaWrapper
return prettifierMetaWrapper(prettyFactory(opts), dest, opts)
} catch (e) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -76,7 +76,7 @@
"import-fresh": "^3.2.1",
"log": "^6.0.0",
"loglevel": "^1.6.7",
"pino-pretty": "^4.1.0",
"pino-pretty": "^5.0.0",
"pre-commit": "^1.2.2",
"proxyquire": "^2.1.3",
"pump": "^3.0.0",
Expand Down
16 changes: 15 additions & 1 deletion test/pretty.test.js
Expand Up @@ -54,12 +54,26 @@ test('throws when prettyPrint is true but pino-pretty module is not installed',
// pino pretty *is* installed, and probably also cached, so rather than
// messing with the filesystem the simplest way to generate a not found
// error is to simulate it:
const prettyFactory = require('pino-pretty')
const pinoPretty = require('pino-pretty')
require.cache[require.resolve('pino-pretty')].exports = () => {
throw Error('Cannot find module \'pino-pretty\'')
}
throws(() => pino({ prettyPrint: true }), 'Missing `pino-pretty` module: `pino-pretty` must be installed separately')
require.cache[require.resolve('pino-pretty')].exports = pinoPretty
})

test('support older pino-pretty', async ({ doesNotThrow }) => {
// pino pretty *is* installed, and probably also cached, so rather than
// messing with the filesystem the simplest way to generate a not found
// error is to simulate it:
const pinoPretty = require('pino-pretty')
const prettyFactory = pinoPretty.prettyFactory
pinoPretty.prettyFactory = undefined
require.cache[require.resolve('pino-pretty')].exports = prettyFactory

doesNotThrow(() => pino({ prettyPrint: true }))

delete require.cache[require.resolve('pino-pretty')]
})

test('throws when prettyPrint has invalid options', async ({ throws }) => {
Expand Down