feat(builders,nitro): configurable sourcemap mode#1843
feat(builders,nitro): configurable sourcemap mode#1843TooTallNate wants to merge 1 commit intomainfrom
Conversation
Add a `sourcemap` builder option (plumbed through @workflow/nitro's module options) and a matching `WORKFLOW_SOURCEMAP` environment variable. Accepts the same values as esbuild: true, false, 'inline', 'linked', 'external', 'both'. Setting this to `false` drops the inline sourcemap from the generated step/workflow/webhook bundles and sets `shouldAddSourcemapSupport: false` on the Vercel step.func config. In the nitro-v3 workbench this reduces the step bundle from ~13MB to ~3.1MB, which unblocks users hitting Vercel's 250MB function size limit.
🦋 Changeset detectedLatest commit: d81c01a The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📊 Benchmark Results
workflow with no steps💻 Local Development
workflow with 1 step💻 Local Development
workflow with 10 sequential steps💻 Local Development
workflow with 25 sequential steps💻 Local Development
workflow with 50 sequential steps💻 Local Development
Promise.all with 10 concurrent steps💻 Local Development
Promise.all with 25 concurrent steps💻 Local Development
Promise.all with 50 concurrent steps💻 Local Development
Promise.race with 10 concurrent steps💻 Local Development
Promise.race with 25 concurrent steps💻 Local Development
Promise.race with 50 concurrent steps💻 Local Development
workflow with 10 sequential data payload steps (10KB)💻 Local Development
workflow with 25 sequential data payload steps (10KB)💻 Local Development
workflow with 50 sequential data payload steps (10KB)💻 Local Development
workflow with 10 concurrent data payload steps (10KB)💻 Local Development
workflow with 25 concurrent data payload steps (10KB)💻 Local Development
workflow with 50 concurrent data payload steps (10KB)💻 Local Development
Stream Benchmarks (includes TTFB metrics)workflow with stream💻 Local Development
stream pipeline with 5 transform steps (1MB)💻 Local Development
10 parallel streams (1MB each)💻 Local Development
fan-out fan-in 10 streams (1MB each)💻 Local Development
SummaryFastest Framework by WorldWinner determined by most benchmark wins
Fastest World by FrameworkWinner determined by most benchmark wins
Column Definitions
Worlds:
❌ Some benchmark jobs failed:
Check the workflow run for details. |
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests💻 Local Development (2 failed)vite-stable (2 failed):
Details by Category❌ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
✅ 📋 Other
❌ Some E2E test jobs failed:
Check the workflow run for details. |
There was a problem hiding this comment.
Pull request overview
Adds a configurable sourcemap mode to Workflow builders (and the Nitro integration) to reduce bundle size—especially for Vercel deployments—while keeping current defaults unless overridden.
Changes:
- Introduces a
sourcemapbuilder option +WORKFLOW_SOURCEMAPenv var parsing/precedence logic. - Plumbs
sourcemapthrough@workflow/nitroModuleOptionsand Nitro builders. - Disables Vercel runtime sourcemap support when sourcemaps are disabled; adds unit tests for resolution behavior.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/nitro/src/types.ts | Adds workflow.sourcemap option to Nitro module types/docs. |
| packages/nitro/src/builders.ts | Passes Nitro workflow.sourcemap into createBaseBuilderConfig(). |
| packages/builders/src/vercel-build-output-api.ts | Ties Vercel shouldAddSourcemapSupport to resolved sourcemap enablement. |
| packages/builders/src/types.ts | Adds SourcemapMode type and documents new config option. |
| packages/builders/src/resolve-sourcemap.test.ts | Adds unit tests for config/env precedence and env parsing. |
| packages/builders/src/config-helpers.ts | Plumbs sourcemap through shared builder config creation helper. |
| packages/builders/src/base-builder.ts | Implements env parsing + resolution helper and applies it to esbuild invocations. |
| .changeset/configurable-sourcemap.md | Declares minor bumps for @workflow/builders and @workflow/nitro. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| * `both`). If neither is set, sourcemaps default to `'inline'` so stack | ||
| * traces from step and workflow VM execution include original file names | ||
| * and line numbers. |
There was a problem hiding this comment.
The docstring implies a single global default ("sourcemaps default to 'inline'") for all bundles including the webhook, but BaseBuilder uses different per-invocation defaults (e.g. webhook/final wrapper default off unless WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING or an explicit sourcemap override is set). Please clarify the wording so users don’t assume webhook bundles default to inline sourcemaps.
| * `both`). If neither is set, sourcemaps default to `'inline'` so stack | |
| * traces from step and workflow VM execution include original file names | |
| * and line numbers. | |
| * `both`). If neither is set, the effective default depends on the bundle | |
| * being generated. Step and workflow VM bundles typically default to | |
| * `'inline'` so stack traces include original file names and line numbers, | |
| * while webhook/final-wrapper bundles may default to `false` unless | |
| * debugging or an explicit sourcemap override enables them. |
| * If unset, the value of the `WORKFLOW_SOURCEMAP` environment variable is | ||
| * consulted. If neither is set, the builder's default (`'inline'`) is used. | ||
| * | ||
| * Setting this to `false` can dramatically reduce the generated function | ||
| * bundle size when deploying to Vercel (useful for staying under the 250MB | ||
| * function size limit). |
There was a problem hiding this comment.
This comment says that if neither config nor WORKFLOW_SOURCEMAP is set, the builder default ('inline') is used. In builders, sourcemap defaults are per-bundle (steps/workflows default to inline, but the webhook wrapper defaults off unless WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING or an override is provided). Please adjust the wording to reflect the per-bundle defaults to avoid confusion for Nitro users.
| protected resolveSourcemap(defaultMode: SourcemapMode): SourcemapMode { | ||
| if (this.config.sourcemap !== undefined) { | ||
| return this.config.sourcemap; | ||
| } | ||
| const fromEnv = parseSourcemapEnv(process.env.WORKFLOW_SOURCEMAP); |
There was a problem hiding this comment.
resolveSourcemap() re-parses WORKFLOW_SOURCEMAP on every call. When the env value is unrecognized, parseSourcemapEnv() emits a warning, which can result in repeated identical warnings during a single build (steps + workflows + webhook + vc-config). Consider memoizing the parsed env value (and/or warning once) to keep logs from getting noisy.
|
Closing as duplicate of #1842, which is more comprehensive (covers Next.js, SvelteKit, Astro, and Nest on top of Nitro, and includes docs updates for every framework). I'll leave a review on #1842 with a few suggestions that came out of this branch:
Happy to port any of those over as follow-ups if useful. |
Summary
sourcemapbuilder option (and matchingWORKFLOW_SOURCEMAPenvironment variable) that accepts esbuild's sourcemap values:true | false | 'inline' | 'linked' | 'external' | 'both'.@workflow/nitro'sModuleOptionsso it can be set vianitro.config.ts.shouldAddSourcemapSupport: false(saves runtime overhead).Motivation
The SDK currently builds the step bundle with
sourcemap: 'inline'unconditionally, which inlines a base64-encoded sourcemap into the bundle and significantly increases the generated function size. For projects deploying to Vercel, that can push functions past the platform's 250MB function size limit. Giving users an option to disable (or choose a non-inline mode for) the sourcemap is an easy lever to bring bundle size down.Verification
Measured in
workbench/nitro-v3(Vercel preset):shouldAddSourcemapSupportWORKFLOW_SOURCEMAP=falseworkflow.sourcemap = falsein nitro config~75% bundle reduction with sourcemaps off.
Tests
10 new unit tests in
packages/builders/src/resolve-sourcemap.test.tscovering config precedence, env var parsing (true/false/0/1/inline/linked/external/both), empty/unrecognized env values, and thesourcemapsEnabledgetter. All 139 builder tests pass.