vite-plugin-purify 0.0.1-security → 2.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of vite-plugin-purify might be problematic. Click here for more details.
- package/.eslintignore +2 -0
- package/.eslintrc +8 -0
- package/.github/dependabot.yml +13 -0
- package/.github/workflows/bench.yml +61 -0
- package/.github/workflows/ci.yml +88 -0
- package/.github/workflows/lock-threads.yml +30 -0
- package/.github/workflows/target-main.yml +23 -0
- package/.nojekyll +0 -0
- package/.prettierignore +1 -0
- package/.taprc.yaml +8 -0
- package/CNAME +1 -0
- package/CONTRIBUTING.md +30 -0
- package/LICENSE +21 -0
- package/README.md +159 -3
- package/SECURITY.md +68 -0
- package/benchmarks/basic.bench.js +95 -0
- package/benchmarks/child-child.bench.js +52 -0
- package/benchmarks/child-creation.bench.js +73 -0
- package/benchmarks/child.bench.js +62 -0
- package/benchmarks/deep-object.bench.js +88 -0
- package/benchmarks/formatters.bench.js +50 -0
- package/benchmarks/internal/custom-levels.js +67 -0
- package/benchmarks/internal/just-pino-heavy.bench.js +76 -0
- package/benchmarks/internal/just-pino.bench.js +182 -0
- package/benchmarks/internal/parent-vs-child.bench.js +75 -0
- package/benchmarks/internal/redact.bench.js +86 -0
- package/benchmarks/long-string.bench.js +81 -0
- package/benchmarks/multi-arg.bench.js +193 -0
- package/benchmarks/multistream.js +98 -0
- package/benchmarks/object.bench.js +82 -0
- package/benchmarks/utils/generate-benchmark-doc.js +36 -0
- package/benchmarks/utils/runbench.js +138 -0
- package/benchmarks/utils/wrap-log-level.js +55 -0
- package/bin.js +6 -0
- package/browser.js +484 -0
- package/build/sync-version.js +10 -0
- package/docs/api.md +1487 -0
- package/docs/asynchronous.md +40 -0
- package/docs/benchmarks.md +55 -0
- package/docs/browser.md +227 -0
- package/docs/bundling.md +40 -0
- package/docs/child-loggers.md +95 -0
- package/docs/ecosystem.md +84 -0
- package/docs/help.md +345 -0
- package/docs/lts.md +64 -0
- package/docs/pretty.md +35 -0
- package/docs/redaction.md +135 -0
- package/docs/transports.md +1238 -0
- package/docs/web.md +269 -0
- package/docsify/sidebar.md +26 -0
- package/examples/basic.js +43 -0
- package/examples/transport.js +68 -0
- package/favicon-16x16.png +0 -0
- package/favicon-32x32.png +0 -0
- package/favicon.ico +0 -0
- package/file.js +12 -0
- package/inc-version.sh +42 -0
- package/index.html +55 -0
- package/lib/caller.js +30 -0
- package/lib/constants.js +28 -0
- package/lib/deprecations.js +8 -0
- package/lib/levels.js +241 -0
- package/lib/meta.js +3 -0
- package/lib/multistream.js +188 -0
- package/lib/proto.js +234 -0
- package/lib/redaction.js +118 -0
- package/lib/symbols.js +74 -0
- package/lib/time.js +11 -0
- package/lib/tools.js +394 -0
- package/lib/transport-stream.js +56 -0
- package/lib/transport.js +167 -0
- package/lib/worker.js +194 -0
- package/lib/writer.js +42 -0
- package/logs-buffer - Shortcut.lnk +0 -0
- package/package.json +117 -3
- package/pino-banner.png +0 -0
- package/pino-logo-hire.png +0 -0
- package/pino-tree.png +0 -0
- package/pino.d.ts +889 -0
- package/pino.js +236 -0
- package/pretty-demo.png +0 -0
- package/test/basic.test.js +874 -0
- package/test/broken-pipe.test.js +57 -0
- package/test/browser-child.test.js +132 -0
- package/test/browser-disabled.test.js +87 -0
- package/test/browser-early-console-freeze.test.js +12 -0
- package/test/browser-levels.test.js +241 -0
- package/test/browser-serializers.test.js +352 -0
- package/test/browser-timestamp.test.js +88 -0
- package/test/browser-transmit.test.js +417 -0
- package/test/browser.test.js +659 -0
- package/test/complex-objects.test.js +34 -0
- package/test/crlf.test.js +32 -0
- package/test/custom-levels.test.js +253 -0
- package/test/error.test.js +398 -0
- package/test/errorKey.test.js +34 -0
- package/test/escaping.test.js +91 -0
- package/test/esm/esm.mjs +12 -0
- package/test/esm/index.test.js +34 -0
- package/test/esm/named-exports.mjs +27 -0
- package/test/exit.test.js +77 -0
- package/test/fixtures/broken-pipe/basic.js +9 -0
- package/test/fixtures/broken-pipe/destination.js +10 -0
- package/test/fixtures/broken-pipe/syncfalse.js +12 -0
- package/test/fixtures/console-transport.js +13 -0
- package/test/fixtures/default-exit.js +8 -0
- package/test/fixtures/destination-exit.js +8 -0
- package/test/fixtures/eval/index.js +13 -0
- package/test/fixtures/eval/node_modules/14-files.js +3 -0
- package/test/fixtures/eval/node_modules/2-files.js +3 -0
- package/test/fixtures/eval/node_modules/file1.js +5 -0
- package/test/fixtures/eval/node_modules/file10.js +5 -0
- package/test/fixtures/eval/node_modules/file11.js +5 -0
- package/test/fixtures/eval/node_modules/file12.js +5 -0
- package/test/fixtures/eval/node_modules/file13.js +5 -0
- package/test/fixtures/eval/node_modules/file14.js +11 -0
- package/test/fixtures/eval/node_modules/file2.js +5 -0
- package/test/fixtures/eval/node_modules/file3.js +5 -0
- package/test/fixtures/eval/node_modules/file4.js +5 -0
- package/test/fixtures/eval/node_modules/file5.js +5 -0
- package/test/fixtures/eval/node_modules/file6.js +5 -0
- package/test/fixtures/eval/node_modules/file7.js +5 -0
- package/test/fixtures/eval/node_modules/file8.js +5 -0
- package/test/fixtures/eval/node_modules/file9.js +5 -0
- package/test/fixtures/noop-transport.js +10 -0
- package/test/fixtures/pretty/null-prototype.js +8 -0
- package/test/fixtures/stdout-hack-protection.js +11 -0
- package/test/fixtures/syncfalse-child.js +6 -0
- package/test/fixtures/syncfalse-exit.js +9 -0
- package/test/fixtures/syncfalse-flush-exit.js +10 -0
- package/test/fixtures/syncfalse.js +6 -0
- package/test/fixtures/syntax-error-esm.mjs +2 -0
- package/test/fixtures/to-file-transport-with-transform.js +20 -0
- package/test/fixtures/to-file-transport.js +13 -0
- package/test/fixtures/to-file-transport.mjs +8 -0
- package/test/fixtures/transport/index.js +12 -0
- package/test/fixtures/transport/package.json +5 -0
- package/test/fixtures/transport-exit-immediately-with-async-dest.js +16 -0
- package/test/fixtures/transport-exit-immediately.js +11 -0
- package/test/fixtures/transport-exit-on-ready.js +12 -0
- package/test/fixtures/transport-main.js +9 -0
- package/test/fixtures/transport-many-lines.js +29 -0
- package/test/fixtures/transport-string-stdout.js +9 -0
- package/test/fixtures/transport-transform.js +21 -0
- package/test/fixtures/transport-uses-pino-config.js +33 -0
- package/test/fixtures/transport-with-on-exit.js +12 -0
- package/test/fixtures/transport-worker-data.js +19 -0
- package/test/fixtures/transport-worker.js +15 -0
- package/test/fixtures/transport-wrong-export-type.js +3 -0
- package/test/fixtures/ts/to-file-transport-with-transform.ts +18 -0
- package/test/fixtures/ts/to-file-transport.ts +11 -0
- package/test/fixtures/ts/transpile.cjs +36 -0
- package/test/fixtures/ts/transport-exit-immediately-with-async-dest.ts +15 -0
- package/test/fixtures/ts/transport-exit-immediately.ts +10 -0
- package/test/fixtures/ts/transport-exit-on-ready.ts +11 -0
- package/test/fixtures/ts/transport-main.ts +8 -0
- package/test/fixtures/ts/transport-string-stdout.ts +8 -0
- package/test/fixtures/ts/transport-worker.ts +14 -0
- package/test/formatters.test.js +355 -0
- package/test/helper.d.ts +4 -0
- package/test/helper.js +128 -0
- package/test/hooks.test.js +118 -0
- package/test/http.test.js +242 -0
- package/test/internals/version.test.js +15 -0
- package/test/is-level-enabled.test.js +185 -0
- package/test/jest/basic.spec.js +10 -0
- package/test/levels.test.js +772 -0
- package/test/metadata.test.js +106 -0
- package/test/mixin-merge-strategy.test.js +55 -0
- package/test/mixin.test.js +218 -0
- package/test/multistream.test.js +673 -0
- package/test/pkg/index.js +46 -0
- package/test/pkg/pkg.config.json +17 -0
- package/test/pkg/pkg.test.js +56 -0
- package/test/redact.test.js +847 -0
- package/test/serializers.test.js +253 -0
- package/test/stdout-protection.test.js +39 -0
- package/test/syncfalse.test.js +188 -0
- package/test/timestamp.test.js +121 -0
- package/test/transport/big.test.js +43 -0
- package/test/transport/bundlers-support.test.js +97 -0
- package/test/transport/caller.test.js +23 -0
- package/test/transport/core.test.js +644 -0
- package/test/transport/core.test.ts +236 -0
- package/test/transport/core.transpiled.test.ts +112 -0
- package/test/transport/module-link.test.js +239 -0
- package/test/transport/pipeline.test.js +135 -0
- package/test/transport/repl.test.js +14 -0
- package/test/transport/syncTrue.test.js +55 -0
- package/test/transport/syncfalse.test.js +68 -0
- package/test/transport/targets.test.js +44 -0
- package/test/transport/uses-pino-config.test.js +167 -0
- package/test/transport-stream.test.js +26 -0
- package/test/types/pino-import.test-d.ts +29 -0
- package/test/types/pino-multistream.test-d.ts +28 -0
- package/test/types/pino-top-export.test-d.ts +35 -0
- package/test/types/pino-transport.test-d.ts +145 -0
- package/test/types/pino-type-only.test-d.ts +64 -0
- package/test/types/pino.test-d.ts +468 -0
- package/test/types/pino.ts +78 -0
- package/tsconfig.json +14 -0
@@ -0,0 +1,135 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const os = require('node:os')
|
4
|
+
const { join } = require('node:path')
|
5
|
+
const { readFile } = require('node:fs').promises
|
6
|
+
const { watchFileCreated, file } = require('../helper')
|
7
|
+
const { test } = require('tap')
|
8
|
+
const pino = require('../../')
|
9
|
+
const { DEFAULT_LEVELS } = require('../../lib/constants')
|
10
|
+
|
11
|
+
const { pid } = process
|
12
|
+
const hostname = os.hostname()
|
13
|
+
|
14
|
+
test('pino.transport with a pipeline', async ({ same, teardown }) => {
|
15
|
+
const destination = file()
|
16
|
+
const transport = pino.transport({
|
17
|
+
pipeline: [{
|
18
|
+
target: join(__dirname, '..', 'fixtures', 'transport-transform.js')
|
19
|
+
}, {
|
20
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
21
|
+
options: { destination }
|
22
|
+
}]
|
23
|
+
})
|
24
|
+
teardown(transport.end.bind(transport))
|
25
|
+
const instance = pino(transport)
|
26
|
+
instance.info('hello')
|
27
|
+
await watchFileCreated(destination)
|
28
|
+
const result = JSON.parse(await readFile(destination))
|
29
|
+
delete result.time
|
30
|
+
same(result, {
|
31
|
+
pid,
|
32
|
+
hostname,
|
33
|
+
level: DEFAULT_LEVELS.info,
|
34
|
+
msg: 'hello',
|
35
|
+
service: 'pino' // this property was added by the transform
|
36
|
+
})
|
37
|
+
})
|
38
|
+
|
39
|
+
test('pino.transport with targets containing pipelines', async ({ same, teardown }) => {
|
40
|
+
const destinationA = file()
|
41
|
+
const destinationB = file()
|
42
|
+
const transport = pino.transport({
|
43
|
+
targets: [
|
44
|
+
{
|
45
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
46
|
+
options: { destination: destinationA }
|
47
|
+
},
|
48
|
+
{
|
49
|
+
pipeline: [
|
50
|
+
{
|
51
|
+
target: join(__dirname, '..', 'fixtures', 'transport-transform.js')
|
52
|
+
},
|
53
|
+
{
|
54
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
55
|
+
options: { destination: destinationB }
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
]
|
60
|
+
})
|
61
|
+
|
62
|
+
teardown(transport.end.bind(transport))
|
63
|
+
const instance = pino(transport)
|
64
|
+
instance.info('hello')
|
65
|
+
await watchFileCreated(destinationA)
|
66
|
+
await watchFileCreated(destinationB)
|
67
|
+
const resultA = JSON.parse(await readFile(destinationA))
|
68
|
+
const resultB = JSON.parse(await readFile(destinationB))
|
69
|
+
delete resultA.time
|
70
|
+
delete resultB.time
|
71
|
+
same(resultA, {
|
72
|
+
pid,
|
73
|
+
hostname,
|
74
|
+
level: DEFAULT_LEVELS.info,
|
75
|
+
msg: 'hello'
|
76
|
+
})
|
77
|
+
same(resultB, {
|
78
|
+
pid,
|
79
|
+
hostname,
|
80
|
+
level: DEFAULT_LEVELS.info,
|
81
|
+
msg: 'hello',
|
82
|
+
service: 'pino' // this property was added by the transform
|
83
|
+
})
|
84
|
+
})
|
85
|
+
|
86
|
+
test('pino.transport with targets containing pipelines with levels defined and dedupe', async ({ same, teardown }) => {
|
87
|
+
const destinationA = file()
|
88
|
+
const destinationB = file()
|
89
|
+
const transport = pino.transport({
|
90
|
+
targets: [
|
91
|
+
{
|
92
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
93
|
+
options: { destination: destinationA },
|
94
|
+
level: DEFAULT_LEVELS.info
|
95
|
+
},
|
96
|
+
{
|
97
|
+
pipeline: [
|
98
|
+
{
|
99
|
+
target: join(__dirname, '..', 'fixtures', 'transport-transform.js')
|
100
|
+
},
|
101
|
+
{
|
102
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
103
|
+
options: { destination: destinationB }
|
104
|
+
}
|
105
|
+
],
|
106
|
+
level: DEFAULT_LEVELS.error
|
107
|
+
}
|
108
|
+
],
|
109
|
+
dedupe: true
|
110
|
+
})
|
111
|
+
|
112
|
+
teardown(transport.end.bind(transport))
|
113
|
+
const instance = pino(transport)
|
114
|
+
instance.info('hello info')
|
115
|
+
instance.error('hello error')
|
116
|
+
await watchFileCreated(destinationA)
|
117
|
+
await watchFileCreated(destinationB)
|
118
|
+
const resultA = JSON.parse(await readFile(destinationA))
|
119
|
+
const resultB = JSON.parse(await readFile(destinationB))
|
120
|
+
delete resultA.time
|
121
|
+
delete resultB.time
|
122
|
+
same(resultA, {
|
123
|
+
pid,
|
124
|
+
hostname,
|
125
|
+
level: DEFAULT_LEVELS.info,
|
126
|
+
msg: 'hello info'
|
127
|
+
})
|
128
|
+
same(resultB, {
|
129
|
+
pid,
|
130
|
+
hostname,
|
131
|
+
level: DEFAULT_LEVELS.error,
|
132
|
+
msg: 'hello error',
|
133
|
+
service: 'pino' // this property was added by the transform
|
134
|
+
})
|
135
|
+
})
|
@@ -0,0 +1,14 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { doesNotThrow, test } = require('tap')
|
4
|
+
const proxyquire = require('proxyquire')
|
5
|
+
|
6
|
+
test('pino.transport resolves targets in REPL', async ({ same }) => {
|
7
|
+
// Arrange
|
8
|
+
const transport = proxyquire('../../lib/transport', {
|
9
|
+
'./caller': () => ['node:repl']
|
10
|
+
})
|
11
|
+
|
12
|
+
// Act / Assert
|
13
|
+
doesNotThrow(() => transport({ target: 'pino-pretty' }))
|
14
|
+
})
|
@@ -0,0 +1,55 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const pino = require('../..')
|
4
|
+
const { join } = require('node:path')
|
5
|
+
const { readFileSync } = require('node:fs')
|
6
|
+
const { test } = require('tap')
|
7
|
+
const { file } = require('../helper')
|
8
|
+
|
9
|
+
test('thread-stream sync true should log synchronously', async (t) => {
|
10
|
+
const outputPath = file()
|
11
|
+
|
12
|
+
function getOutputLogLines () {
|
13
|
+
return (readFileSync(outputPath)).toString().trim().split('\n').map(JSON.parse)
|
14
|
+
}
|
15
|
+
|
16
|
+
const transport = pino.transport({
|
17
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
18
|
+
options: { destination: outputPath, flush: true },
|
19
|
+
sync: true
|
20
|
+
})
|
21
|
+
const instance = pino(transport)
|
22
|
+
|
23
|
+
var value = { message: 'sync' }
|
24
|
+
instance.info(value)
|
25
|
+
instance.info(value)
|
26
|
+
instance.info(value)
|
27
|
+
instance.info(value)
|
28
|
+
instance.info(value)
|
29
|
+
instance.info(value)
|
30
|
+
let interrupt = false
|
31
|
+
let flushData
|
32
|
+
let loopCounter = 0
|
33
|
+
|
34
|
+
// Start a synchronous loop
|
35
|
+
while (!interrupt && loopCounter < (process.env.MAX_TEST_LOOP_ITERATION || 20000)) {
|
36
|
+
try {
|
37
|
+
loopCounter++
|
38
|
+
const data = getOutputLogLines()
|
39
|
+
flushData = data
|
40
|
+
if (data) {
|
41
|
+
interrupt = true
|
42
|
+
break
|
43
|
+
}
|
44
|
+
} catch (error) {
|
45
|
+
// File may not exist yet
|
46
|
+
// Wait till MAX_TEST_LOOP_ITERATION iterations
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
if (!interrupt) {
|
51
|
+
throw new Error('Sync loop did not get interrupt')
|
52
|
+
}
|
53
|
+
|
54
|
+
t.equal(flushData.length, 6)
|
55
|
+
})
|
@@ -0,0 +1,68 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const os = require('node:os')
|
4
|
+
const pino = require('../..')
|
5
|
+
const { join } = require('node:path')
|
6
|
+
const { test } = require('tap')
|
7
|
+
const { readFile } = require('node:fs').promises
|
8
|
+
const { watchFileCreated, file } = require('../helper')
|
9
|
+
const { promisify } = require('node:util')
|
10
|
+
|
11
|
+
const { pid } = process
|
12
|
+
const hostname = os.hostname()
|
13
|
+
|
14
|
+
test('thread-stream async flush', async ({ equal, same }) => {
|
15
|
+
const destination = file()
|
16
|
+
const transport = pino.transport({
|
17
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
18
|
+
options: { destination }
|
19
|
+
})
|
20
|
+
const instance = pino(transport)
|
21
|
+
instance.info('hello')
|
22
|
+
|
23
|
+
equal(instance.flush(), undefined)
|
24
|
+
|
25
|
+
await watchFileCreated(destination)
|
26
|
+
const result = JSON.parse(await readFile(destination))
|
27
|
+
delete result.time
|
28
|
+
same(result, {
|
29
|
+
pid,
|
30
|
+
hostname,
|
31
|
+
level: 30,
|
32
|
+
msg: 'hello'
|
33
|
+
})
|
34
|
+
})
|
35
|
+
|
36
|
+
test('thread-stream async flush should call the passed callback', async (t) => {
|
37
|
+
const outputPath = file()
|
38
|
+
async function getOutputLogLines () {
|
39
|
+
return (await readFile(outputPath)).toString().trim().split('\n').map(JSON.parse)
|
40
|
+
}
|
41
|
+
const transport = pino.transport({
|
42
|
+
target: join(__dirname, '..', 'fixtures', 'to-file-transport.js'),
|
43
|
+
options: { destination: outputPath }
|
44
|
+
})
|
45
|
+
const instance = pino(transport)
|
46
|
+
const flushPromise = promisify(instance.flush).bind(instance)
|
47
|
+
|
48
|
+
instance.info('hello')
|
49
|
+
await flushPromise()
|
50
|
+
await watchFileCreated(outputPath)
|
51
|
+
|
52
|
+
const [firstFlushData] = await getOutputLogLines()
|
53
|
+
|
54
|
+
t.equal(firstFlushData.msg, 'hello')
|
55
|
+
|
56
|
+
// should not flush this as no data accumulated that's bigger than min length
|
57
|
+
instance.info('world')
|
58
|
+
|
59
|
+
// Making sure data is not flushed yet
|
60
|
+
const afterLogData = await getOutputLogLines()
|
61
|
+
t.equal(afterLogData.length, 1)
|
62
|
+
|
63
|
+
await flushPromise()
|
64
|
+
|
65
|
+
// Making sure data is not flushed yet
|
66
|
+
const afterSecondFlush = (await getOutputLogLines())[1]
|
67
|
+
t.equal(afterSecondFlush.msg, 'world')
|
68
|
+
})
|
@@ -0,0 +1,44 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { test } = require('tap')
|
4
|
+
const { join } = require('node:path')
|
5
|
+
const proxyquire = require('proxyquire')
|
6
|
+
const Writable = require('node:stream').Writable
|
7
|
+
const pino = require('../../pino')
|
8
|
+
|
9
|
+
test('file-target mocked', async function ({ equal, same, plan, pass }) {
|
10
|
+
plan(1)
|
11
|
+
let ret
|
12
|
+
const fileTarget = proxyquire('../../file', {
|
13
|
+
'./pino': {
|
14
|
+
destination (opts) {
|
15
|
+
same(opts, { dest: 1, sync: false })
|
16
|
+
|
17
|
+
ret = new Writable()
|
18
|
+
ret.fd = opts.dest
|
19
|
+
|
20
|
+
process.nextTick(() => {
|
21
|
+
ret.emit('ready')
|
22
|
+
})
|
23
|
+
|
24
|
+
return ret
|
25
|
+
}
|
26
|
+
}
|
27
|
+
})
|
28
|
+
|
29
|
+
await fileTarget()
|
30
|
+
})
|
31
|
+
|
32
|
+
test('pino.transport with syntax error', ({ same, teardown, plan }) => {
|
33
|
+
plan(1)
|
34
|
+
const transport = pino.transport({
|
35
|
+
targets: [{
|
36
|
+
target: join(__dirname, '..', 'fixtures', 'syntax-error-esm.mjs')
|
37
|
+
}]
|
38
|
+
})
|
39
|
+
teardown(transport.end.bind(transport))
|
40
|
+
|
41
|
+
transport.on('error', (err) => {
|
42
|
+
same(err, new SyntaxError('Unexpected end of input'))
|
43
|
+
})
|
44
|
+
})
|
@@ -0,0 +1,167 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const os = require('node:os')
|
4
|
+
const { join } = require('node:path')
|
5
|
+
const { readFile } = require('node:fs').promises
|
6
|
+
const writeStream = require('flush-write-stream')
|
7
|
+
const { watchFileCreated, file } = require('../helper')
|
8
|
+
const { test } = require('tap')
|
9
|
+
const pino = require('../../')
|
10
|
+
|
11
|
+
const { pid } = process
|
12
|
+
const hostname = os.hostname()
|
13
|
+
|
14
|
+
function serializeError (error) {
|
15
|
+
return {
|
16
|
+
type: error.name,
|
17
|
+
message: error.message,
|
18
|
+
stack: error.stack
|
19
|
+
}
|
20
|
+
}
|
21
|
+
|
22
|
+
function parseLogs (buffer) {
|
23
|
+
return JSON.parse(`[${buffer.toString().replace(/}{/g, '},{')}]`)
|
24
|
+
}
|
25
|
+
|
26
|
+
test('transport uses pino config', async ({ same, teardown, plan }) => {
|
27
|
+
plan(1)
|
28
|
+
const destination = file()
|
29
|
+
const transport = pino.transport({
|
30
|
+
pipeline: [{
|
31
|
+
target: join(__dirname, '..', 'fixtures', 'transport-uses-pino-config.js')
|
32
|
+
}, {
|
33
|
+
target: 'pino/file',
|
34
|
+
options: { destination }
|
35
|
+
}]
|
36
|
+
})
|
37
|
+
teardown(transport.end.bind(transport))
|
38
|
+
const instance = pino({
|
39
|
+
messageKey: 'customMessageKey',
|
40
|
+
errorKey: 'customErrorKey',
|
41
|
+
customLevels: { custom: 35 }
|
42
|
+
}, transport)
|
43
|
+
|
44
|
+
const error = new Error('bar')
|
45
|
+
instance.custom('foo')
|
46
|
+
instance.error(error)
|
47
|
+
await watchFileCreated(destination)
|
48
|
+
const result = parseLogs(await readFile(destination))
|
49
|
+
|
50
|
+
same(result, [{
|
51
|
+
severityText: 'custom',
|
52
|
+
body: 'foo',
|
53
|
+
attributes: {
|
54
|
+
pid,
|
55
|
+
hostname
|
56
|
+
}
|
57
|
+
}, {
|
58
|
+
severityText: 'error',
|
59
|
+
body: 'bar',
|
60
|
+
attributes: {
|
61
|
+
pid,
|
62
|
+
hostname
|
63
|
+
},
|
64
|
+
error: serializeError(error)
|
65
|
+
}])
|
66
|
+
})
|
67
|
+
|
68
|
+
test('transport uses pino config without customizations', async ({ same, teardown, plan }) => {
|
69
|
+
plan(1)
|
70
|
+
const destination = file()
|
71
|
+
const transport = pino.transport({
|
72
|
+
pipeline: [{
|
73
|
+
target: join(__dirname, '..', 'fixtures', 'transport-uses-pino-config.js')
|
74
|
+
}, {
|
75
|
+
target: 'pino/file',
|
76
|
+
options: { destination }
|
77
|
+
}]
|
78
|
+
})
|
79
|
+
teardown(transport.end.bind(transport))
|
80
|
+
const instance = pino(transport)
|
81
|
+
|
82
|
+
const error = new Error('qux')
|
83
|
+
instance.info('baz')
|
84
|
+
instance.error(error)
|
85
|
+
await watchFileCreated(destination)
|
86
|
+
const result = parseLogs(await readFile(destination))
|
87
|
+
|
88
|
+
same(result, [{
|
89
|
+
severityText: 'info',
|
90
|
+
body: 'baz',
|
91
|
+
attributes: {
|
92
|
+
pid,
|
93
|
+
hostname
|
94
|
+
}
|
95
|
+
}, {
|
96
|
+
severityText: 'error',
|
97
|
+
body: 'qux',
|
98
|
+
attributes: {
|
99
|
+
pid,
|
100
|
+
hostname
|
101
|
+
},
|
102
|
+
error: serializeError(error)
|
103
|
+
}])
|
104
|
+
})
|
105
|
+
|
106
|
+
test('transport uses pino config with multistream', async ({ same, teardown, plan }) => {
|
107
|
+
plan(2)
|
108
|
+
const destination = file()
|
109
|
+
const messages = []
|
110
|
+
const stream = writeStream(function (data, enc, cb) {
|
111
|
+
const message = JSON.parse(data)
|
112
|
+
delete message.time
|
113
|
+
messages.push(message)
|
114
|
+
cb()
|
115
|
+
})
|
116
|
+
const transport = pino.transport({
|
117
|
+
pipeline: [{
|
118
|
+
target: join(__dirname, '..', 'fixtures', 'transport-uses-pino-config.js')
|
119
|
+
}, {
|
120
|
+
target: 'pino/file',
|
121
|
+
options: { destination }
|
122
|
+
}]
|
123
|
+
})
|
124
|
+
teardown(transport.end.bind(transport))
|
125
|
+
const instance = pino({
|
126
|
+
messageKey: 'customMessageKey',
|
127
|
+
errorKey: 'customErrorKey',
|
128
|
+
customLevels: { custom: 35 }
|
129
|
+
}, pino.multistream([transport, { stream }]))
|
130
|
+
|
131
|
+
const error = new Error('buzz')
|
132
|
+
const serializedError = serializeError(error)
|
133
|
+
instance.custom('fizz')
|
134
|
+
instance.error(error)
|
135
|
+
await watchFileCreated(destination)
|
136
|
+
const result = parseLogs(await readFile(destination))
|
137
|
+
|
138
|
+
same(result, [{
|
139
|
+
severityText: 'custom',
|
140
|
+
body: 'fizz',
|
141
|
+
attributes: {
|
142
|
+
pid,
|
143
|
+
hostname
|
144
|
+
}
|
145
|
+
}, {
|
146
|
+
severityText: 'error',
|
147
|
+
body: 'buzz',
|
148
|
+
attributes: {
|
149
|
+
pid,
|
150
|
+
hostname
|
151
|
+
},
|
152
|
+
error: serializedError
|
153
|
+
}])
|
154
|
+
|
155
|
+
same(messages, [{
|
156
|
+
level: 35,
|
157
|
+
pid,
|
158
|
+
hostname,
|
159
|
+
customMessageKey: 'fizz'
|
160
|
+
}, {
|
161
|
+
level: 50,
|
162
|
+
pid,
|
163
|
+
hostname,
|
164
|
+
customErrorKey: serializedError,
|
165
|
+
customMessageKey: 'buzz'
|
166
|
+
}])
|
167
|
+
})
|
@@ -0,0 +1,26 @@
|
|
1
|
+
'use strict'
|
2
|
+
|
3
|
+
const { test } = require('tap')
|
4
|
+
|
5
|
+
test('should import', async (t) => {
|
6
|
+
t.plan(2)
|
7
|
+
const mockRealRequire = (target) => {
|
8
|
+
return {
|
9
|
+
default: {
|
10
|
+
default: () => {
|
11
|
+
t.equal(target, 'pino-pretty')
|
12
|
+
return Promise.resolve()
|
13
|
+
}
|
14
|
+
}
|
15
|
+
}
|
16
|
+
}
|
17
|
+
const mockRealImport = async () => { await Promise.resolve(); throw Object.assign(new Error(), { code: 'ERR_MODULE_NOT_FOUND' }) }
|
18
|
+
|
19
|
+
/** @type {typeof import('../lib/transport-stream.js')} */
|
20
|
+
const loadTransportStreamBuilder = t.mock('../lib/transport-stream.js', { 'real-require': { realRequire: mockRealRequire, realImport: mockRealImport } })
|
21
|
+
|
22
|
+
const fn = await loadTransportStreamBuilder('pino-pretty')
|
23
|
+
|
24
|
+
t.resolves(fn())
|
25
|
+
t.end()
|
26
|
+
})
|
@@ -0,0 +1,29 @@
|
|
1
|
+
import { expectType } from "tsd";
|
2
|
+
|
3
|
+
import pino from '../../pino';
|
4
|
+
import { pino as pinoNamed, P } from "../../pino";
|
5
|
+
import * as pinoStar from "../../pino";
|
6
|
+
import pinoCjsImport = require ("../../pino");
|
7
|
+
const pinoCjs = require("../../pino");
|
8
|
+
const { P: pinoCjsNamed } = require('pino')
|
9
|
+
|
10
|
+
const log = pino();
|
11
|
+
expectType<P.LogFn>(log.info);
|
12
|
+
expectType<P.LogFn>(log.error);
|
13
|
+
|
14
|
+
expectType<pino.Logger>(pinoNamed());
|
15
|
+
expectType<P.Logger>(pinoNamed());
|
16
|
+
expectType<pino.Logger>(pinoStar.default());
|
17
|
+
expectType<pino.Logger>(pinoStar.pino());
|
18
|
+
expectType<pino.Logger>(pinoCjsImport.default());
|
19
|
+
expectType<pino.Logger>(pinoCjsImport.pino());
|
20
|
+
expectType<any>(pinoCjsNamed());
|
21
|
+
expectType<any>(pinoCjs());
|
22
|
+
|
23
|
+
const levelChangeEventListener: P.LevelChangeEventListener = (
|
24
|
+
lvl: P.LevelWithSilent | string,
|
25
|
+
val: number,
|
26
|
+
prevLvl: P.LevelWithSilent | string,
|
27
|
+
prevVal: number,
|
28
|
+
) => {}
|
29
|
+
expectType<P.LevelChangeEventListener>(levelChangeEventListener)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
import { expectType } from 'tsd'
|
2
|
+
|
3
|
+
import { createWriteStream } from 'node:fs'
|
4
|
+
|
5
|
+
import pino, { multistream } from '../../pino'
|
6
|
+
|
7
|
+
const streams = [
|
8
|
+
{ stream: process.stdout },
|
9
|
+
{ stream: createWriteStream('') },
|
10
|
+
{ level: 'error' as const, stream: process.stderr },
|
11
|
+
{ level: 'fatal' as const, stream: process.stderr },
|
12
|
+
]
|
13
|
+
|
14
|
+
expectType<pino.MultiStreamRes>(pino.multistream(process.stdout))
|
15
|
+
expectType<pino.MultiStreamRes>(pino.multistream([createWriteStream('')]))
|
16
|
+
expectType<pino.MultiStreamRes<'error'>>(pino.multistream({ level: 'error' as const, stream: process.stderr }))
|
17
|
+
expectType<pino.MultiStreamRes<'fatal'>>(pino.multistream([{ level: 'fatal' as const, stream: createWriteStream('') }]))
|
18
|
+
|
19
|
+
expectType<pino.MultiStreamRes<'error' | 'fatal'>>(pino.multistream(streams))
|
20
|
+
expectType<pino.MultiStreamRes<'error' | 'fatal'>>(pino.multistream(streams, {}))
|
21
|
+
expectType<pino.MultiStreamRes<'error' | 'fatal'>>(pino.multistream(streams, { levels: { 'info': 30 } }))
|
22
|
+
expectType<pino.MultiStreamRes<'error' | 'fatal'>>(pino.multistream(streams, { dedupe: true }))
|
23
|
+
expectType<pino.MultiStreamRes<'error' | 'fatal'>>(pino.multistream(streams[0]).add(streams[1]))
|
24
|
+
expectType<pino.MultiStreamRes<'error' | 'fatal'>>(multistream(streams))
|
25
|
+
expectType<pino.MultiStreamRes<'error'>>(multistream(streams).clone('error'))
|
26
|
+
|
27
|
+
|
28
|
+
expectType<pino.MultiStreamRes>(multistream(process.stdout));
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { expectType, expectAssignable } from 'tsd'
|
2
|
+
import type { SonicBoom } from "sonic-boom";
|
3
|
+
|
4
|
+
import {
|
5
|
+
destination,
|
6
|
+
LevelMapping,
|
7
|
+
levels,
|
8
|
+
Logger,
|
9
|
+
multistream,
|
10
|
+
MultiStreamRes,
|
11
|
+
SerializedError,
|
12
|
+
stdSerializers,
|
13
|
+
stdTimeFunctions,
|
14
|
+
symbols,
|
15
|
+
transport,
|
16
|
+
version,
|
17
|
+
} from "../../pino";
|
18
|
+
import pino from "../../pino";
|
19
|
+
|
20
|
+
expectType<SonicBoom>(destination(""));
|
21
|
+
expectType<LevelMapping>(levels);
|
22
|
+
expectType<MultiStreamRes>(multistream(process.stdout));
|
23
|
+
expectType<SerializedError>(stdSerializers.err({} as any));
|
24
|
+
expectType<string>(stdTimeFunctions.isoTime());
|
25
|
+
expectType<string>(version);
|
26
|
+
|
27
|
+
// Can't test against `unique symbol`, see https://github.com/SamVerschueren/tsd/issues/49
|
28
|
+
expectAssignable<Symbol>(symbols.endSym);
|
29
|
+
|
30
|
+
// TODO: currently returns (aliased) `any`, waiting for strong typed `thread-stream`
|
31
|
+
transport({
|
32
|
+
target: '#pino/pretty',
|
33
|
+
options: { some: 'options for', the: 'transport' }
|
34
|
+
});
|
35
|
+
|