Skip to content

Commit 09a60f6

Browse files
fix: cleanup builder directories (#319)
* fix: add sveltekit server routes to builder * fix: remove root workflow dir check * fix missing root level workflow route * Fix: The constructor now hardcodes `dirs: ['src/routes', 'src/lib']` which silently ignores any user\-provided `dirs` option passed to the plugin\, breaking the documented API and removing support for custom workflow directories\. * Fix: The test expectations don\'t match the new implementation of `getWorkflowDirs()`\. The mock provides `scanDirs` which the new code no longer uses\, and the new implementation adds scanning of `routesDir` and `apiDir` instead\. * fix(nitro): use src dir --------- Co-authored-by: Vercel <vercel[bot]@users.noreply.github.com> Co-authored-by: vercel[bot] <35613825+vercel[bot]@users.noreply.github.com>
1 parent b68a5c6 commit 09a60f6

File tree

3 files changed

+15
-27
lines changed

3 files changed

+15
-27
lines changed

packages/nitro/src/builders.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,14 @@ ${webhookRouteContent}`;
8282
}
8383

8484
export function getWorkflowDirs(nitro: Nitro) {
85+
const srcDir = nitro.options.srcDir || nitro.options.rootDir;
86+
8587
return unique(
8688
[
8789
...(nitro.options.workflow?.dirs ?? []),
88-
join(nitro.options.rootDir, 'workflows'),
89-
...nitro.options.scanDirs.map((dir) => join(dir, 'workflows')),
90+
join(srcDir, 'workflows'),
91+
join(srcDir, nitro.options.routesDir || 'routes'),
92+
join(srcDir, nitro.options.apiDir || 'api'),
9093
].map((dir) => resolve(nitro.options.rootDir, dir))
9194
).sort();
9295
}

packages/nitro/test/dirs.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const nitroMock = (dirs: string[]) => {
1515
describe('nitro:getWorkflowDirs', () => {
1616
test('default dirs', () => {
1717
const result = getWorkflowDirs(nitroMock([]));
18-
expect(result).toEqual(['/root/server/workflows', '/root/workflows']);
18+
expect(result).toEqual(['/root/api', '/root/routes', '/root/workflows']);
1919
});
2020

2121
test('custom dirs', () => {
@@ -24,8 +24,9 @@ describe('nitro:getWorkflowDirs', () => {
2424
);
2525
expect(result).toEqual([
2626
'/custom/dir2',
27+
'/root/api',
2728
'/root/relative/dir1',
28-
'/root/server/workflows',
29+
'/root/routes',
2930
'/root/workflows',
3031
]);
3132
});

packages/sveltekit/src/builder.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ async function convertSvelteKitRequest(request) {
2020
export class SvelteKitBuilder extends BaseBuilder {
2121
constructor(config?: Partial<SvelteKitConfig>) {
2222
const workingDir = config?.workingDir || process.cwd();
23-
const dirs = getWorkflowDirs({ dirs: config?.dirs });
23+
24+
// Merge user-provided dirs with framework defaults
25+
// User dirs are included if provided, then framework defaults are added
26+
const defaultDirs = ['workflows', 'src/workflows', 'routes', 'src/routes'];
27+
const userDirs = config?.dirs ?? [];
28+
const allDirs = Array.from(new Set([...userDirs, ...defaultDirs]));
2429

2530
super({
2631
...config,
27-
dirs,
32+
dirs: allDirs,
2833
buildTarget: 'sveltekit' as const,
2934
stepsBundlePath: '', // unused in base
3035
workflowsBundlePath: '', // unused in base
@@ -232,24 +237,3 @@ export const OPTIONS = createSvelteKitHandler('OPTIONS');`
232237
}
233238
}
234239
}
235-
236-
/**
237-
* Gets the list of directories to scan for workflow files.
238-
*/
239-
export function getWorkflowDirs(options?: { dirs?: string[] }): string[] {
240-
return unique([
241-
// User-provided directories take precedence
242-
...(options?.dirs ?? []),
243-
// Scan routes directories (like Next.js does with app/pages directories)
244-
// This allows workflows to be placed anywhere in the routes tree
245-
'routes',
246-
'src/routes',
247-
// Also scan dedicated workflow directories for organization
248-
'workflows',
249-
'src/workflows',
250-
]).sort();
251-
}
252-
253-
function unique<T>(array: T[]): T[] {
254-
return Array.from(new Set(array));
255-
}

0 commit comments

Comments
 (0)