Skip to content

Commit 4ec29b2

Browse files
authoredDec 13, 2021
Allow loading common js config files by default (#282)
* Allow loading cjs files as config by default * Remove redundant joycon loader
1 parent fd1308e commit 4ec29b2

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed
 

‎bin.js

100755100644
+1-4
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ const parseJSON = input => {
1919
const joycon = new JoyCon({
2020
parseJSON,
2121
files: [
22+
'pino-pretty.config.cjs',
2223
'pino-pretty.config.js',
2324
'.pino-prettyrc',
2425
'.pino-prettyrc.json'
2526
],
2627
stopDir: path.dirname(process.cwd())
2728
})
28-
joycon.addLoader({
29-
test: /\.[^.]*rc$/,
30-
loadSync: (path) => parseJSON(fs.readFileSync(path, 'utf-8'))
31-
})
3229

3330
args
3431
.option(['c', 'colorize'], 'Force adding color sequences to the output')

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"colorette": "^2.0.7",
3737
"dateformat": "^4.6.3",
3838
"fast-safe-stringify": "^2.0.7",
39-
"joycon": "^3.0.0",
39+
"joycon": "^3.1.1",
4040
"pino-abstract-transport": "^0.5.0",
4141
"pump": "^3.0.0",
4242
"readable-stream": "^3.6.0",

‎test/cli-rc.test.js

+23
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,29 @@ test('cli', (t) => {
3535
})
3636
})
3737

38+
t.test('loads and applies default config file: pino-pretty.config.cjs', (t) => {
39+
t.plan(1)
40+
// Set translateTime: true on run configuration
41+
const configFile = path.join(tmpDir, 'pino-pretty.config.cjs')
42+
fs.writeFileSync(configFile, 'module.exports = { translateTime: true }')
43+
// Tell the loader to expect ESM modules
44+
const packageJsonFile = path.join(tmpDir, 'package.json')
45+
fs.writeFileSync(packageJsonFile, JSON.stringify({ type: 'module' }, null, 4))
46+
const env = { TERM: 'dumb' }
47+
const child = spawn(process.argv[0], [bin], { env, cwd: tmpDir })
48+
// Validate that the time has been translated
49+
child.on('error', t.threw)
50+
child.stdout.on('data', (data) => {
51+
t.equal(data.toString(), '[2018-03-30 17:35:28.992 +0000] INFO (42 on foo): hello world\n')
52+
})
53+
child.stdin.write(logLine)
54+
t.teardown(() => {
55+
fs.unlinkSync(configFile)
56+
fs.unlinkSync(packageJsonFile)
57+
child.kill()
58+
})
59+
})
60+
3861
t.test('loads and applies default config file: .pino-prettyrc', (t) => {
3962
t.plan(1)
4063
// Set translateTime: true on run configuration

0 commit comments

Comments
 (0)
Please sign in to comment.