Skip to content

Commit

Permalink
Make it work in both ESM and CJS environment
Browse files Browse the repository at this point in the history
  • Loading branch information
goce-cz committed May 27, 2024
1 parent 522250a commit 29ee3bb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import { readFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'

const loadCerts = async (): Promise<SecureServerOptions> => {
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 {
Expand Down

0 comments on commit 29ee3bb

Please sign in to comment.