Repository navigation
feat(bundle-size): add Cloudflare Workers bundle via wrangler - #690
Conversation
Adds a CF Workers variant to the bundle-size fixture, alongside the
existing Node postgres and mongo entries. Two new entries (no-emit + emit)
bundle a worker that imports `@prisma-next/postgres/serverless` and runs
the same `SELECT id FROM "Note" LIMIT 10` query — same shape as the
existing postgres entries, different deployment target.
The bundles are produced by `wrangler deploy --dry-run --metafile`
(wrangler 4.91+ exposes the esbuild metafile flag). The script normalises
wrangler's output (`worker.js`, `bundle-meta.json`) to the dist/ flat-naming
convention `dist/cf-worker-{no-emit,emit}.worker{,.min}.mjs` plus a
sibling `.meta.json` so `scripts/why.ts` can inspect the per-bundle
reachability graph the same way it does for the esbuild bundles.
`.size-limit.json` grows two new entries that the existing
`andresz1/size-limit-action` workflow picks up automatically — no CI
workflow change needed, the PR comment will report the cf-worker sizes
alongside the others.
Notable measurement properties:
- CF Worker bundles are larger than the Node equivalents because `pg`
(and its node-compat polyfills via `unenv`) must be inlined for the
Workers runtime, whereas the Node bundles externalise `pg`.
- Wrangler's `--minify` step clears the per-output `inputs[].bytesInOutput`
field in the metafile (a known esbuild-via-wrangler quirk). The global
`inputs[].bytes` map stays populated in both variants. For
per-output-byte attribution analysis on a cf-worker bundle, read the
unminified metafile (`*.worker.mjs.meta.json`).
Signed-off-by: Serhii Tatarintsev <[email protected]>
📝 WalkthroughWalkthroughThis PR extends the bundle-size example to measure Cloudflare Workers bundles alongside existing Node.js targets. It adds two worker implementations, configures them with Wrangler, integrates the build pipeline to bundle them via ChangesCloudflare Workers bundle-size integration
Version upgrade instructions
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
size-limit report 📦
|
@prisma-next/extension-author-tools
@prisma-next/mongo-runtime
@prisma-next/family-mongo
@prisma-next/sql-runtime
@prisma-next/family-sql
@prisma-next/extension-arktype-json
@prisma-next/middleware-cache
@prisma-next/mongo
@prisma-next/extension-paradedb
@prisma-next/extension-pgvector
@prisma-next/extension-postgis
@prisma-next/postgres
@prisma-next/sql-orm-client
@prisma-next/sqlite
@prisma-next/target-mongo
@prisma-next/adapter-mongo
@prisma-next/driver-mongo
@prisma-next/contract
@prisma-next/utils
@prisma-next/config
@prisma-next/errors
@prisma-next/framework-components
@prisma-next/operations
@prisma-next/ts-render
@prisma-next/contract-authoring
@prisma-next/ids
@prisma-next/psl-parser
@prisma-next/psl-printer
@prisma-next/cli
@prisma-next/cli-telemetry
@prisma-next/emitter
@prisma-next/migration-tools
prisma-next
@prisma-next/vite-plugin-contract-emit
@prisma-next/mongo-codec
@prisma-next/mongo-contract
@prisma-next/mongo-value
@prisma-next/mongo-contract-psl
@prisma-next/mongo-contract-ts
@prisma-next/mongo-emitter
@prisma-next/mongo-schema-ir
@prisma-next/mongo-query-ast
@prisma-next/mongo-orm
@prisma-next/mongo-query-builder
@prisma-next/mongo-lowering
@prisma-next/mongo-wire
@prisma-next/sql-contract
@prisma-next/sql-errors
@prisma-next/sql-operations
@prisma-next/sql-schema-ir
@prisma-next/sql-contract-psl
@prisma-next/sql-contract-ts
@prisma-next/sql-contract-emitter
@prisma-next/sql-lane-query-builder
@prisma-next/sql-relational-core
@prisma-next/sql-builder
@prisma-next/target-postgres
@prisma-next/target-sqlite
@prisma-next/adapter-postgres
@prisma-next/adapter-sqlite
@prisma-next/driver-postgres
@prisma-next/driver-sqlite
commit: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
examples/bundle-size/scripts/bundle.ts (1)
257-258: 💤 Low valueOptional: normalize displayed input paths for consistency.
The esbuild section displays inputs relative to the repo root (Line 133), but here the raw metafile
pathis printed. If wrangler emits temp/absolute-ish paths, the two tables won't line up. Consider applying the samerelative(...)normalization for readability.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@examples/bundle-size/scripts/bundle.ts` around lines 257 - 258, The printed bundle input paths in the loop over `top` use raw `path`, which can be temp/absolute and misalign with the esbuild table; change the console output to normalize paths (e.g., call the same `relative(...)` helper used earlier) before formatting so both tables match — update the `for (const { path, bytes } of top)` console.log to use `relative(path)` (or the same repo root normalization function) when printing.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@examples/bundle-size/scripts/bundle.ts`:
- Around line 257-258: The printed bundle input paths in the loop over `top` use
raw `path`, which can be temp/absolute and misalign with the esbuild table;
change the console output to normalize paths (e.g., call the same
`relative(...)` helper used earlier) before formatting so both tables match —
update the `for (const { path, bytes } of top)` console.log to use
`relative(path)` (or the same repo root normalization function) when printing.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: be784f1d-497a-44e3-92a0-ef941febfaf4
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (9)
examples/bundle-size/.size-limit.jsonexamples/bundle-size/README.mdexamples/bundle-size/package.jsonexamples/bundle-size/scripts/bundle.tsexamples/bundle-size/src/postgres-worker/worker-emit.tsexamples/bundle-size/src/postgres-worker/worker.tsexamples/bundle-size/wrangler.worker-emit.jsoncexamples/bundle-size/wrangler.worker.jsoncskills/upgrade/prisma-next-upgrade/upgrades/0.12-to-0.13/instructions.md
Adds a CF Workers variant to the
bundle-sizefixture alongside the existing Node postgres and mongo entries.What changed
Two new entries —
cf-worker / no-emitandcf-worker / emit— bundle a Workers entry that imports@prisma-next/postgres/serverlessand runs the sameSELECT id FROM "Note" LIMIT 10query as the existing postgres entries. The reused contract surfaces (no-emit:src/postgres/contract.ts; emit:src/postgres/generated/) keep the comparison apples-to-apples — same domain shape, different deployment target.How the bundle is produced
scripts/bundle.tsnow runswrangler deploy --dry-run --metafile [--minify]per cf-worker entry (wrangler 4.91 exposes the esbuild metafile flag). It normalises wrangler's output (worker.js,bundle-meta.json, etc.) to the dist/ flat-naming convention:dist/cf-worker-no-emit.worker.mjs/.worker.min.mjsdist/cf-worker-no-emit.worker.min.mjs.meta.json(and unminified counterpart)dist/cf-worker-emit.worker{,.min}.mjs+ matching.meta.json+.gzThe script prints a sizes table and the top-10 input contributors per minified bundle, mirroring the existing esbuild sections.
CI reporting
.size-limit.jsongrows two new entries that the existingandresz1/size-limit-actionworkflow (.github/workflows/bundle-size.yml) picks up automatically — no workflow change needed. The PR comment will report the cf-worker sizes alongside the others.Metafile inspection
Same
scripts/why.tstracer that works for the esbuild bundles works for the wrangler bundles — the wrangler--metafileoutput uses the same esbuild-metafile schema. The README documents one quirk: wrangler's--minifystep clears the per-outputinputs[].bytesInOutputmap (a known esbuild-via-wrangler behaviour). The globalinputs[].bytesmap stays populated in both variants. For per-output-byte attribution analysis on a cf-worker bundle, read the unminified metafile (*.worker.mjs.meta.json); for total-size measurement, the minified.worker.min.mjs.meta.jsonis fine.Measurements on this branch
Run locally on the same fixture (
Note { id }contract, one query):CF Worker bundles are larger than the Node equivalents because
pg(and its node-compat polyfills viaunenv) must be inlined for the Workers runtime, whereas the Node esbuild config externalisespg. That's a realistic difference: a Workers consumer pays for the inline polyfills.Verification
pnpm bundleproduces all 6 minified artefacts + metafiles +.gz.pnpm size(size-limit, the CI's engine) reports on all 6 entries.pnpm typecheckclean.pnpm lintclean.pnpm lint:depsclean.pnpm testpostgres-path green (mongo path env-blocked on local NixOS host; pre-existing constraint).Notes
examples/prisma-next-cloudflare-worker, which uses@cloudflare/vitest-pool-workers.changes: []0.12-to-0.13 upgrade-instructions stub (perrecord-upgrade-instructionsskill) because it touchesexamples/. No consumer action required — the worker entry additions are internal to the bundle-size fixture.Summary by CodeRabbit
New Features
Documentation
Chores