Add support for top-level using declarations inside of step / workflow functions#866
Conversation
🦋 Changeset detectedLatest commit: 9be6d75 The changes in this PR will be included in the next version bump. This PR includes changesets to release 15 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
▲ Production (Vercel)
🔍 Observability: Nitro | Next.js (Turbopack) | Express workflow with 1 step💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Express | Next.js (Turbopack) workflow with 10 sequential steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Express | Next.js (Turbopack) Promise.all with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Express | Next.js (Turbopack) Promise.all with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Nitro | Next.js (Turbopack) | Express Promise.race with 10 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Next.js (Turbopack) | Nitro | Express Promise.race with 25 concurrent steps💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Next.js (Turbopack) | Nitro Stream Benchmarks (includes TTFB metrics)workflow with stream💻 Local Development
▲ Production (Vercel)
🔍 Observability: Express | Next.js (Turbopack) | Nitro SummaryFastest Framework by WorldWinner determined by most benchmark wins
Fastest World by FrameworkWinner determined by most benchmark wins
Column Definitions
Worlds:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🧪 E2E Test Results❌ Some tests failed Summary
❌ Failed Tests🌍 Community Worlds (161 failed)mongodb (40 failed):
redis (40 failed):
starter (41 failed):
turso (40 failed):
Details by Category✅ ▲ Vercel Production
✅ 💻 Local Development
✅ 📦 Local Production
✅ 🐘 Local Postgres
✅ 🪟 Windows
❌ 🌍 Community Worlds
✅ 📋 Other
|
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull request overview
Adds support for recognizing step/workflow directives when TypeScript/SWC transforms top-level using declarations by wrapping the function body in a try/catch/finally, which previously hid the directive from the plugin’s directive scanner.
Changes:
- Detect
"use step"/"use workflow"directives inside thetryblock of theusing-transform pattern. - Remove directives from inside that
tryblock during transformation. - Add a fixture covering
usingin a step function and document the behavior in the plugin spec.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/swc-plugin-workflow/transform/src/lib.rs | Adds heuristic detection/removal logic for directives inside using-transformed try blocks. |
| packages/swc-plugin-workflow/transform/tests/fixture/using-declaration-step/input.js | New fixture input representing using-transformed step function output. |
| packages/swc-plugin-workflow/transform/tests/fixture/using-declaration-step/output-step.js | Expected step-mode transformation output for the new fixture. |
| packages/swc-plugin-workflow/transform/tests/fixture/using-declaration-step/output-client.js | Expected client-mode output for the new fixture. |
| packages/swc-plugin-workflow/transform/tests/fixture/using-declaration-step/output-workflow.js | Expected workflow-mode output for the new fixture. |
| packages/swc-plugin-workflow/spec.md | Documents support for directives inside using-transformed functions. |
| .changeset/green-foxes-lose.md | Publishes a patch release note for the plugin change. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| ``` | ||
|
|
||
| The plugin detects this pattern and correctly identifies the directive inside the try block, removing it during transformation while preserving the disposable resource handling. |
There was a problem hiding this comment.
this behaviour seems flaky no? esp. if you have multiple transforms that are being applied one after the other?
or are you saying that this is not a problem since we control the swc transformation and version, so it's deterministic and won't break because of other transforms?
There was a problem hiding this comment.
ah yeah I re-read your PR description. makes sense 👍
maybe good to include that as a comment in the code/spec.md file itself so the context isn't lost
There was a problem hiding this comment.
Ya from what I understand the using transformation is done by SWC itself before any plugins are invoked, so that's what we have to check for. The directive check happens before any other transformations so I think we don't need to worry about other transformations, and since we control the version of SWC in the Builders, this seems "fine" to me.
…s-and-commands * origin/main: fix(@workflow/ai): support provider-executed tools (AI SDK v6) (#734) Publish "workflow" and "@workflow/core" package versions in sync (#870) Add SDK version to workflow run executionContext for observability (#868) Allow recreateRun to accept an optional deploymentId parameter (#869) Add support for top-level `using` declarations inside of step / workflow functions (#866) docs: URL in docs was missing the docs/ prefix, 404 errors (#852) Add "classes" object to `manifest.json` file (#864) Fix Nest workbench app build (#865) Ignore Astro on local dev tests for source map e2e tests (#863) Enable custom class serialization transformations for "client" mode (#860) Submit request bodies with CBOR encoding (#844) [world-vercel] Update queue to use VQS v3 API (#799) NestJS framework support (#840) Fix resolve hook theming and token fetching. (#856) docs: rename Control Flow Patterns to Common Patterns and add new content (#846) docs: revamp World documentation pages (#763) Remove unused `getWritable` stub function (#855) # Conflicts: # packages/core/package.json # pnpm-lock.yaml

Added support for top-level
usingdeclarations inside step and workflow functions. Note that the detection code in our SWC plugin is looking for the specific transformation that SWC itself produces when using theusingdeclaration, which is fragile. However because we control the version of SWC being used that makes it not so bad (i.e. our e2e tests would fail if/when we update SWC and if the transformation format changed in an incompatible way).Fixes #837.
What changed?
This PR adds support for TypeScript's
usingdeclarations (disposable resources) within step and workflow functions. When TypeScript transformsusingdeclarations, it wraps the function body in a try-catch-finally block, which previously prevented the plugin from correctly identifying the directive. The implementation:usingtransformation patternusingdeclaration in step functionsHow to test?
Create a step or workflow function that uses TypeScript's
usingdeclarations:Verify that the function is correctly identified and transformed as a step function.
Why make this change?
TypeScript's
usingdeclarations are a useful feature for managing disposable resources. This change ensures that developers can use this feature within step and workflow functions without breaking the plugin's ability to identify and transform these functions correctly.