Skip to content

Conversation

@dmmulroy
Copy link

@dmmulroy dmmulroy commented Dec 15, 2025

Problem

  1. consumers cant tree-shake - tsc preserves internal structure, bundlers pull entire lib
  2. missing sockets export - @cloudflare/actors/sockets not exposed
  3. types condition missing - exports lack types field, TS resolution unreliable
  4. deep dist paths - dist/core/src/index.js leaks internal structure
  5. legacy typesVersions - redundant w/ modern exports
  6. consumer vitest tests fail - missing workerd + default conditions breaks vitest-pool-workers import resolution

Solution

tsdown bundles each entry point into flat output. conditional exports with types/workerd/import/default conditions ensure resolution works in all contexts (TS, workerd, Node, bundlers).

Changes

  • add tsdown.config.ts with multi-entry points
  • update package.json exports with types/workerd/import/default conditions
  • add ./sockets export, remove typesVersions
  • flatten dist: dist/core/index.js not dist/core/src/index.js
  • fix Entrypoint class type issues with WorkerEntrypoint

Verification

  • pnpm build produces flat dist
  • tree-shaking verified via esbuild:
    • @cloudflare/actors/storage → 6.5KB (no Alarms/Sockets code)
    • @cloudflare/actors (full Actor) → 52.5KB
    • ~8x reduction when importing subpath only
  • consumer vitest tests pass with vitest-pool-workers:
    • imports Actor from @cloudflare/actors
    • imports Storage from @cloudflare/actors/storage
    • imports Alarms from @cloudflare/actors/alarms

@dmmulroy dmmulroy marked this pull request as draft December 15, 2025 20:13
@dmmulroy dmmulroy force-pushed the feat/tsup-bundling branch 2 times, most recently from 46d6bc2 to 5af6223 Compare December 15, 2025 21:49
- add tsdown.config.ts with multi-entry points
- update package.json exports with types/workerd/import/default conditions
- add ./sockets export, remove typesVersions
- flatten dist: dist/core/index.js (not dist/core/src/index.js)
- fix Entrypoint class type issues with WorkerEntrypoint
@dmmulroy dmmulroy changed the title migrate to tsup w/ flat dist structure migrate to tsdown w/ flat dist structure Dec 15, 2025
@dmmulroy dmmulroy changed the title migrate to tsdown w/ flat dist structure migrate to tsdown with flat dist structure Dec 15, 2025
@dmmulroy dmmulroy changed the title migrate to tsdown with flat dist structure feat: migrate to tsdown with flat dist structure Dec 15, 2025
@dmmulroy dmmulroy marked this pull request as ready for review December 17, 2025 18:20
"description": "An easier way to build with Cloudflare Durable Objects",
"type": "module",
"main": "./dist/index.js",
"main": "./dist/core/index.js",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This would break existing users importing the entire package index, which was the intention I believe here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants