@workflow/next 5.0.0-beta.9 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  ---
2
2
  title: withWorkflow
3
- description: Configure webpack/turbopack to transform workflow directives in Next.js.
3
+ description: Configure webpack and Turbopack to transform workflow directives in Next.js.
4
4
  type: reference
5
5
  summary: Wrap your Next.js config with withWorkflow to enable workflow directive transformation.
6
6
  prerequisites:
7
7
  - /docs/getting-started/next
8
8
  ---
9
9
 
10
- Configures webpack/turbopack loaders to transform workflow code (`"use step"`/`"use workflow"` directives)
10
+ Configures webpack and Turbopack loaders to transform workflow code (`"use step"` and `"use workflow"` directives).
11
11
 
12
12
  ## Usage
13
13
 
@@ -16,13 +16,13 @@ To enable `"use step"` and `"use workflow"` directives while developing locally
16
16
  ```typescript title="next.config.ts" lineNumbers
17
17
  import { withWorkflow } from "workflow/next"; // [!code highlight]
18
18
  import type { NextConfig } from "next";
19
-
19
+
20
20
  const nextConfig: NextConfig = {
21
21
  // … rest of your Next.js config
22
22
  };
23
23
 
24
24
  // not required but allows configuring workflow options
25
- const workflowConfig = {}
25
+ const workflowConfig = {};
26
26
 
27
27
  export default withWorkflow(nextConfig, workflowConfig); // [!code highlight]
28
28
  ```
@@ -31,12 +31,36 @@ export default withWorkflow(nextConfig, workflowConfig); // [!code highlight]
31
31
  If a package in `serverExternalPackages` contains workflow code (`"use step"`,
32
32
  `"use workflow"`, or serialization classes), `withWorkflow()` automatically
33
33
  removes it from `serverExternalPackages` for the current build and prints a
34
- warning. This ensures the package still gets transformed by the Workflow
35
- compiler. Remove that package from `serverExternalPackages` in your
34
+ warning. Workflow still compiles the package so its directives are transformed.
35
+ Remove that package from `serverExternalPackages` in your
36
36
  `next.config` to silence the warning.
37
37
  </Callout>
38
38
 
39
- ### Monorepos and Workspace Imports
39
+ ### Workflow discovery in Next.js
40
+
41
+ `withWorkflow()` discovers workflows by scanning your Next.js entrypoints (App
42
+ Router `route`, `page`, and `layout` files under `app/` or `src/app/`, and any
43
+ file under `pages/` or `src/pages/`) for `start()` calls imported from
44
+ `workflow/api`. The workflow and step files themselves can live anywhere (for
45
+ example `src/workflows/`); they are discovered transitively through imports, as
46
+ long as a `start()` call in an entrypoint statically reaches them.
47
+
48
+ <Callout type="info">
49
+ Call `start()` from server-side entrypoints, including Route Handlers and Server
50
+ Actions. Don't call workflow functions directly, which bypasses the workflow
51
+ runtime.
52
+ </Callout>
53
+
54
+ ### Next.js server actions and `"use server"`
55
+
56
+ Don't put a top-level `"use server"` directive in modules imported by workflow
57
+ or step functions. Workflow transformation wraps imported modules in synchronous
58
+ initializers, and Next.js rejects a `"use server"` directive inside that wrapper
59
+ with errors like `Server Actions must be async functions`. Keep `"use server"`
60
+ on the files that define your Server Actions, and move shared logic into
61
+ separate modules that don't carry the directive.
62
+
63
+ ### Monorepos and workspace imports
40
64
 
41
65
  By default, Next.js detects the correct workspace root automatically. If your Next.js app lives in a subdirectory such as `apps/web` and workspace resolution is not working correctly, you can set `outputFileTracingRoot` as a workaround:
42
66
 
@@ -68,7 +92,6 @@ const nextConfig: NextConfig = {};
68
92
 
