From fa68c2f22112b00989d488aded1c1f9b7952302b Mon Sep 17 00:00:00 2001 From: Nitesh Seram Date: Sat, 5 Dec 2026 12:02:20 +0530 Subject: [PATCH] fix(cli): generate index handler for root routes --- packages/void/src/cli/gen.ts | 2 +- packages/void/test/unit/gen.test.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/void/src/cli/gen.ts b/packages/void/src/cli/gen.ts index c669bf6a3..2c4284e27 100644 --- a/packages/void/src/cli/gen.ts +++ b/packages/void/src/cli/gen.ts @@ -626,7 +626,7 @@ function runMigration(root: string, name: string): void { } function runRoute(root: string, routePath: string, methods: Array): void { - const filePath = join(readProjectPaths(root).routesDir, routePath + '.ts'); + const filePath = join(readProjectPaths(root).routesDir, `${routePath || 'index'}.ts`); const exports = methods .map((m) => { const upper = m.toUpperCase(); diff --git a/packages/void/test/unit/gen.test.ts b/packages/void/test/unit/gen.test.ts index 245604903..9489e5b96 100644 --- a/packages/void/test/unit/gen.test.ts +++ b/packages/void/test/unit/gen.test.ts @@ -5,6 +5,7 @@ import { log, outro } from '@voidzero-dev/vite-plus-prompts'; import { toSlash } from 'pathslash'; import { describe, it, expect, afterEach, beforeEach, vi } from 'vite-plus/test'; import { packageFixturePath } from '../../../../test/fixture-dir.ts'; +import { parseGenArgs } from '../../src/cli/gen-args.ts'; import type { GenArgs } from '../../src/cli/gen-args.ts'; import { runGenCommand, formatTimestamp, detectValidator } from '../../src/cli/gen.ts'; import { Buffer } from '../../src/cli/node-buffer.ts'; @@ -1039,6 +1040,14 @@ describe('gen migration', () => { }); describe('gen route', () => { + it('generates routes/index.ts for the root route', async () => { + await runGenCommand(TMP, parseGenArgs(['route', '/'])); + + const content = read('routes/index.ts'); + expect(content).toContain('export const GET = defineHandler'); + expect(existsSync(join(TMP, 'routes/.ts'))).toBe(false); + }); + it('keeps an existing route and prints no creation success when skipped', async () => { const path = join(TMP, 'routes/api/health.ts'); mkdirSync(dirname(path), { recursive: true });