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
7 changes: 5 additions & 2 deletions packages/nitro/src/builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ ${webhookRouteContent}`;
}

export function getWorkflowDirs(nitro: Nitro) {
const srcDir = nitro.options.srcDir || nitro.options.rootDir;

return unique(
[
...(nitro.options.workflow?.dirs ?? []),
join(nitro.options.rootDir, 'workflows'),
...nitro.options.scanDirs.map((dir) => join(dir, 'workflows')),
join(srcDir, 'workflows'),
join(srcDir, nitro.options.routesDir || 'routes'),
join(srcDir, nitro.options.apiDir || 'api'),
].map((dir) => resolve(nitro.options.rootDir, dir))
).sort();
}
Expand Down
5 changes: 3 additions & 2 deletions packages/nitro/test/dirs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const nitroMock = (dirs: string[]) => {
describe('nitro:getWorkflowDirs', () => {
test('default dirs', () => {
const result = getWorkflowDirs(nitroMock([]));
expect(result).toEqual(['/root/server/workflows', '/root/workflows']);
expect(result).toEqual(['/root/api', '/root/routes', '/root/workflows']);
});

test('custom dirs', () => {
Expand All @@ -24,8 +24,9 @@ describe('nitro:getWorkflowDirs', () => {
);
expect(result).toEqual([
'/custom/dir2',
'/root/api',
'/root/relative/dir1',
'/root/server/workflows',
'/root/routes',
'/root/workflows',
]);
});
Expand Down
30 changes: 7 additions & 23 deletions packages/sveltekit/src/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@ async function convertSvelteKitRequest(request) {
export class SvelteKitBuilder extends BaseBuilder {
constructor(config?: Partial<SvelteKitConfig>) {
const workingDir = config?.workingDir || process.cwd();
const dirs = getWorkflowDirs({ dirs: config?.dirs });

// Merge user-provided dirs with framework defaults
// User dirs are included if provided, then framework defaults are added
const defaultDirs = ['workflows', 'src/workflows', 'routes', 'src/routes'];
const userDirs = config?.dirs ?? [];
const allDirs = Array.from(new Set([...userDirs, ...defaultDirs]));

super({
...config,
dirs,
dirs: allDirs,
buildTarget: 'sveltekit' as const,
stepsBundlePath: '', // unused in base
workflowsBundlePath: '', // unused in base
Expand Down Expand Up @@ -232,24 +237,3 @@ export const OPTIONS = createSvelteKitHandler('OPTIONS');`
}
}
}

/**
* Gets the list of directories to scan for workflow files.
*/
export function getWorkflowDirs(options?: { dirs?: string[] }): string[] {
return unique([
// User-provided directories take precedence
...(options?.dirs ?? []),
// Scan routes directories (like Next.js does with app/pages directories)
// This allows workflows to be placed anywhere in the routes tree
'routes',
'src/routes',
// Also scan dedicated workflow directories for organization
'workflows',
'src/workflows',
]).sort();
}

function unique<T>(array: T[]): T[] {
return Array.from(new Set(array));
}
Loading