@workflow/next 5.0.0-beta.5 → 5.0.0-beta.50

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.
Files changed (44) hide show
  1. package/dist/builder-eager.d.ts +2 -1
  2. package/dist/builder-eager.d.ts.map +1 -1
  3. package/dist/builder-eager.js +421 -169
  4. package/dist/builder.d.ts +1 -4
  5. package/dist/builder.d.ts.map +1 -1
  6. package/dist/builder.js +2 -28
  7. package/dist/index.d.ts +0 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +171 -69
  10. package/dist/loader.d.ts +5 -0
  11. package/dist/loader.d.ts.map +1 -1
  12. package/dist/loader.js +15 -341
  13. package/dist/runtime.d.ts +1 -1
  14. package/dist/runtime.d.ts.map +1 -1
  15. package/dist/runtime.js +2 -2
  16. package/dist/swc-plugin-cache.d.ts +7 -0
  17. package/dist/swc-plugin-cache.d.ts.map +1 -0
  18. package/dist/swc-plugin-cache.js +23 -0
  19. package/dist/watch-ignore.d.ts +51 -0
  20. package/dist/watch-ignore.d.ts.map +1 -0
  21. package/dist/watch-ignore.js +264 -0
  22. package/dist/watch-rebuild.d.ts +110 -0
  23. package/dist/watch-rebuild.d.ts.map +1 -0
  24. package/dist/watch-rebuild.js +476 -0
  25. package/docs/api-reference/with-workflow.mdx +39 -17
  26. package/docs/next.mdx +22 -16
  27. package/package.json +12 -9
  28. package/dist/builder-deferred.d.ts +0 -2
  29. package/dist/builder-deferred.d.ts.map +0 -1
  30. package/dist/builder-deferred.js +0 -1326
  31. package/dist/builder-deferred.js.map +0 -1
  32. package/dist/builder-eager.js.map +0 -1
  33. package/dist/builder.js.map +0 -1
  34. package/dist/environment-flag.d.ts +0 -2
  35. package/dist/environment-flag.d.ts.map +0 -1
  36. package/dist/environment-flag.js +0 -15
  37. package/dist/environment-flag.js.map +0 -1
  38. package/dist/index.js.map +0 -1
  39. package/dist/loader.js.map +0 -1
  40. package/dist/runtime.js.map +0 -1
  41. package/dist/socket-server.d.ts +0 -48
  42. package/dist/socket-server.d.ts.map +0 -1
  43. package/dist/socket-server.js +0 -154
  44. package/dist/socket-server.js.map +0 -1
@@ -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: true,
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` | `false` | When `true`, defers workflow discovery until files are requested instead of scanning eagerly at startup. Useful for large projects where startup time matters. |
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
 
@@ -75,9 +79,9 @@ To enable helpful hints in your IDE, setup the workflow plugin in `tsconfig.json
75
79
  </Accordion>
76
80
 
77
81
  <Accordion type="single" collapsible>
78
- <AccordionItem value="typescript-intellisense" className="[&_h3]:my-0">
82
+ <AccordionItem value="configure-proxy-handler" className="[&_h3]:my-0">
79
83
  <AccordionTrigger className="text-sm">
80
- ### Configure Proxy Handler (if applicable)
84
+ <h3 id="configure-proxy-handler">Configure Proxy Handler (if applicable)</h3>
81
85
  </AccordionTrigger>
82
86
  <AccordionContent className="[&_p]:my-2">
83
87
 
@@ -85,7 +89,9 @@ 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
- Add `.well-known/workflow/*` to your middleware's exclusion list:
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`.
93
+
94
+ Add `.well-known/workflow/*` to your matcher exclusion list:
89
95
 
90
96
  ```typescript title="proxy.ts" lineNumbers
91
97
  import { NextResponse } from "next/server";
@@ -115,7 +121,7 @@ This ensures that internal Workflow paths are not intercepted by your middleware
115
121
 
116
122
  <Step>
117
123
 
118
- ## Create Your First Workflow
124
+ ## Create your first workflow
119
125
 
120
126
  Create a new file for our first workflow:
121
127
 
@@ -138,14 +144,14 @@ export async function handleUserSignup(email: string) {
138
144
 
139
145
  ```
140
146
 
141
- 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:
142
148
 
143
149
  * We define a **workflow** function with the directive `"use workflow"`. Think of the workflow function as the _orchestrator_ of individual **steps**.
144
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.
145
151
 
146
- ## Create Your Workflow Steps
152
+ ## Create your workflow steps
147
153
 
148
- Let's now define those missing functions.
154
+ Define the missing functions.
149
155
 
150
156
  ```typescript title="workflows/user-signup.ts" lineNumbers
151
157
  import { FatalError } from "workflow"
@@ -186,7 +192,7 @@ async function sendOnboardingEmail(user: { id: string; email: string}) {
186
192
 
187
193
  Taking a look at this code:
188
194
 
189
- * 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.
190
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).
191
197
  * Steps can throw a `FatalError` if an error is intentional and should not be retried.
192
198
 
@@ -198,7 +204,7 @@ We'll dive deeper into workflows, steps, and other ways to suspend or handle eve
198
204
 
199
205
  <Step>
200
206
 
201
- ## Create Your Route Handler
207
+ ## Create your route handler
202
208
 
203
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:
204
210
 
@@ -270,12 +276,12 @@ Check the [Deploying](/docs/deploying) section to learn how your workflows can b
270
276
 
271
277
  If you see this error when upgrading to Next.js 16.1 or later:
272
278
 
273
- ```
279
+ ```text
274
280
  Build error occurred
275
281
  Error: Cannot find module 'next/dist/lib/server-external-packages.json'
276
282
  ```
277
283
 
278
- Upgrade to `workflow@4.0.1-beta.26` or later:
284
+ Upgrade `workflow` to the latest release:
279
285
 
280
286
  ```package-install
281
287
  workflow@latest
@@ -309,8 +315,8 @@ Without this configuration, you may experience intermittent issues where workflo
309
315
 
310
316
  If you see this error:
311
317
 
312
- ```
313
- '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.
314
320
  ```
315
321
 
316
322
  Check both of these first:
@@ -320,7 +326,7 @@ Check both of these first:
320
326
 
321
327
  See [start-invalid-workflow-function](/docs/errors/start-invalid-workflow-function) for full examples and fixes.
322
328
 
323
- ## Next Steps
329
+ ## Next steps
324
330
 
325
331
  * Learn more about the [Foundations](/docs/foundations).
326
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.5",
3
+ "version": "5.0.0-beta.50",
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.5",
33
- "@workflow/core": "5.0.0-beta.5",
34
- "@workflow/swc-plugin": "5.0.0-beta.4"
30
+ "@workflow/builders": "5.0.0-beta.50",
31
+ "@workflow/core": "5.0.0-beta.50",
32
+ "@workflow/swc-plugin": "5.0.0-beta.6",
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-beta.0",
41
+ "next": "16.2.11",
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":"AAqCA,wBAAsB,sBAAsB,iBAwwD3C"}