Implements Cloudflare Workers target with export conditions matching Wrangler's behavior:
- workerd (first priority - Cloudflare's runtime)
- worker (second priority - generic web worker)
- browser (third priority - browser-compatible code)
This matches the official Wrangler bundler behavior as documented in:
https://github.com/cloudflare/workers-sdk/blob/main/packages/wrangler/src/deployment-bundle/bundle.ts#L51-L88
Like node and bun targets, cloudflare is a server-side target that:
- Uses isServerSide() = true
- Prefers module field over main in package.json
- Uses .esm output format (not .esm_ascii like bun target)
Changes:
- Added cloudflare to options.Target enum
- Added cloudflare to Api.Target enum
- Configured default export conditions for cloudflare target (workerd, worker, browser)
- Updated all switch statements to handle cloudflare case
- Refactored CLI argument parser to use ComptimeStringMap instead of ExactSizeMatcher
- Added comprehensive test suite in test/bundler/bundler_cloudflare.test.ts
Tests verify:
- workerd condition has highest priority
- Falls back to worker then browser conditions
- Falls back to default when no cloudflare-related conditions match
- Handles nested exports with conditions
- Works with multiple packages using different conditions
- Prefers module field like other server-side targets
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>