Skip to content

Commit 6a43a87

Browse files
committed
chore: some package cleanup
1 parent 6f69d02 commit 6a43a87

File tree

7 files changed

+48
-21
lines changed

7 files changed

+48
-21
lines changed

.github/workflows/ci.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ jobs:
3636
strategy:
3737
matrix:
3838
node: [22.x, 24.x]
39+
40+
services:
41+
loki:
42+
image: grafana/loki:latest
43+
ports:
44+
- 3100:3100
45+
3946
env:
40-
LOKI_HOST: ${{ secrets.LOKI_HOST }}
41-
LOKI_USERNAME: ${{ secrets.LOKI_USERNAME }}
42-
LOKI_PASSWORD: ${{ secrets.LOKI_PASSWORD }}
47+
LOKI_HOST: http://localhost:3100
4348

4449
steps:
4550
- uses: actions/checkout@v4
@@ -59,5 +64,18 @@ jobs:
5964
- name: Build
6065
run: pnpm build
6166

67+
- name: Wait for Loki to be ready
68+
run: |
69+
for i in {1..30}; do
70+
if curl -s http://localhost:3100/ready | grep -q "ready"; then
71+
echo "Loki is ready"
72+
exit 0
73+
fi
74+
echo "Waiting for Loki... ($i/30)"
75+
sleep 2
76+
done
77+
echo "Loki failed to start"
78+
exit 1
79+
6280
- name: Test
6381
run: pnpm test

examples/basic.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { LokiOptions } from '../src/types.ts'
77

88
const transport = pino.transport<LokiOptions>({
99
// 👇 Replace this with "pino-loki"
10-
target: '../dist/index.js',
10+
target: '../dist/index.mjs',
1111

1212
options: {
1313
// These labels will be added to every log

examples/batching.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import type { LokiOptions } from '../src/types.ts'
1010

1111
const transport = pino.transport<LokiOptions>({
1212
// 👇 Replace this with "pino-loki"
13-
target: '../dist/index.js',
13+
target: '../dist/index.mjs',
1414

1515
options: {
1616
batching: true,

examples/custom_timestamp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function nanoseconds() {
2424

2525
const transport = pino.transport<LokiOptions>({
2626
// 👇 Replace this with "pino-loki"
27-
target: '../dist/index.js',
27+
target: '../dist/index.mjs',
2828

2929
options: {
3030
// These labels will be added to every log

examples/multiple_transports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const transport = pino.transport({
66
targets: [
77
{
88
// 👇 Replace this with "pino-loki"
9-
target: '../dist/index.js',
9+
target: '../dist/index.mjs',
1010

1111
level: 'info',
1212
options: {

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,22 @@
2323
],
2424
"exports": {
2525
".": {
26-
"import": "./dist/index.js",
27-
"require": "./dist/index.cjs"
26+
"import": {
27+
"types": "./dist/index.d.mts",
28+
"default": "./dist/index.mjs"
29+
},
30+
"require": {
31+
"types": "./dist/index.d.cts",
32+
"default": "./dist/index.cjs"
33+
}
2834
},
2935
"./package.json": "./package.json"
3036
},
3137
"main": "./dist/index.cjs",
32-
"module": "./dist/index.js",
33-
"types": "./dist/index.d.cts",
38+
"module": "./dist/index.mjs",
39+
"types": "./dist/index.d.mts",
3440
"bin": {
35-
"pino-loki": "dist/cli.js"
41+
"pino-loki": "dist/cli.mjs"
3642
},
3743
"files": [
3844
"dist"

tests/integration/loki.spec.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@ import { LokiClient } from '../helpers.ts'
88
import { pinoLoki } from '../../src/index.ts'
99
import type { LokiOptions } from '../../src/types.ts'
1010

11-
const credentials = {
11+
const credentials: { host: string; basicAuth?: { username: string; password: string } } = {
1212
host: process.env.LOKI_HOST!,
13-
basicAuth: { username: process.env.LOKI_USERNAME!, password: process.env.LOKI_PASSWORD! },
13+
...(process.env.LOKI_USERNAME &&
14+
process.env.LOKI_PASSWORD && {
15+
basicAuth: { username: process.env.LOKI_USERNAME, password: process.env.LOKI_PASSWORD },
16+
}),
1417
}
1518

1619
test.group('Loki integration', () => {
@@ -100,7 +103,7 @@ test.group('Loki integration', () => {
100103
test('batching mode should not drop logs when main process exits', async ({ assert }) => {
101104
const application = randomUUID()
102105

103-
const logger = pino.transport<LokiOptions>({
106+
const transport = pino.transport<LokiOptions>({
104107
target: '../../dist/index.mjs',
105108
options: {
106109
...credentials,
@@ -110,15 +113,15 @@ test.group('Loki integration', () => {
110113
},
111114
})
112115

113-
const pinoLogger = pino({}, logger)
116+
const logger = pino({}, transport)
114117

115-
pinoLogger.info({ test: 1 })
116-
pinoLogger.info({ test: 2 })
117-
pinoLogger.info({ test: 3 })
118+
logger.info({ test: 1 })
119+
logger.info({ test: 2 })
120+
logger.info({ test: 3 })
118121

119-
// Manually end the logger. This will be executed automatically
122+
// Manually end the transport. This will be executed automatically
120123
// when the main process exits
121-
logger.end()
124+
transport.end()
122125

123126
await setTimeout(1000)
124127

0 commit comments

Comments
 (0)