From 29ee3bbdbcb223a7e8e415c4ee14c159d312b868 Mon Sep 17 00:00:00 2001 From: jirist Date: Mon, 27 May 2024 14:04:32 +0200 Subject: [PATCH] Make it work in both ESM and CJS environment --- package.json | 2 +- src/index.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index a0ebf0c..cc30e39 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "scripts": { "dev": "tsx src/index.ts", - "build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/oauth.cjs --minify && chmod +x dist/oauth.cjs", + "build": "esbuild src/index.ts --bundle --platform=node --outfile=dist/oauth.cjs '--external:*.pem' --minify && chmod +x dist/oauth.cjs", "prettify": "prettier --write ." }, "dependencies": { diff --git a/src/index.ts b/src/index.ts index 7f5c4f6..1d5e3ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,11 +9,11 @@ import { readFile } from 'node:fs/promises' import { fileURLToPath } from 'node:url' const loadCerts = async (): Promise => { - const isCjs = !!global.require + const isCjs = !import.meta.resolve if (isCjs) { return { - cert: await readFile(global.require.resolve('./cert.pem')), - key: await readFile(global.require.resolve('./key.pem')), + cert: await readFile(require.resolve('./cert.pem')), + key: await readFile(require.resolve('./key.pem')), } } else { return {