Skip to content

Commit

Permalink
Add ESM support, fallback to CommonJS
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmielnik committed Jan 26, 2025
1 parent 835ff9e commit 0609a99
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,17 @@
"engines": {
"node": ">=22"
},
"main": "./build/index.js",
"type": "module",
"main": "./build/cjs/index.js",
"module": "./build/esm/index.js",
"types": "./build/esm/index.d.ts",
"exports": {
".": {
"require": "./build/cjs/index.js",
"import": "./build/esm/index.js",
"types": "./build/esm/index.d.ts"
}
},
"license": "MIT",
"author": {
"name": "Kamil Mielnik",
Expand All @@ -34,15 +44,14 @@
"files": [
"build/**"
],
"types": "./build/index.d.ts",
"np": {
"yarn": false
},
"publishConfig": {
"access": "public"
},
"scripts": {
"build": "tsc --project .",
"build": "tsc --project . && tsc --project tsconfig.cjs.json",
"build:docs": "typedoc",
"clean": "rimraf build coverage docs",
"postbuild": "npm run build:docs",
Expand Down
21 changes: 21 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"declaration": true,
"downlevelIteration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext"],
"module": "commonjs",
"moduleResolution": "node",
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./build/cjs",
"resolveJsonModule": true,
"rootDir": "./src",
"strict": true,
"target": "esnext"
},
"exclude": ["node_modules", "**/*.test.ts"],
"include": ["./src", "index.ts"]
}
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"lib": ["esnext"],
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"noImplicitReturns": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"outDir": "./build",
"outDir": "./build/esm",
"resolveJsonModule": true,
"rootDir": "./src",
"strict": true,
Expand Down

0 comments on commit 0609a99

Please sign in to comment.