Skip to content

Commit 5db1887

Browse files
committed
fix: generate types once to separate lib/types directory
Previously, DTS files were generated twice (for ESM and CJS) which caused out-of-memory errors in CI due to worker memory limits. Changes: - Generate types once to lib/types/ using dts: { only: true } - ESM and CJS builds no longer generate their own types - Simplify package.json exports to use single types path - Extract shared entry config to reduce duplication This follows the pattern used by Stripe SDK and Hono, where types are kept in a separate directory and shared between ESM/CJS consumers. Build time reduced from ~48s to ~22s.
1 parent 0b00ff0 commit 5db1887

File tree

2 files changed

+34
-45
lines changed

2 files changed

+34
-45
lines changed

package.json

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"type": "module",
1515
"main": "./lib/cjs/index.cjs",
1616
"module": "./lib/esm/index.js",
17-
"types": "./lib/esm/index.d.ts",
17+
"types": "./lib/types/index.d.ts",
1818
"files": [
1919
"lib/",
2020
"package.json"
@@ -75,10 +75,7 @@
7575
},
7676
"exports": {
7777
".": {
78-
"types": {
79-
"require": "./lib/cjs/index.d.cts",
80-
"import": "./lib/esm/index.d.ts"
81-
},
78+
"types": "./lib/types/index.d.ts",
8279
"workerd": {
8380
"import": "./lib/esm/index.worker.js",
8481
"require": "./lib/cjs/index.worker.cjs"
@@ -105,19 +102,13 @@
105102
"default": "./lib/esm/index.js"
106103
},
107104
"./client": {
108-
"types": {
109-
"require": "./lib/cjs/index.client.d.cts",
110-
"import": "./lib/esm/index.client.d.ts"
111-
},
105+
"types": "./lib/types/index.client.d.ts",
112106
"import": "./lib/esm/index.client.js",
113107
"require": "./lib/cjs/index.client.cjs",
114108
"default": "./lib/esm/index.client.js"
115109
},
116110
"./worker": {
117-
"types": {
118-
"require": "./lib/cjs/index.worker.d.cts",
119-
"import": "./lib/esm/index.worker.d.ts"
120-
},
111+
"types": "./lib/types/index.worker.d.ts",
121112
"import": "./lib/esm/index.worker.js",
122113
"require": "./lib/cjs/index.worker.cjs",
123114
"default": "./lib/esm/index.worker.js"

tsup.config.ts

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
11
import { defineConfig } from 'tsup';
22
import { fixImportsPlugin } from 'esbuild-fix-imports-plugin';
33

4+
const 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+
413
export default defineConfig([
5-
// ESM build
14+
// Types only
615
{
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-
],
16+
entry,
1517
format: 'esm',
16-
outDir: 'lib/esm',
17-
splitting: false,
18-
target: 'es2022',
19-
sourcemap: true,
20-
clean: true,
18+
outDir: 'lib/types',
2119
dts: {
20+
only: true, // Only emit declarations, no JS
2221
resolve: true,
2322
compilerOptions: {
2423
lib: ['dom', 'es2022'],
2524
types: ['node'],
2625
},
2726
},
2827
bundle: false,
28+
},
29+
// ESM build - no types
30+
{
31+
entry,
32+
format: 'esm',
33+
outDir: 'lib/esm',
34+
splitting: false,
35+
target: 'es2022',
36+
sourcemap: true,
37+
clean: true,
38+
dts: false,
39+
bundle: false,
2940
outExtension() {
3041
return { js: '.js' };
3142
},
@@ -34,32 +45,19 @@ export default defineConfig([
3445
},
3546
esbuildPlugins: [fixImportsPlugin()],
3647
},
37-
// CJS build
48+
// CJS build - no types
3849
{
39-
entry: [
40-
'src/**/*.ts',
41-
'!src/**/*.spec.ts',
42-
'!src/**/*.test.ts',
43-
'!src/**/fixtures/**',
44-
'!src/**/*.d.ts',
45-
'!src/**/test-utils.ts',
46-
],
50+
entry,
4751
format: 'cjs',
4852
outDir: 'lib/cjs',
4953
splitting: false,
5054
target: 'es2022',
5155
sourcemap: true,
52-
clean: false, // Don't clean, keep ESM files
53-
dts: {
54-
resolve: true,
55-
compilerOptions: {
56-
lib: ['dom', 'es2022'],
57-
types: ['node'],
58-
},
59-
},
56+
clean: false,
57+
dts: false,
6058
bundle: false,
6159
outExtension() {
62-
return { js: '.cjs', dts: '.d.cts' };
60+
return { js: '.cjs' };
6361
},
6462
esbuildOptions(options) {
6563
options.keepNames = true;

0 commit comments

Comments
 (0)