Skip to content

[v8] fix: migrate from tsup to tsdown for faster, lower-memory builds#1413

Merged
nicknisi merged 6 commits intoversion-8from
nicknisi/v8-build-improvements
Dec 4, 2025
Merged

[v8] fix: migrate from tsup to tsdown for faster, lower-memory builds#1413
nicknisi merged 6 commits intoversion-8from
nicknisi/v8-build-improvements

Conversation

@nicknisi
Copy link
Member

@nicknisi nicknisi commented Dec 4, 2025

Description

Migrate from tsup to tsdown to fix CI out-of-memory errors during TypeScript declaration generation.

Problem

The build was hitting ERR_WORKER_OUT_OF_MEMORY errors in CI on Node 20 and 22. With 297 source files and tsup's worker-based DTS generation, the memory requirements were too high.

Solution

Replace tsup with tsdown, a modern bundler powered by Rolldown (Rust-based) and Oxc. Key benefits:

  • Faster builds: Rolldown is significantly faster than esbuild for bundling
  • Lower memory usage: Oxc-based TypeScript declaration generation is more memory-efficient
  • Same output structure: Maintains the existing lib/esm, lib/cjs, and lib/types directory structure

Changes

  • Replaced tsup with tsdown
  • Removed esbuild-fix-imports-plugin (no longer needed)
  • Created tsdown.config.ts with equivalent configuration
  • Updated build scripts in package.json

Output

  • 297 ESM files (.js) in lib/esm/
  • 297 CJS files (.cjs) in lib/cjs/
  • 296 declaration files (.d.ts) in lib/types/
  • All tests pass (427 passed)

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

[ ] Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@nicknisi nicknisi requested a review from a team as a code owner December 4, 2025 16:50
@nicknisi nicknisi requested review from stanleyphu and removed request for a team December 4, 2025 16:50
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 4, 2025

Greptile Overview

Greptile Summary

This PR migrates from tsup to tsdown to resolve out-of-memory errors during CI builds, leveraging Rolldown's Rust-based bundler and Oxc's memory-efficient TypeScript declaration generation.

Key Changes:

  • Replaced tsup with tsdown in package.json and removed esbuild-fix-imports-plugin
  • Created new tsdown.config.ts with three build configurations: ESM (.js), CJS (.cjs), and types-only (.d.ts)
  • Added NODE_OPTIONS='--max-old-space-size=4096' to CI workflows for additional memory headroom during builds
  • Maintains identical output structure: lib/esm/, lib/cjs/, and lib/types/ directories

Benefits:

  • Faster builds powered by Rolldown (Rust-based, faster than esbuild)
  • Lower memory usage with Oxc-based TypeScript parsing
  • Resolves ERR_WORKER_OUT_OF_MEMORY errors experienced with tsup on Node 20 and 22

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk - it's a build tooling migration that maintains identical output structure
  • The migration is well-designed and low-risk: (1) the configuration precisely mirrors the previous tsup setup, (2) all 427 tests pass, (3) the output structure remains unchanged (lib/esm, lib/cjs, lib/types), (4) the change directly addresses a real CI memory issue, and (5) the approach follows established patterns from other major SDKs like Stripe and Hono
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
tsdown.config.ts 5/5 New tsdown configuration replacing tsup - generates ESM, CJS, and separate TypeScript declarations with memory-efficient Oxc-based DTS generation
package.json 5/5 Replaced tsup with tsdown dependency, removed esbuild-fix-imports-plugin, simplified build scripts
.github/workflows/ci.yml 5/5 Added NODE_OPTIONS with 4GB memory limit for build step to handle TypeScript declaration generation
.github/workflows/runtime-tests.yml 5/5 Added NODE_OPTIONS with 4GB memory limit for build step to handle TypeScript declaration generation

Sequence Diagram

