Skip to content

Commit f9f196f

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 } - Remove resolve: true to reduce memory usage (external types are referenced rather than inlined) - 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 - Add NODE_OPTIONS to CI for additional memory headroom This follows the pattern used by Stripe SDK and Hono, where types are kept in a separate directory and shared between ESM/CJS consumers.
1 parent 0b00ff0 commit f9f196f

File tree

4 files changed

+39
-48
lines changed

4 files changed

+39
-48
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,9 @@ jobs:
3636
npm run lint
3737
3838
- name: Build
39-
run: |
40-
npm run build
39+
run: npm run build
40+
env:
41+
NODE_OPTIONS: '--max-old-space-size=4096'
4142

4243
- name: Test
4344
run: |

.github/workflows/runtime-tests.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ jobs:
1919
run: |
2020
npm install
2121
npm run build
22+
env:
23+
NODE_OPTIONS: '--max-old-space-size=4096'
2224

2325
- name: Runtime compatibility check
2426
run: npm run check:runtimes

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 & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
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: {
22-
resolve: true,
20+
only: true, // Only emit declarations, no JS
2321
compilerOptions: {
2422
lib: ['dom', 'es2022'],
2523
types: ['node'],
2624
},
2725
},
2826
bundle: false,
27+
},
28+
// ESM build - no types
29+
{
30+
entry,
31+
format: 'esm',
32+
outDir: 'lib/esm',
33+
splitting: false,
34+
target: 'es2022',
35+
sourcemap: true,
36+
clean: true,
37+
dts: false,
38+
bundle: false,
2939
outExtension() {
3040
return { js: '.js' };
3141
},
@@ -34,32 +44,19 @@ export default defineConfig([
3444
},
3545
esbuildPlugins: [fixImportsPlugin()],
3646
},
37-
// CJS build
47+
// CJS build - no types
3848
{
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-
],
49+
entry,
4750
format: 'cjs',
4851
outDir: 'lib/cjs',
4952
splitting: false,
5053
target: 'es2022',
5154
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-
},
55+
clean: false,
56+
dts: false,
6057
bundle: false,
6158
outExtension() {
62-
return { js: '.cjs', dts: '.d.cts' };
59+
return { js: '.cjs' };
6360
},
6461
esbuildOptions(options) {
6562
options.keepNames = true;

0 commit comments

Comments
 (0)