From 3465aac19b479d149fe0158f88572270434ccdf2 Mon Sep 17 00:00:00 2001 From: Nitesh Seram Date: Sat, 5 Dec 2026 17:10:51 +0530 Subject: [PATCH] fix(cli): deduplicate generated route methods --- packages/void/src/cli/gen-args.ts | 1 + packages/void/test/unit/gen.test.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/void/src/cli/gen-args.ts b/packages/void/src/cli/gen-args.ts index cf72cf6aee..cd0f1ff052 100644 --- a/packages/void/src/cli/gen-args.ts +++ b/packages/void/src/cli/gen-args.ts @@ -134,6 +134,7 @@ function parseRouteArgs(args: Array): GenArgs { ); } } + methods = [...new Set(methods)]; } // Strip leading slashes diff --git a/packages/void/test/unit/gen.test.ts b/packages/void/test/unit/gen.test.ts index 245604903a..2f013755aa 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'; @@ -1082,6 +1083,17 @@ describe('gen route', () => { expect(content).not.toContain('export const PATCH'); }); + it('generates one handler per method in order of first occurrence', async () => { + await runGenCommand(TMP, parseGenArgs(['route', 'api/items', '--methods', 'get,GET,post'])); + + const content = read('routes/api/items.ts'); + const handlers = Array.from( + content.matchAll(/^export const (\w+) = defineHandler/gm), + (match) => match[1], + ); + expect(handlers).toEqual(['GET', 'POST']); + }); + it('generates PUT and PATCH methods', async () => { await runGenCommand(TMP, { subcommand: 'route',