From 60ebf25fc2eaa2f29c15636c76b6b04ad89a7497 Mon Sep 17 00:00:00 2001 From: rhettjay Date: Wed, 9 Oct 2024 01:01:30 -0600 Subject: [PATCH] refactor: remove unnecessary checks --- src/logger.ts | 6 +++--- src/util.ts | 15 --------------- tsconfig.cjs.json | 9 +++++++-- tsconfig.json | 8 +++++++- 4 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/logger.ts b/src/logger.ts index 98504ba..33ec299 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -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 = { @@ -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\'' } } } } diff --git a/src/util.ts b/src/util.ts index 154b92c..750cf39 100644 --- a/src/util.ts +++ b/src/util.ts @@ -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 = { production: 'info', test: 'silent', @@ -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 { return typeof value === 'object' && value !== null } diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json index d79581a..da26bd4 100644 --- a/tsconfig.cjs.json +++ b/tsconfig.cjs.json @@ -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" diff --git a/tsconfig.json b/tsconfig.json index c624ec8..65c7d5f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"