Skip to content

Commit 2c1714e

Browse files
committed
docs: migrate to latest nitro v3
Signed-off-by: Pooya Parsa <pooya@pi0.io>
1 parent 6373ab5 commit 2c1714e

File tree

7 files changed

+724
-81
lines changed

7 files changed

+724
-81
lines changed

docs/content/docs/getting-started/nitro.mdx

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Nitro
44

55
# Nitro
66

7-
This guide will walk through setting up your first workflow in a Nitro app. Along the way, you'll learn more about the concepts that are fundamental to using the development kit in your own projects.
7+
This guide will walk through setting up your first workflow in a [Nitro v3](https://v3.nitro.build/) project. Along the way, you'll learn more about the concepts that are fundamental to using the development kit in your own projects.
88

99
---
1010

@@ -16,7 +16,7 @@ This guide will walk through setting up your first workflow in a Nitro app. Alon
1616
Start by creating a new Nitro project. This command will create a new directory named `nitro-app` and setup a Nitro project inside it.
1717

1818
```bash
19-
npx giget@latest nitro nitro-app --install
19+
npx create-nitro-app
2020
```
2121

2222
Enter the newly made directory:
@@ -44,16 +44,16 @@ cd nitro-app
4444

4545
### Configure Nitro
4646

47-
Add `workflow/nitro` to your `nitro.config.ts` This enables usage of the `"use workflow"` and `"use step"` directives.
47+
Add `workflow/nitro` module to your `nitro.config.ts` This enables usage of the `"use workflow"` and `"use step"` directives.
4848

4949
```typescript title="nitro.config.ts" lineNumbers
50-
import { defineNitroConfig } from "nitropack/config";
50+
import { defineConfig } from "nitro";
5151

52-
export default defineNitroConfig({
53-
compatibilityDate: "latest",
54-
srcDir: "server",
52+
export default defineConfig({
53+
serverDir: "./server",
5554
modules: ["workflow/nitro"],
5655
});
56+
5757
```
5858

5959
<Accordion type="single" collapsible>
@@ -173,18 +173,16 @@ To invoke your new workflow, we'll create a new API route handler at `server/api
173173

174174
```typescript title="server/api/signup.post.ts"
175175
import { start } from 'workflow/api';
176-
import { defineEventHandler, readBody } from 'h3';
176+
import { defineEventHandler } from 'nitro/h3';
177177
import { handleUserSignup } from "../../workflows/user-signup";
178178

179-
export default defineEventHandler(async (event) => {
180-
const { email } = await readBody(event);
181-
179+
export default defineEventHandler(async ({ req }) => {
180+
const { email } = await req.json() as { email: string };
182181
// Executes asynchronously and doesn't block your app
183182
await start(handleUserSignup, [email]);
184-
185-
return Response.json({
183+
return {
186184
message: "User signup workflow started",
187-
});
185+
}
188186
});
189187
```
190188

packages/nitro/src/vite.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
import type {} from 'nitro/vite'
12
import type { Nitro } from 'nitro/types';
23
import type { Plugin } from 'vite';
34
import type { ModuleOptions } from './index.js';
45
import nitroModule from './index.js';
56
import { workflowRollupPlugin } from './rollup.js';
67

8+
79
export function workflow(options?: ModuleOptions): Plugin[] {
810
return [
911
workflowRollupPlugin(),
1012
{
1113
name: 'workflow:nitro',
12-
// Requires https://github.com/nitrojs/nitro/discussions/3680
13-
// @ts-expect-error
1414
nitro: {
1515
setup: (nitro: Nitro) => {
1616
nitro.options.workflow = {

pnpm-lock.yaml

Lines changed: 697 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ catalog:
1010
'@vercel/functions': ^3.1.4
1111
'@vercel/oidc': ^3.0.3
1212
'@vitest/coverage-v8': ^3.2.4
13-
"nitro": "npm:nitro-nightly@3.0.1-20251031-202656-883af4f9"
13+
"nitro": "^3.0.1-alpha.1"
1414
ai: 5.0.76
1515
esbuild: ^0.25.11
1616
typescript: ^5.9.3

workbench/nitro-v3/nitro.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { defineNitroConfig } from 'nitro/config';
22

33
export default defineNitroConfig({
4-
modules: ['workflow/nitro'],
4+
serverDir: './',
5+
modules: [
6+
'workflow/nitro'
7+
],
8+
// Workaround for monorepo symlinked packages
9+
externals: {
10+
external: [id => id.includes('.nitro/workflow')]
11+
},
512
});

workbench/nitro-v3/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"lodash.chunk": "^4.2.0",
1515
"nitro": "catalog:",
1616
"openai": "^6.1.0",
17+
"rollup": "^4.53.2",
1718
"workflow": "workspace:*",
1819
"zod": "catalog:"
1920
},

workbench/vite/vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ import { workflow } from 'workflow/vite';
44

55
export default defineConfig({
66
plugins: [nitro(), workflow()],
7+
nitro: {
8+
serverDir: "./",
9+
}
710
});

0 commit comments

Comments
 (0)