Skip to content

Commit

Permalink
chore: support esm syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
stuft2 committed Sep 20, 2024
1 parent 2a3bbee commit 4e81c6f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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 @@ -16,7 +20,7 @@ export function isProduction (): boolean {

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

0 comments on commit 4e81c6f

Please sign in to comment.