Skip to content

Commit fbe76af

Browse files
committed
fix the ESM/CJS build
1 parent bee7e85 commit fbe76af

File tree

2 files changed

+83
-48
lines changed

2 files changed

+83
-48
lines changed

package.json

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
"node": ">=18"
1717
},
1818
"type": "module",
19-
"main": "./lib/index.cjs",
20-
"module": "./lib/index.js",
21-
"types": "./lib/index.d.ts",
19+
"main": "./lib/cjs/index.cjs",
20+
"module": "./lib/esm/index.js",
21+
"types": "./lib/esm/index.d.ts",
2222
"files": [
2323
"lib/",
2424
"package.json"
@@ -54,14 +54,17 @@
5454
"@babel/preset-typescript": "^7.27.0",
5555
"@eslint/js": "^9.21.0",
5656
"@types/cookie": "^0.6.0",
57+
"@types/glob": "^8.1.0",
5758
"@types/jest": "^29.5.14",
5859
"@types/node": "~18",
5960
"@types/pluralize": "0.0.33",
6061
"@typescript-eslint/parser": "^8.25.0",
6162
"babel-jest": "^29.7.0",
63+
"esbuild-fix-imports-plugin": "^1.0.21",
6264
"eslint": "^9.21.0",
6365
"eslint-plugin-jest": "^28.11.0",
6466
"eslint-plugin-n": "^17.15.1",
67+
"glob": "^11.0.3",
6568
"jest": "29.7.0",
6669
"jest-environment-miniflare": "^2.14.2",
6770
"jest-fetch-mock": "^3.0.3",
@@ -75,24 +78,24 @@
7578
},
7679
"exports": {
7780
".": {
78-
"types": "./lib/index.d.ts",
81+
"types": "./lib/esm/index.d.ts",
7982
"workerd": {
80-
"import": "./lib/index.worker.js",
81-
"require": "./lib/index.worker.cjs"
83+
"import": "./lib/esm/index.worker.js",
84+
"require": "./lib/cjs/index.worker.cjs"
8285
},
8386
"edge-light": {
84-
"import": "./lib/index.worker.js",
85-
"require": "./lib/index.worker.cjs"
87+
"import": "./lib/esm/index.worker.js",
88+
"require": "./lib/cjs/index.worker.cjs"
8689
},
87-
"import": "./lib/index.js",
88-
"require": "./lib/index.cjs",
89-
"default": "./lib/index.js"
90+
"import": "./lib/esm/index.js",
91+
"require": "./lib/cjs/index.cjs",
92+
"default": "./lib/esm/index.js"
9093
},
9194
"./worker": {
92-
"types": "./lib/index.worker.d.ts",
93-
"import": "./lib/index.worker.js",
94-
"require": "./lib/index.worker.cjs",
95-
"default": "./lib/index.worker.js"
95+
"types": "./lib/esm/index.worker.d.ts",
96+
"import": "./lib/esm/index.worker.js",
97+
"require": "./lib/cjs/index.worker.cjs",
98+
"default": "./lib/esm/index.worker.js"
9699
},
97100
"./package.json": "./package.json"
98101
}

tsup.config.ts

Lines changed: 65 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,69 @@
11
import { defineConfig } from 'tsup';
2+
import { fixImportsPlugin } from 'esbuild-fix-imports-plugin';
23

3-
export default defineConfig({
4-
entry: [
5-
'src/**/*.ts',
6-
'!src/**/*.spec.ts',
7-
'!src/**/*.test.ts',
8-
'!src/**/fixtures/**',
9-
'!src/**/*.d.ts',
10-
'!src/**/test-utils.ts',
11-
],
12-
format: ['cjs', 'esm'],
13-
dts: {
14-
resolve: true,
15-
compilerOptions: {
16-
lib: ['dom', 'es2022'],
17-
types: ['node'],
4+
export default defineConfig([
5+
// ESM build
6+
{
7+
entry: [
8+
'src/**/*.ts',
9+
'!src/**/*.spec.ts',
10+
'!src/**/*.test.ts',
11+
'!src/**/fixtures/**',
12+
'!src/**/*.d.ts',
13+
'!src/**/test-utils.ts',
14+
],
15+
format: 'esm',
16+
outDir: 'lib/esm',
17+
splitting: false,
18+
target: 'es2022',
19+
sourcemap: true,
20+
clean: true,
21+
dts: {
22+
resolve: true,
23+
compilerOptions: {
24+
lib: ['dom', 'es2022'],
25+
types: ['node'],
26+
},
1827
},
28+
bundle: false,
29+
external: ['iron-session', 'jose', 'leb', 'pluralize'],
30+
outExtension() {
31+
return { js: '.js' };
32+
},
33+
esbuildOptions(options) {
34+
options.keepNames = true;
35+
},
36+
esbuildPlugins: [
37+
fixImportsPlugin()
38+
]
1939
},
20-
bundle: false,
21-
sourcemap: true,
22-
clean: true,
23-
target: 'es2022',
24-
platform: 'node',
25-
outDir: 'lib',
26-
splitting: false,
27-
external: ['iron-session', 'jose', 'leb', 'pluralize'],
28-
outExtension({ format }) {
29-
return {
30-
js: format === 'cjs' ? '.cjs' : '.js',
31-
};
32-
},
33-
esbuildOptions(options, { format }) {
34-
options.keepNames = true;
35-
},
36-
});
37-
40+
// CJS build
41+
{
42+
entry: [
43+
'src/**/*.ts',
44+
'!src/**/*.spec.ts',
45+
'!src/**/*.test.ts',
46+
'!src/**/fixtures/**',
47+
'!src/**/*.d.ts',
48+
'!src/**/test-utils.ts',
49+
],
50+
format: 'cjs',
51+
outDir: 'lib/cjs',
52+
splitting: false,
53+
target: 'es2022',
54+
sourcemap: true,
55+
clean: false, // Don't clean, keep ESM files
56+
dts: false, // Only generate types once (in ESM build)
57+
bundle: false,
58+
external: ['iron-session', 'jose', 'leb', 'pluralize'],
59+
outExtension() {
60+
return { js: '.cjs' };
61+
},
62+
esbuildOptions(options) {
63+
options.keepNames = true;
64+
},
65+
esbuildPlugins: [
66+
fixImportsPlugin()
67+
]
68+
}
69+
]);

0 commit comments

Comments
 (0)