69
93
  export default withWorkflow(nextConfig, {
70
94
  workflows: {
71
- lazyDiscovery: false,
72
95
  local: {
73
96
  port: 4000,
74
97
  },
@@ -79,35 +102,34 @@ export default withWorkflow(nextConfig, {
79
102
 
80
103
  | Option | Type | Default | Description |
81
104
  | --- | --- | --- | --- |
82
- | `workflows.lazyDiscovery` | `boolean` | `true` | Defers workflow discovery until files are requested instead of scanning eagerly at startup. Set to `false` to force eager discovery (scanning the project up front). Requires a Next.js version that supports deferred entries; older versions fall back to eager discovery automatically. |
83
105
  | `workflows.local.port` | `number` | — | Overrides the `PORT` environment variable for local development. Has no effect when deployed to Vercel. |
84
- | `workflows.sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` | Controls source maps on generated workflow bundles. See [Source maps](#source-maps) below. |
106
+ | `workflows.sourcemap` | `boolean \| 'inline' \| 'linked' \| 'external' \| 'both'` | `'inline'` (dev) / `false` (prod) | Controls source maps on generated workflow bundles. See [Source maps](#source-maps) below. |
85
107
 
86
108
  ### Source maps
87
109
 
88
- The step bundle and intermediate workflow bundle default to `'inline'` source maps so that stack traces from step errors and workflow VM errors point at your source files. The `sourcemap` option lets you change that:
110
+ The step bundle and intermediate workflow bundle default to `'inline'` source maps **in development** (so stack traces from step errors and workflow virtual machine (VM) errors point at your source files) and to **`false` in production**, so function bundles stay small. The `sourcemap` option lets you change that:
89
111
 
90
112
  | Value | Behavior |
91
113
  | --- | --- |
92
- | `true` / `'inline'` | Base64-encode the source map and append it to the bundle (default). |
114
+ | `true` / `'inline'` | Base64-encode the source map and append it to the bundle (default in development). |
93
115
  | `'linked'` | Write a separate `.map` file and add a `sourceMappingURL` comment. |
94
116
  | `'external'` | Write a separate `.map` file without the comment. |
95
117
  | `'both'` | Emit both inline and external source maps. |
96
118
  | `false` | Omit source maps entirely. |
97
119
 
98
- Setting `sourcemap: false` is the main escape hatch for users hitting the Vercel 250MB function size limit — it drops the inline source map from every bundle and also skips the source-map-support runtime shim on the Vercel step function. The tradeoff is that workflow VM stack traces will reference generated code (e.g. `evalmachine.<anonymous>`) rather than your source files.
120
+ In production, source maps are already off by default. Setting `sourcemap: false` explicitly also turns them off in development, and it drops the inline source map from every bundle while skipping the source-map-support runtime shim on the Vercel step function (the same behavior production gets by default), the main lever for staying under the Vercel 250 MB function size limit. The tradeoff is that workflow VM stack traces will reference generated code (for example, `evalmachine.<anonymous>`) rather than your source files.
99
121
 
100
122
  <Callout type="info">
101
- Setting `sourcemap` explicitly affects **all** generated bundles (steps, workflows, webhook). The legacy `WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING=1` environment variable is narrower — it only toggles source maps on the final workflow wrapper and webhook bundle (which default to off). It continues to work, but new code should use the `sourcemap` option or the `WORKFLOW_SOURCEMAP` environment variable instead.
123
+ Setting `sourcemap` explicitly affects **all** generated bundles (steps, workflows, webhook). The legacy `WORKFLOW_EMIT_SOURCEMAPS_FOR_DEBUGGING=1` environment variable is narrower: it only toggles source maps on the final workflow wrapper and webhook bundle (which default to off). It continues to work, but new code should use the `sourcemap` option or the `WORKFLOW_SOURCEMAP` environment variable instead.
102
124
  </Callout>
103
125
 
104
- The option can also be set via the `WORKFLOW_SOURCEMAP` environment variable, which accepts the same values plus `'0'` / `'1'` as aliases for `false` / `true`. Precedence is: explicit config > `WORKFLOW_SOURCEMAP` > per-bundle default.
126
+ The option can also be set via the `WORKFLOW_SOURCEMAP` environment variable, which accepts the same values plus `'0'` / `'1'` as aliases for `false` / `true`. Precedence is: explicit config > `WORKFLOW_SOURCEMAP` > the environment-aware default (`'inline'` in development, `false` in production). Development is detected from `next dev` / `NODE_ENV=development`, so the config option and the env var both let you force either behavior in either environment.
105
127
 
106
128
  <Callout type="info">
107
129
  The `workflows.local` options only affect local development. When deployed to Vercel, the runtime ignores `local` settings and uses the Vercel world automatically.
108
130
  </Callout>
109
131
 
110
- ## Exporting a Function
132
+ ## Exporting a function
111
133
 
112
134
 
113
135
  If you are exporting a function in your `next.config` you will need to ensure you call the function returned from `withWorkflow`.
@@ -136,4 +158,4 @@ export default async function config(
136
158
  }
137
159
  return nextConfig;
138
160
  }
139
- ```
161
+ ```
package/docs/next.mdx CHANGED
@@ -7,13 +7,17 @@ prerequisites:
7
7
  - /docs/getting-started
8
8
  related:
9
9
  - /docs/api-reference/workflow-next
10
- - /docs/deploying/world/vercel-world
10
+ - /worlds/vercel
11
11
  ---
12
12
 
13
+ <CopyPrompt
14
+ text="In this Next.js app, run `npm i workflow`. Wrap `next.config.ts` with `withWorkflow` from `workflow/next`. If the app has `proxy.ts` or middleware, exclude `.well-known/workflow/` from its matcher. Add `workflows/user-signup.ts` exporting `handleUserSignup(email)` with `&quot;use workflow&quot;`, `sleep` from `workflow`, and `&quot;use step&quot;` helper functions that create a user, send a welcome email, and send an onboarding email. Add `app/api/signup/route.ts` with a POST handler that reads `{ email }`, calls `start(handleUserSignup, [email])` from `workflow/api`, and returns JSON. Run `npm run dev`, trigger `curl -X POST --json '{&quot;email&quot;:&quot;hello@example.com&quot;}' http://localhost:3000/api/signup`, and inspect with `npx workflow web` or `npx workflow inspect runs`."
15
+ />
16
+
13
17
  <Steps>
14
18
 
15
19
  <Step>
16
- ## Create Your Next.js Project
20
+ ## Create your Next.js project
17
21
 
18
22
  Start by creating a new Next.js project. This command will create a new directory named `my-workflow-app` and set up a Next.js project inside it.
19
23
 
@@ -85,7 +89,7 @@ If your Next.js app has a [proxy handler](https://nextjs.org/docs/app/api-refere
85
89
  (formerly known as "middleware"), you'll need to update the matcher pattern to exclude Workflow's
86
90
  internal paths to prevent the proxy handler from running on them.
87
91
 
88
- If you see `[local world] Queue operation failed` with `Cannot perform ArrayBuffer.prototype.slice on a detached ArrayBuffer`, your proxy matcher is still intercepting Workflow's internal `POST /.well-known/workflow/v1/flow` request. This is especially easy to miss in Next.js 16, where `proxy.ts` replaced `middleware.ts`.
92
+ If you see `[local world] Queue operation failed` with `Cannot perform ArrayBuffer.prototype.slice on a detached ArrayBuffer`, your proxy matcher is still intercepting Workflow's internal `POST /.well-known/workflow/v1/flow` request. This issue can be hard to spot in Next.js 16, where `proxy.ts` replaced `middleware.ts`.
89
93
 
90
94
  Add `.well-known/workflow/*` to your matcher exclusion list:
91
95
 
@@ -117,7 +121,7 @@ This ensures that internal Workflow paths are not intercepted by your middleware
117
121
 
118
122
  <Step>
119
123
 
120
- ## Create Your First Workflow
124
+ ## Create your first workflow
121
125
 
122
126
  Create a new file for our first workflow:
123
127
 
@@ -140,14 +144,14 @@ export async function handleUserSignup(email: string) {
140
144
 
141
145
  ```
142
146
 
143
- We'll fill in those functions next, but let's take a look at this code:
147
+ We'll fill in those functions next. The current code does the following:
144
148
 
145
149
  * We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
146
150
  * The Workflow SDK's `sleep` function allows us to suspend execution of the workflow without using up any resources. A sleep can be a few seconds, hours, days, or even months long.
147
151
 
148
- ## Create Your Workflow Steps
152
+ ## Create your workflow steps
149
153
 
150
- Let's now define those missing functions.
154
+ Define the missing functions.
151
155
 
152
156
  ```typescript title="workflows/user-signup.ts" lineNumbers
153
157
  import { FatalError } from "workflow"
@@ -188,7 +192,7 @@ async function sendOnboardingEmail(user: { id: string; email: string}) {
188
192
 
189
193
  Taking a look at this code:
190
194
 
191
- * Business logic lives inside **steps**. When a step is invoked inside a **workflow**, it gets enqueued to run on a separate request while the workflow is suspended, just like `sleep`.
195
+ * Business logic lives inside **steps**. When a workflow invokes a step, the workflow suspends while the step runs with full Node.js access. The combined handler may execute it inline; queued retries and continuations return through the same flow route.
192
196
  * If a step throws an error, like in `sendWelcomeEmail`, the step will automatically be retried until it succeeds (or hits the step's max retry count).
193
197
  * Steps can throw a `FatalError` if an error is intentional and should not be retried.
194
198
 
@@ -200,7 +204,7 @@ We'll dive deeper into workflows, steps, and other ways to suspend or handle eve
200
204
 
201
205
  <Step>
202
206
 
203
- ## Create Your Route Handler
207
+ ## Create your route handler
204
208
 
205
209
  To invoke your new workflow, we'll need to add your workflow to a `POST` API Route Handler, `app/api/signup/route.ts`, with the following code:
206
210
 
@@ -272,12 +276,12 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b
272
276
 
273
277
  If you see this error when upgrading to Next.js 16.1 or later:
274
278
 
275
- ```
279
+ ```text
276
280
  Build error occurred
277
281
  Error: Cannot find module 'next/dist/lib/server-external-packages.json'
278
282
  ```
279
283
 
280
- Upgrade to `workflow@4.0.1-beta.26` or later:
284
+ Upgrade `workflow` to the latest release:
281
285
 
282
286
  ```package-install
283
287
  workflow@latest
@@ -311,8 +315,8 @@ Without this configuration, you may experience intermittent issues where workflo
311
315
 
312
316
  If you see this error:
313
317
 
314
- ```
315
- 'start' received an invalid workflow function. Ensure the Workflow Development Kit is configured correctly and the function includes a 'use workflow' directive.
318
+ ```text
319
+ 'start' received an invalid workflow function. Ensure the Workflow SDK is configured correctly and the function includes a 'use workflow' directive.
316
320
  ```
317
321
 
318
322
  Check both of these first:
@@ -322,7 +326,7 @@ Check both of these first:
322
326
 
323
327
  See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
324
328
 
325
- ## Next Steps
329
+ ## Next steps
326
330
 
327
331
  * Learn more about the [Foundations](/docs/foundations).
328
332
  * Check [Errors](/docs/errors) if you encounter issues.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workflow/next",
3
- "version": "5.0.0-beta.9",
3
+ "version": "5.0.0",
4
4
  "description": "Next.js integration for Workflow SDK",
5
5
  "type": "commonjs",
6
6
  "main": "dist/index.js",
@@ -27,18 +27,20 @@
27
27
  },
28
28
  "dependencies": {
29
29
  "@swc/core": "1.15.3",
30
- "semver": "7.7.4",
31
- "watchpack": "2.5.1",
32
- "@workflow/builders": "5.0.0-beta.9",
33
- "@workflow/core": "5.0.0-beta.9",
34
- "@workflow/swc-plugin": "5.0.0-beta.4"
30
+ "@workflow/builders": "5.0.0",
31
+ "@workflow/core": "5.0.0",
32
+ "@workflow/swc-plugin": "5.0.0",
33
+ "chokidar": "4.0.3",
34
+ "ignore": "7.0.5",
35
+ "semver": "7.7.4"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/node": "22.19.0",
38
39
  "@types/semver": "7.7.1",
39
- "@types/watchpack": "2.4.4",
40
- "next": "16.2.1",
41
- "@workflow/tsconfig": "5.0.0-beta.0"
40
+ "@workflow/tsconfig": "5.0.0",
41
+ "next": "16.3.6",
42
+ "typescript": "^6.0.3",
43
+ "vitest": "^4.1.10"
42
44
  },
43
45
  "peerDependencies": {
44
46
  "next": ">13"
@@ -51,6 +53,7 @@
51
53
  "scripts": {
52
54
  "build": "tsc",
53
55
  "dev": "tsc --watch",
56
+ "test": "vitest run src",
54
57
  "clean": "tsc --build --clean && rm -rf dist docs"
55
58
  }
56
59
  }
@@ -1,2 +0,0 @@
1
- export declare function getNextBuilderDeferred(): Promise<any>;
2
- //# sourceMappingURL=builder-deferred.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"builder-deferred.d.ts","sourceRoot":"","sources":["../src/builder-deferred.ts"],"names":[],"mappings":"AAuCA,wBAAsB,sBAAsB,iBAu0D3C"}