Skip to content

Commit

Permalink
refactor: remove unnecessary checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rhettjay committed Oct 9, 2024
1 parent 41fbdec commit 60ebf25
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import deepmerge from 'deepmerge'
import { Logger, LoggerOptions, pino } from 'pino'
import { getLevel, isInstalled, isProduction } from './util.js'
import { getLevel, isProduction } from './util.js'

export function ByuLogger (options?: LoggerOptions): Logger {
const defaultOptions: LoggerOptions = {
Expand All @@ -18,10 +18,10 @@ export function ByuLogger (options?: LoggerOptions): Logger {
// if in local environment and not running tests try to pretty print logs
// jest and pretty-print don't get along (causes open handles and sometimes doesn't close),
// so we'll default to not include pretty-print if running tests
...!isProduction() && process.env.NODE_ENV !== 'test' && isInstalled('pino-pretty') && {
...!isProduction() && process.env.NODE_ENV !== 'test' && {
transport: {
target: 'pino-pretty',
options: { translateTime: 'UTC:yyyy-mm-dd\'T\'HH:MM:ss.l\'Z\'' }
options: { sync: true, translateTime: 'UTC:yyyy-mm-dd\'T\'HH:MM:ss.l\'Z\'' }
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { createRequire } from 'node:module'
import Pino from 'pino'

// @ts-ignore
const nodeRequire = createRequire(import.meta.url)

const ENV_LEVELS: Record<string, Pino.LevelWithSilent> = {
production: 'info',
test: 'silent',
Expand All @@ -18,17 +14,6 @@ export function isProduction (): boolean {
return process.env.NODE_ENV === 'production'
}

export function isInstalled (name: string): boolean {
try {
return nodeRequire(name) !== null
} catch (e) {
if (isRecord(e) && hasProperty(e, 'code') && e.code === 'MODULE_NOT_FOUND') {
return false
}
throw e
}
}

export function isRecord (value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
}
Expand Down
9 changes: 7 additions & 2 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"extends": "@tsconfig/node-lts/tsconfig.json",
"compilerOptions": {
"target": "es2022",
"declaration": true,
"declarationMap": true,
"module": "CommonJS",
"moduleResolution": "node",
"declarationDir": "dist/cjs",
"outDir": "dist/cjs"
"outDir": "dist/cjs",
"esModuleInterop": true,
"importHelpers": true,
"strict": true,
"skipLibCheck": true
},
"include": [
"src"
Expand Down
8 changes: 7 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"extends": "@tsconfig/node18/tsconfig.json",
"compilerOptions": {
"lib": ["es2023"],
"module": "node16",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"moduleResolution": "node16",
"declaration": true,
"declarationDir": "dist/esm",
"outDir": "dist/esm"
Expand Down

0 comments on commit 60ebf25

Please sign in to comment.