From 633015f06ba21c680054f876784df41fd09b43b6 Mon Sep 17 00:00:00 2001 From: svix-lucho <133019767+svix-lucho@users.noreply.github.com> Date: Wed, 4 Dec 2024 18:24:54 -0300 Subject: [PATCH] [Lib/JS] Compile svix package for ESM and CommonJS (#1549) Closes https://github.com/svix/svix-webhooks/issues/1483 Compile the svix JavaScript package in `ESM` and `CommonJS` simultaneously. This should solve the issues with tree-shaking (since it can only be done when the package is compiled with ESM). Also keeps the CommonJS version for backwards compatibility. Tested this locally and all the usual imports (`import { EventTypeOut } from "svix"`) work as expected, with no changes whatsoever. --- javascript/package.json | 23 +++++++++---- .../{tsconfig.json => tsconfig.cjs.json} | 15 +++++---- javascript/tsconfig.esm.json | 33 +++++++++++++++++++ 3 files changed, 59 insertions(+), 12 deletions(-) rename javascript/{tsconfig.json => tsconfig.cjs.json} (87%) create mode 100644 javascript/tsconfig.esm.json diff --git a/javascript/package.json b/javascript/package.json index 0ef3830a0..da4e22c29 100644 --- a/javascript/package.json +++ b/javascript/package.json @@ -1,10 +1,9 @@ { "name": "svix", - "version": "1.42.0", + "version": "1.41.0", "description": "Svix webhooks API client and webhook verification library", "author": "svix", "repository": "https://github.com/svix/svix-libs", - "type": "commonjs", "keywords": [ "svix", "diahook", @@ -12,14 +11,26 @@ "typescript" ], "license": "MIT", - "main": "./dist/index.js", - "typings": "./dist/index.d.ts", + "main": "./dist/cjs/index.js", + "types": "./dist/esm/index.d.ts", + "exports": { + ".": { + "types": "./dist/esm/index.d.ts", + "import": "./dist/esm/index.js", + "require": "./dist/cjs/index.js" + }, + "./dist/*": { + "types": "./dist/esm/*/index.d.ts", + "import": "./dist/esm/*/index.js", + "require": "./dist/cjs/*/index.js" + } + }, "files": [ "src", "dist" ], "scripts": { - "build": "tsc", + "build": "tsc --project tsconfig.cjs.json && tsc --project tsconfig.esm.json", "prepare": "yarn run build", "test": "jest", "prepublishOnly": "yarn lint", @@ -49,4 +60,4 @@ "ts-jest": "^29.2.5", "typescript": "^4.0" } -} +} \ No newline at end of file diff --git a/javascript/tsconfig.json b/javascript/tsconfig.cjs.json similarity index 87% rename from javascript/tsconfig.json rename to javascript/tsconfig.cjs.json index 663287a83..de8b5d728 100644 --- a/javascript/tsconfig.json +++ b/javascript/tsconfig.cjs.json @@ -7,18 +7,19 @@ "moduleResolution": "node", "declaration": true, "allowJs": true, - /* Additional Checks */ "noUnusedLocals": false /* Report errors on unused locals. */, // TODO: reenable (unused imports!) "noUnusedParameters": false /* Report errors on unused parameters. */, // TODO: set to true again "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, - "removeComments": true, "sourceMap": true, - "outDir": "./dist", + "outDir": "./dist/cjs", "noLib": false, - "lib": ["es6", "dom"] + "lib": [ + "es6", + "dom" + ] }, "exclude": [ "dist", @@ -26,5 +27,7 @@ "jest.config.js", "src/**/*.test.ts", ], - "filesGlob": ["./src/**/*.ts"] -} + "filesGlob": [ + "./src/**/*.ts" + ] +} \ No newline at end of file diff --git a/javascript/tsconfig.esm.json b/javascript/tsconfig.esm.json new file mode 100644 index 000000000..afc038f4c --- /dev/null +++ b/javascript/tsconfig.esm.json @@ -0,0 +1,33 @@ +{ + "compilerOptions": { + "strict": true, + /* Basic Options */ + "target": "es6", + "module": "ESNext", + "moduleResolution": "node", + "declaration": true, + "allowJs": true, + /* Additional Checks */ + "noUnusedLocals": false /* Report errors on unused locals. */, // TODO: reenable (unused imports!) + "noUnusedParameters": false /* Report errors on unused parameters. */, // TODO: set to true again + "noImplicitReturns": true /* Report error when not all code paths in function return a value. */, + "noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */, + "removeComments": true, + "sourceMap": true, + "outDir": "./dist/esm", + "noLib": false, + "lib": [ + "es6", + "dom" + ] + }, + "exclude": [ + "dist", + "node_modules", + "jest.config.js", + "src/**/*.test.ts", + ], + "filesGlob": [ + "./src/**/*.ts" + ] +} \ No newline at end of file