Skip to content

Commit 33690e2

Browse files
committed
chore: fix exports definition to support both ESM and CJS
1 parent ebdb1f7 commit 33690e2

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

.changeset/curly-beers-jump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'better-ajv-errors': patch
3+
---
4+
5+
Fix exports definition for ESM and CJS types.

build.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ const { copy } = require('esbuild-plugin-copy');
99

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

12-
const copyTypingsPlugin = copy({
13-
assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }],
14-
});
15-
1612
const config = {
1713
cjs: {
1814
format: 'cjs',
1915
platform: 'node',
2016
outdir: './lib/cjs',
21-
plugins: [copyTypingsPlugin],
17+
plugins: [
18+
copy({
19+
assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.ts'] }],
20+
}),
21+
],
2222
},
2323
esm: {
2424
format: 'esm',
@@ -39,7 +39,9 @@ const config = {
3939
});
4040
},
4141
},
42-
copyTypingsPlugin,
42+
copy({
43+
assets: [{ from: ['./typings.d.ts'], to: ['./typings.d.mts'] }],
44+
}),
4345
],
4446
},
4547
};

package.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
"main": "./lib/cjs/index.js",
77
"exports": {
88
".": {
9-
"require": "./lib/cjs/index.js",
9+
"import": {
10+
"types": "./lib/esm/typings.d.mts",
1011
"default": "./lib/esm/index.mjs"
12+
},
13+
"require": {
14+
"types": "./lib/cjs/typings.d.ts",
15+
"default": "./lib/cjs/index.js"
16+
}
1117
}
1218
},
1319
"module": "./lib/esm/index.mjs",
@@ -26,10 +32,9 @@
2632
"Tong Li"
2733
],
2834
"license": "Apache-2.0",
29-
"types": "./typings.d.ts",
35+
"types": "./lib/cjs/typings.d.ts",
3036
"files": [
31-
"lib",
32-
"typings.d.ts"
37+
"lib"
3338
],
3439
"scripts": {
3540
"prebuild": "rm -rf lib",

0 commit comments

Comments
 (0)