Skip to content

Commit

Permalink
Allow loading common js config files by default (#282)
Browse files Browse the repository at this point in the history
* Allow loading cjs files as config by default

* Remove redundant joycon loader
  • Loading branch information
EchelonFour committed Dec 13, 2021
1 parent fd1308e commit 4ec29b2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
5 changes: 1 addition & 4 deletions bin.js
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ const parseJSON = input => {
const joycon = new JoyCon({
parseJSON,
files: [
'pino-pretty.config.cjs',
'pino-pretty.config.js',
'.pino-prettyrc',
'.pino-prettyrc.json'
],
stopDir: path.dirname(process.cwd())
})
joycon.addLoader({
test: /\.[^.]*rc$/,
loadSync: (path) => parseJSON(fs.readFileSync(path, 'utf-8'))
})

args
.option(['c', 'colorize'], 'Force adding color sequences to the output')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"colorette": "^2.0.7",
"dateformat": "^4.6.3",
"fast-safe-stringify": "^2.0.7",
"joycon": "^3.0.0",
"joycon": "^3.1.1",
"pino-abstract-transport": "^0.5.0",
"pump": "^3.0.0",
"readable-stream": "^3.6.0",
Expand Down
23 changes: 23 additions & 0 deletions test/cli-rc.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,29 @@ test('cli', (t) => {
})
})

t.test('loads and applies default config file: pino-pretty.config.cjs', (t) => {
t.plan(1)
// Set translateTime: true on run configuration
const configFile = path.join(tmpDir, 'pino-pretty.config.cjs')
fs.writeFileSync(configFile, 'module.exports = { translateTime: true }')
// Tell the loader to expect ESM modules
const packageJsonFile = path.join(tmpDir, 'package.json')
fs.writeFileSync(packageJsonFile, JSON.stringify({ type: 'module' }, null, 4))
const env = { TERM: 'dumb' }
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })
// Validate that the time has been translated
child.on('error', t.threw)
child.stdout.on('data', (data) => {
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
})
child.stdin.write(logLine)
t.teardown(() => {
fs.unlinkSync(configFile)
fs.unlinkSync(packageJsonFile)
child.kill()
})
})

t.test('loads and applies default config file: .pino-prettyrc', (t) => {
t.plan(1)
// Set translateTime: true on run configuration
Expand Down

0 comments on commit 4ec29b2

Please sign in to comment.