sequenceDiagram
    participant CI as CI Pipeline
    participant Node as Node.js Runtime
    participant tsdown as tsdown CLI
    participant Rolldown as Rolldown Bundler
    participant Oxc as Oxc TypeScript Parser
    participant FS as File System

    CI->>Node: Set NODE_OPTIONS=--max-old-space-size=4096
    CI->>tsdown: npm run build
    tsdown->>tsdown: Load tsdown.config.ts
    
    Note over tsdown: Config 1: ESM Build
    tsdown->>Rolldown: Bundle src/**/*.ts → lib/esm/*.js
    Rolldown->>FS: Write 297 ESM files with sourcemaps
    
    Note over tsdown: Config 2: CJS Build
    tsdown->>Rolldown: Bundle src/**/*.ts → lib/cjs/*.cjs
    Rolldown->>FS: Write 297 CJS files with sourcemaps
    
    Note over tsdown: Config 3: Types Only
    tsdown->>Oxc: Generate declarations from src/**/*.ts
    Oxc->>Oxc: Parse TypeScript (memory-efficient)
    Oxc->>FS: Write 296 .d.ts files to lib/types/
    
    FS->>CI: Build complete
    CI->>CI: Run tests against built output
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

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.
@nicknisi nicknisi force-pushed the nicknisi/v8-build-improvements branch from 660aba3 to f9f196f Compare December 4, 2025 18:37
@nicknisi nicknisi changed the title [v8] fix: generate types once to reduce build memory usage [v8] fix: migrate from tsup to tsdown for faster, lower-memory builds Dec 4, 2025
@nicknisi
Copy link
Member Author

nicknisi commented Dec 4, 2025

@greptileai

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@nicknisi nicknisi merged commit e1d4cd4 into version-8 Dec 4, 2025
8 checks passed
@nicknisi nicknisi deleted the nicknisi/v8-build-improvements branch December 4, 2025 22:25
nicknisi added a commit that referenced this pull request Dec 4, 2025
…#1413)

## Description

Migrate from tsup to tsdown to fix CI out-of-memory errors during
TypeScript declaration generation.

### Problem
The build was hitting `ERR_WORKER_OUT_OF_MEMORY` errors in CI on Node 20
and 22. With 297 source files and tsup's worker-based DTS generation,
the memory requirements were too high.

