From 3fce88952030ca3a74a9ff5a3faeb4eb211b86b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Rzepecki?= Date: Sun, 13 Oct 2024 11:52:20 +0200 Subject: [PATCH] feat: Build CommonJS modules in addition to ESM --- package.json | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bf3cfae..1052d60 100644 --- a/package.json +++ b/package.json @@ -59,11 +59,18 @@ ], "type": "module", "exports": { - ".": "./dist/index.js", - "./jwt": "./dist/core/jwt.js", + ".": { + "require": "./dist/index.cjs", + "default": "./dist/index.js" + }, + "./jwt": { + "require": "./dist/core/jwt.cjs", + "default": "./dist/core/jwt.js" + }, "./google": { "types": "./dist/google/index.d.ts", "import": "./dist/google/index.js", + "require": "./dist/google/index.cjs", "default": "./dist/google/index.js" }, "./package.json": "./package.json" @@ -71,7 +78,7 @@ "scripts": { "lint": "eslint --report-unused-disable-directives .", "test": "node --experimental-vm-modules $(yarn bin jest)", - "build": "rm -rf ./dist && yarn tsc" + "build": "rm -rf ./dist && yarn tsc && BABEL_ENV=commonjs yarn babel dist --extensions .js --out-dir dist --out-file-extension .cjs" }, "dependencies": { "jose": ">= 4.12.0 < 5.0.0", @@ -116,7 +123,32 @@ } } ] - ] + ], + "env": { + "commonjs": { + "presets": [ + [ + "@babel/preset-env", + { + "targets": { + "node": "current" + }, + "modules": "commonjs" + } + ] + ], + "plugins": [ + [ + "replace-import-extension", + { + "extMapping": { + ".js": ".cjs" + } + } + ] + ] + } + } }, "eslintConfig": { "root": true,