Skip to content

Commit

Permalink
[Lib/JS] Compile svix package for ESM and CommonJS (#1549)
Browse files Browse the repository at this point in the history
Closes #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.
  • Loading branch information
svix-lucho authored Dec 4, 2024
1 parent 9b6cf7c commit 633015f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
23 changes: 17 additions & 6 deletions javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,36 @@
{
"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",
"webhooks",
"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",
Expand Down Expand Up @@ -49,4 +60,4 @@
"ts-jest": "^29.2.5",
"typescript": "^4.0"
}
}
}
15 changes: 9 additions & 6 deletions javascript/tsconfig.json → javascript/tsconfig.cjs.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,27 @@
"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",
"node_modules",
"jest.config.js",
"src/**/*.test.ts",
],
"filesGlob": ["./src/**/*.ts"]
}
"filesGlob": [
"./src/**/*.ts"
]
}
33 changes: 33 additions & 0 deletions javascript/tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

0 comments on commit 633015f

Please sign in to comment.