Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/nitro-monorepo-project-root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@workflow/nitro": patch
"@workflow/nuxt": patch
---

Use Nitro's workspace root for workflow module resolution so Nitro and Nuxt monorepo apps can import sibling workspace packages without extra config.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ When enabled, the module:
- Registers the workflow runtime routes under `/.well-known/workflow/v1/`.
- Serves a redirect to the local observability dashboard at `/_workflow` in development.
- Configures Vercel function rules (queue triggers and `maxDuration`) for the workflow routes when deploying to Vercel.
- Uses Nitro's `workspaceDir` as the workflow project root so monorepo apps can import sibling workspace packages without extra workflow config.

## Module Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ When enabled, the module:
- Registers the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module on Nuxt's Nitro server, which transforms `"use workflow"` and `"use step"` directives, builds the workflow bundles, and registers the workflow runtime routes under `/.well-known/workflow/v1/`.
- Configures Vite to bundle (rather than externalize) the Workflow SDK packages in SSR mode so workflow code is transformed correctly.
- Enables the `workflow` TypeScript plugin by default for IDE IntelliSense.
- Uses Nuxt/Nitro's detected `workspaceDir` so monorepo apps can import sibling workspace packages without extra workflow config.

## Module Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ When enabled, the module:
- Registers the workflow runtime routes under `/.well-known/workflow/v1/`.
- Serves a redirect to the local observability dashboard at `/_workflow` in development.
- Configures Vercel function rules (queue triggers and `maxDuration`) for the workflow routes when deploying to Vercel.
- Uses Nitro's `workspaceDir` as the workflow project root so monorepo apps can import sibling workspace packages without extra workflow config.

## Module Options

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ When enabled, the module:
- Registers the [`workflow/nitro`](/docs/api-reference/workflow-nitro) module on Nuxt's Nitro server, which transforms `"use workflow"` and `"use step"` directives, builds the workflow bundles, and registers the workflow runtime routes under `/.well-known/workflow/v1/`.
- Configures Vite to bundle (rather than externalize) the Workflow SDK packages in SSR mode so workflow code is transformed correctly.
- Enables the `workflow` TypeScript plugin by default for IDE IntelliSense.
- Uses Nuxt/Nitro's detected `workspaceDir` so monorepo apps can import sibling workspace packages without extra workflow config.

## Module Options

Expand Down
2 changes: 2 additions & 0 deletions packages/nitro/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# workflow/nitro

The docs have moved! Refer to them [here](https://useworkflow.dev/)

The Nitro module uses Nitro's `workspaceDir` as the workflow project root, so monorepo apps can import sibling workspace packages without extra workflow config.
6 changes: 6 additions & 0 deletions packages/nitro/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ import { join } from 'pathe';
const FLOW_ROUTE = '^\\/\\.well-known\\/workflow\\/v1\\/flow$';
const STEP_ROUTE = '^\\/\\.well-known\\/workflow\\/v1\\/step$';

function getNitroProjectRoot(nitro: Nitro): string {
return nitro.options.workspaceDir ?? nitro.options.rootDir;
}

export class VercelBuilder extends VercelBuildOutputAPIBuilder {
constructor(nitro: Nitro) {
super({
...createBaseBuilderConfig({
workingDir: nitro.options.rootDir,
projectRoot: getNitroProjectRoot(nitro),
dirs: ['.'], // Different apps that use nitro have different directories
runtime: nitro.options.workflow?.runtime,
}),
Expand Down Expand Up @@ -45,6 +50,7 @@ export class LocalBuilder extends BaseBuilder {
super({
...createBaseBuilderConfig({
workingDir: nitro.options.rootDir,
projectRoot: getNitroProjectRoot(nitro),
watch: nitro.options.dev,
dirs: ['.'], // Different apps that use nitro have different directories
}),
Expand Down
35 changes: 32 additions & 3 deletions packages/nitro/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@ import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Nitro } from 'nitro/types';
import { describe, expect, it, onTestFinished } from 'vitest';
import { VercelBuilder } from './builders.js';
import { LocalBuilder, VercelBuilder } from './builders.js';
import nitroModule from './index.js';

function createNitroStub({ routing }: { routing: boolean }): Nitro {
type StubOptions = {
routing: boolean;
workspaceDir?: string;
workflow?: { runtime?: string };
};

function createNitroStub({
routing,
workspaceDir = '/tmp/project',
workflow = {},
}: StubOptions) {
return {
routing,
options: {
Expand All @@ -26,7 +36,8 @@ function createNitroStub({ routing }: { routing: boolean }): Nitro {
rootDir: '/tmp/project',
typescript: {},
virtual: {},
workflow: {},
workspaceDir,
workflow,
},
hooks: {
hook() {},
Expand Down Expand Up @@ -139,3 +150,21 @@ async function exampleStep() {
]);
});
});

describe('@workflow/nitro projectRoot', () => {
for (const [label, Builder] of [
['VercelBuilder', VercelBuilder],
['LocalBuilder', LocalBuilder],
] as const) {
describe(label, () => {
it('uses nitro workspaceDir as the workflow projectRoot', () => {
const nitro = createNitroStub({
routing: true,
workspaceDir: '/tmp',
});
const builder = new Builder(nitro) as any;
expect(builder.config.projectRoot).toBe('/tmp');
});
});
}
});
1 change: 1 addition & 0 deletions packages/nuxt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

Nuxt module for [Workflow SDK](https://useworkflow.dev).

Monorepo workspace package imports work without extra workflow config because `workflow/nuxt` runs through Nitro's detected `workspaceDir`.
Loading