From c5eafd1645aac1187f0040beddd85654212084ca Mon Sep 17 00:00:00 2001 From: Andrew Barba Date: Wed, 18 Dec 2024 10:28:37 -0500 Subject: [PATCH] Support both ejs and cjs --- package.json | 23 +++++++++++++++++------ tsconfig.cjs.json | 8 ++++++++ tsconfig.esm.json | 8 ++++++++ tsconfig.json | 7 ++++--- 4 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 tsconfig.cjs.json create mode 100644 tsconfig.esm.json diff --git a/package.json b/package.json index d3ea937..7ed71b9 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,19 @@ { "name": "apns2", - "version": "12.0.0", + "version": "12.1.0-beta.1", "description": "Node client for connecting to Apple's Push Notification Service using the new HTTP/2 protocol with JSON web tokens.", "author": "Andrew Barba ", "license": "MIT", "type": "module", - "main": "dist/index.js", - "types": "dist/index.d.ts", + "main": "./dist/cjs/index.js", + "module": "./dist/esm/index.js", + "types": "./dist/index.d.ts", "exports": { - ".": "./dist/index.js" + ".": { + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js", + "types": "./dist/index.d.ts" + } }, "engines": { "node": ">=20" @@ -16,7 +21,7 @@ "repository": { "url": "https://github.com/AndrewBarba/apns2" }, - "files": ["dist"], + "files": ["dist", "dist/cjs", "dist/esm"], "keywords": [ "apn", "apns", @@ -45,7 +50,13 @@ "vitest": "^2.1.6" }, "scripts": { - "build": "tsc", + "clean": "rm -rf dist", + "build": "npm run clean && npm run build:cjs && npm run build:esm && npm run build:package-files", + "build:cjs": "tsc -p tsconfig.cjs.json", + "build:esm": "tsc -p tsconfig.esm.json", + "build:package-files": "npm run build:package-files:cjs && npm run build:package-files:esm", + "build:package-files:cjs": "echo '{\"type\":\"commonjs\"}' > dist/cjs/package.json", + "build:package-files:esm": "echo '{\"type\":\"module\"}' > dist/esm/package.json", "lint": "biome ci src test", "lint:format": "biome format --write src test", "lint:check": "biome check --write --unsafe src test", diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..0b68e5e --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "moduleResolution": "node", + "outDir": "./dist/cjs" + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..ed5cb26 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "ESNext", + "moduleResolution": "node", + "outDir": "./dist/esm" + } +} diff --git a/tsconfig.json b/tsconfig.json index fee68f7..b6fd9ed 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,8 +2,9 @@ "extends": "@tsconfig/node20", "compilerOptions": { "declaration": true, - "outDir": "dist" + "declarationDir": "./dist", + "outDir": "./dist", + "rootDir": "./src" }, - "include": ["src"], - "exclude": ["dist"] + "include": ["src"] }