Skip to content

Commit

Permalink
chore: fix exports definition to support both ESM and CJS
Browse files Browse the repository at this point in the history
  • Loading branch information
duniul committed Sep 19, 2023
1 parent ebdb1f7 commit 33690e2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/curly-beers-jump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'better-ajv-errors': patch
---

Fix exports definition for ESM and CJS types.
14 changes: 8 additions & 6 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ const { copy } = require('esbuild-plugin-copy');

const isEsmBuild = process.argv[2] !== '--cjs';

const copyTypingsPlugin = copy({
assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }],
});

const config = {
cjs: {
format: 'cjs',
platform: 'node',
outdir: './lib/cjs',
plugins: [copyTypingsPlugin],
plugins: [
copy({
assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }],
}),
],
},
esm: {
format: 'esm',
Expand All @@ -39,7 +39,9 @@ const config = {
});
},
},
copyTypingsPlugin,
copy({
assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.mts'] }],
}),
],
},
};
Expand Down
13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
"main": "./lib/cjs/index.js",
"exports": {
".": {
"require": "./lib/cjs/index.js",
"import": {
"types": "./lib/esm/typings.d.mts",
"default": "./lib/esm/index.mjs"
},
"require": {
"types": "./lib/cjs/typings.d.ts",
"default": "./lib/cjs/index.js"
}
}
},
"module": "./lib/esm/index.mjs",
Expand All @@ -26,10 +32,9 @@
"Tong Li"
],
"license": "Apache-2.0",
"types": "./typings.d.ts",
"types": "./lib/cjs/typings.d.ts",
"files": [
"lib",
"typings.d.ts"
"lib"
],
"scripts": {
"prebuild": "rm -rf lib",
Expand Down

0 comments on commit 33690e2

Please sign in to comment.