### Solution
Replace tsup with [tsdown](https://tsdown.dev/), a modern bundler
powered by Rolldown (Rust-based) and Oxc. Key benefits:

- **Faster builds**: Rolldown is significantly faster than esbuild for
bundling
- **Lower memory usage**: Oxc-based TypeScript declaration generation is
more memory-efficient
- **Same output structure**: Maintains the existing `lib/esm`,
`lib/cjs`, and `lib/types` directory structure

### Changes
- Replaced `tsup` with `tsdown` 
- Removed `esbuild-fix-imports-plugin` (no longer needed)
- Created `tsdown.config.ts` with equivalent configuration
- Updated build scripts in `package.json`

### Output
- 297 ESM files (`.js`) in `lib/esm/`
- 297 CJS files (`.cjs`) in `lib/cjs/`
- 296 declaration files (`.d.ts`) in `lib/types/`
- All tests pass (427 passed)

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 16, 2025
…#1413)

## Description

Migrate from tsup to tsdown to fix CI out-of-memory errors during
TypeScript declaration generation.

### Problem
The build was hitting `ERR_WORKER_OUT_OF_MEMORY` errors in CI on Node 20
and 22. With 297 source files and tsup's worker-based DTS generation,
the memory requirements were too high.

### Solution
Replace tsup with [tsdown](https://tsdown.dev/), a modern bundler
powered by Rolldown (Rust-based) and Oxc. Key benefits:

- **Faster builds**: Rolldown is significantly faster than esbuild for
bundling
- **Lower memory usage**: Oxc-based TypeScript declaration generation is
more memory-efficient
- **Same output structure**: Maintains the existing `lib/esm`,
`lib/cjs`, and `lib/types` directory structure

### Changes
- Replaced `tsup` with `tsdown` 
- Removed `esbuild-fix-imports-plugin` (no longer needed)
- Created `tsdown.config.ts` with equivalent configuration
- Updated build scripts in `package.json`

### Output
- 297 ESM files (`.js`) in `lib/esm/`
- 297 CJS files (`.cjs`) in `lib/cjs/`
- 296 declaration files (`.d.ts`) in `lib/types/`
- All tests pass (427 passed)

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Dec 22, 2025
…#1413)

## Description

Migrate from tsup to tsdown to fix CI out-of-memory errors during
TypeScript declaration generation.

### Problem
The build was hitting `ERR_WORKER_OUT_OF_MEMORY` errors in CI on Node 20
and 22. With 297 source files and tsup's worker-based DTS generation,
the memory requirements were too high.

### Solution
Replace tsup with [tsdown](https://tsdown.dev/), a modern bundler
powered by Rolldown (Rust-based) and Oxc. Key benefits:

- **Faster builds**: Rolldown is significantly faster than esbuild for
bundling
- **Lower memory usage**: Oxc-based TypeScript declaration generation is
more memory-efficient
- **Same output structure**: Maintains the existing `lib/esm`,
`lib/cjs`, and `lib/types` directory structure

### Changes
- Replaced `tsup` with `tsdown` 
- Removed `esbuild-fix-imports-plugin` (no longer needed)
- Created `tsdown.config.ts` with equivalent configuration
- Updated build scripts in `package.json`

### Output
- 297 ESM files (`.js`) in `lib/esm/`
- 297 CJS files (`.cjs`) in `lib/cjs/`
- 296 declaration files (`.d.ts`) in `lib/types/`
- All tests pass (427 passed)

## Documentation

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Jan 8, 2026
…#1413)

Migrate from tsup to tsdown to fix CI out-of-memory errors during
TypeScript declaration generation.

The build was hitting `ERR_WORKER_OUT_OF_MEMORY` errors in CI on Node 20
and 22. With 297 source files and tsup's worker-based DTS generation,
the memory requirements were too high.

Replace tsup with [tsdown](https://tsdown.dev/), a modern bundler
powered by Rolldown (Rust-based) and Oxc. Key benefits:

- **Faster builds**: Rolldown is significantly faster than esbuild for
bundling
- **Lower memory usage**: Oxc-based TypeScript declaration generation is
more memory-efficient
- **Same output structure**: Maintains the existing `lib/esm`,
`lib/cjs`, and `lib/types` directory structure

- Replaced `tsup` with `tsdown`
- Removed `esbuild-fix-imports-plugin` (no longer needed)
- Created `tsdown.config.ts` with equivalent configuration
- Updated build scripts in `package.json`

- 297 ESM files (`.js`) in `lib/esm/`
- 297 CJS files (`.cjs`) in `lib/cjs/`
- 296 declaration files (`.d.ts`) in `lib/types/`
- All tests pass (427 passed)

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Jan 9, 2026
…#1413)

Migrate from tsup to tsdown to fix CI out-of-memory errors during
TypeScript declaration generation.

The build was hitting `ERR_WORKER_OUT_OF_MEMORY` errors in CI on Node 20
and 22. With 297 source files and tsup's worker-based DTS generation,
the memory requirements were too high.

Replace tsup with [tsdown](https://tsdown.dev/), a modern bundler
powered by Rolldown (Rust-based) and Oxc. Key benefits:

- **Faster builds**: Rolldown is significantly faster than esbuild for
bundling
- **Lower memory usage**: Oxc-based TypeScript declaration generation is
more memory-efficient
- **Same output structure**: Maintains the existing `lib/esm`,
`lib/cjs`, and `lib/types` directory structure

- Replaced `tsup` with `tsdown`
- Removed `esbuild-fix-imports-plugin` (no longer needed)
- Created `tsdown.config.ts` with equivalent configuration
- Updated build scripts in `package.json`

- 297 ESM files (`.js`) in `lib/esm/`
- 297 CJS files (`.cjs`) in `lib/cjs/`
- 296 declaration files (`.d.ts`) in `lib/types/`
- All tests pass (427 passed)

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
nicknisi added a commit that referenced this pull request Jan 12, 2026
…#1413)

Migrate from tsup to tsdown to fix CI out-of-memory errors during
TypeScript declaration generation.

The build was hitting `ERR_WORKER_OUT_OF_MEMORY` errors in CI on Node 20
and 22. With 297 source files and tsup's worker-based DTS generation,
the memory requirements were too high.

Replace tsup with [tsdown](https://tsdown.dev/), a modern bundler
powered by Rolldown (Rust-based) and Oxc. Key benefits:

- **Faster builds**: Rolldown is significantly faster than esbuild for
bundling
- **Lower memory usage**: Oxc-based TypeScript declaration generation is
more memory-efficient
- **Same output structure**: Maintains the existing `lib/esm`,
`lib/cjs`, and `lib/types` directory structure

- Replaced `tsup` with `tsdown`
- Removed `esbuild-fix-imports-plugin` (no longer needed)
- Created `tsdown.config.ts` with equivalent configuration
- Updated build scripts in `package.json`

- 297 ESM files (`.js`) in `lib/esm/`
- 297 CJS files (`.cjs`) in `lib/cjs/`
- 296 declaration files (`.d.ts`) in `lib/types/`
- All tests pass (427 passed)

Does this require changes to the WorkOS Docs? E.g. the [API
Reference](https://workos.com/docs/reference) or code snippets need
updates.

```
[ ] Yes
```

If yes, link a related docs PR and add a docs maintainer as a reviewer.
Their approval is required.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants