Skip to content

Commit

Permalink
chore: move back to esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien-R44 committed May 22, 2023
1 parent 790ec4d commit 65729e1
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 49 deletions.
3 changes: 1 addition & 2 deletions bin/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import 'dotenv/config'
import { assert } from '@japa/assert'
import { specReporter } from '@japa/spec-reporter'
import { processCliArgs, configure, run } from '@japa/runner'
import { pathToFileURL } from 'url'

/*
|--------------------------------------------------------------------------
Expand All @@ -22,7 +21,7 @@ configure({
plugins: [assert()],
reporters: [specReporter()],
forceExit: true,
importer: (filePath) => import(pathToFileURL(filePath).href),
importer: (filePath) => import(filePath),
suites: [
{
name: 'unit',
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dotenv/config'
import { pino } from 'pino'
import { LokiOptions } from '../src/types/index.js'
import { LokiOptions } from '../src/types/index'

const transport = pino.transport<LokiOptions>({
// 👇 Replace this with "pino-loki"
Expand Down
26 changes: 15 additions & 11 deletions examples/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import 'dotenv/config'
import { pino } from 'pino'
import { LokiOptions } from '../src/types/index.js'
import { LokiOptions } from '../src/types/index'

const transport = pino.transport<LokiOptions>({
// 👇 Replace this with "pino-loki"
Expand All @@ -28,15 +28,19 @@ const transport = pino.transport<LokiOptions>({

const logger = pino(transport)

// These logs will be batched and sent to loki after 2 seconds
logger.info('Hello 1!')
logger.info('Hello 2!')
logger.info('Hello 3!')
async function main() {
// These logs will be batched and sent to loki after 2 seconds
logger.info('Hello 1!')
logger.info('Hello 2!')
logger.info('Hello 3!')

await new Promise((resolve) => setTimeout(resolve, 3000))
await new Promise((resolve) => setTimeout(resolve, 3000))

// These logs will also be batched but sent immediately since
// our main process is about to exit
logger.info('Hello 4!')
logger.info('Hello 5!')
logger.info('Hello 6!')
// These logs will also be batched but sent immediately since
// our main process is about to exit
logger.info('Hello 4!')
logger.info('Hello 5!')
logger.info('Hello 6!')
}

main()
2 changes: 1 addition & 1 deletion examples/custom_timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import 'dotenv/config'
import { pino } from 'pino'
import { LokiOptions } from '../src/index.js'
import { LokiOptions } from '../src/index'

const loadNs = process.hrtime()
const loadMs = new Date().getTime()
Expand Down
2 changes: 1 addition & 1 deletion examples/module_usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import 'dotenv/config'
import { pino } from 'pino'
import pinoLoki from '../src/index.js'
import pinoLoki from '../src/index'

const logger = pino(
{ level: 'info' },
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "pino-loki",
"version": "2.1.2",
"type": "module",
"type": "commonjs",
"description": "A transport for pino that sends messages to Loki",
"keywords": [
"pino",
Expand Down Expand Up @@ -53,8 +53,8 @@
"prepublishOnly": "pnpm build",
"release": "bumpp --commit --push --tag && pnpm publish",
"stub": "unbuild --stub",
"quick:test": "node --loader=ts-node/esm bin/test.ts",
"test": "c8 node --loader=ts-node/esm bin/test.ts",
"quick:test": "node -r ts-node/register bin/test.ts",
"test": "c8 node -r ts-node/register bin/test.ts",
"typecheck": "tsc --noEmit"
},
"devDependencies": {
Expand Down
15 changes: 9 additions & 6 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { LokiOptions } from './types/index.js'
import type { LokiOptions } from './types/index'
import { program } from 'commander'
import pkg from '../package.json' assert { type: 'json' }
import build from './index.js'
import pkg from '../package.json'
import build from './index'
import pump from 'pump'

/**
Expand Down Expand Up @@ -54,7 +54,10 @@ export const createPinoLokiConfigFromArgs = () => {
return config
}

const config = createPinoLokiConfigFromArgs()
const pinoLoki = build(config)
function main() {
const config = createPinoLokiConfigFromArgs()
const pinoLoki = build(config)
pump(process.stdin, pinoLoki)
}

pump(process.stdin, pinoLoki)
main()
11 changes: 4 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import abstractTransportBuild from 'pino-abstract-transport'
import { PinoLog, LokiOptions } from './types/index.js'
import { LogPusher } from './log_pusher/index.js'
import debug from './debug.js'

// @ts-ignore
const build = abstractTransportBuild as typeof abstractTransportBuild.default
import { PinoLog, LokiOptions } from './types/index'
import { LogPusher } from './log_pusher/index'
import debug from './debug'

/**
* Resolves the options for the Pino Loki transport
Expand All @@ -30,7 +27,7 @@ function pinoLoki(userOptions: LokiOptions) {
let batchInterval: NodeJS.Timer | undefined
let pinoLogBuffer: PinoLog[] = []

return build(
return abstractTransportBuild(
async (source) => {
if (options.batching) {
batchInterval = setInterval(async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/log_builder/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LokiLog, LokiLogLevel, PinoLog } from '../types/index.js'
import { LokiLog, LokiLogLevel, PinoLog } from '../types/index'

const NANOSECONDS_LENGTH = 19

Expand Down
6 changes: 3 additions & 3 deletions src/log_pusher/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { PinoLog, LokiOptions } from '../types/index.js'
import { LogBuilder } from '../log_builder/index.js'
import debug from '../debug.js'
import { PinoLog, LokiOptions } from '../types/index'
import { LogBuilder } from '../log_builder/index'
import debug from '../debug'
import got, { Got, RequestError } from 'got'

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/loki.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { test } from '@japa/runner'
import pinoLoki from '../../src/index.js'
import pinoLoki from '../../src/index'
import { pino } from 'pino'
import { LokiClient } from '../../tests_helpers/index.js'
import { LokiClient } from '../../tests_helpers/index'
import { randomUUID } from 'crypto'
import { sleep } from '../../src/utils/index.js'
import { LokiOptions } from '../../src/types/index.js'
import { sleep } from '../../src/utils/index'
import { LokiOptions } from '../../src/types/index'

const credentials = {
host: process.env.LOKI_HOST!,
Expand Down Expand Up @@ -99,7 +99,7 @@ test.group('Loki integration', () => {
const application = randomUUID()

const logger = pino.transport<LokiOptions>({
target: '../../dist/index.mjs',
target: '../../dist/index.cjs',

options: {
...credentials,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/cli.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@japa/runner'
import { createPinoLokiConfigFromArgs } from '../../src/cli.js'
import { createPinoLokiConfigFromArgs } from '../../src/cli'

test.group('Cli', () => {
test('Should parse custom labels', ({ assert }) => {
Expand Down
6 changes: 3 additions & 3 deletions tests/unit/log_builder.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test } from '@japa/runner'
import { PinoLog } from '../../src/types/index.js'
import { LogBuilder } from '../../src/log_builder/index.js'
import { sleep } from '../../src/utils/index.js'
import { PinoLog } from '../../src/types/index'
import { LogBuilder } from '../../src/log_builder/index'
import { sleep } from '../../src/utils/index'

const loadNs = process.hrtime()
const loadMs = new Date().getTime()
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/log_pusher.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test } from '@japa/runner'
import { LogPusher } from '../../src/log_pusher/index.js'
import { LogPusher } from '../../src/log_pusher/index'
import nock from 'nock'

test.group('LogPusher', (group) => {
Expand Down
2 changes: 1 addition & 1 deletion tests_helpers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { got } from 'got'
import got from 'got'

interface QueryRangeResponse<StreamType extends Record<string, string>> {
status: string
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{

"ts-node": {
"transpileOnly": true
},

"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"module": "CommonJS",
"lib": ["ESNext"],
"noUnusedLocals": true,
"noUnusedParameters": true,
Expand Down

0 comments on commit 65729e1

Please sign in to comment.